| name | css |
| description | Apply CSS best practices using Tailwind CSS v4 with container queries, mobile-first design, and shadcn/ui tokens. Use when writing CSS, styling components, creating responsive layouts, or working with Tailwind configuration. Use when this capability is needed. |
| metadata | {"author":"dungle-scrubs"} |
CSS Best Practices Skill
When to Use This Skill
This skill should be triggered when:
- Writing or reviewing CSS/Tailwind styles
- Creating responsive layouts or components
- Configuring Tailwind or shadcn/ui theming
- Discussing CSS architecture decisions
- Setting up new projects with styling
Core Principles
1. Tailwind CSS v4 by Default
New projects should always use the latest version of Tailwind CSS (v4). Key v4 features:
- CSS-first configuration using
@theme directive
- Native CSS variables for all design tokens
- Automatic content detection (no
content config needed)
- Built-in container queries support
2. Container Queries First
Use @container queries for component-level responsiveness when possible:
.card-container {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 400px) {
.card-content {
display: grid;
grid-template-columns: 1fr 1fr;
}
}
With Tailwind v4:
<div class="@container">
<div class="@sm:grid @sm:grid-cols-2">
</div>
</div>
3. Media Queries for Viewport Dependencies
Use viewport-based media queries only when responsiveness depends on viewport width:
- Navigation/header layouts
- Full-page layouts
- Elements that must coordinate across the entire viewport
<nav class="flex flex-col md:flex-row">
</nav>
4. Mobile-First Approach
Write base styles for mobile, then enhance for larger screens:
<div class="text-sm md:text-base lg:text-lg">
</div>
shadcn/ui Token Structure
CSS Variables Configuration
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% ;
: ;
: ;
: ;
: ;
: ;
: ;
}
{
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
: ;
}
}
Using Tokens in Tailwind
<div class="bg-background text-foreground">
<button class="bg-primary text-primary-foreground hover:bg-primary/90">
Primary Action
</button>
<p class="text-muted-foreground">Secondary text</p>
</div>
Tailwind v4 Configuration
CSS-based Config (v4 style)
@import "tailwindcss";
@theme {
--color-primary: oklch(0.7 0.15 250);
--color-secondary: oklch(0.8 0.1 200);
--spacing-18: 4.5rem;
--font-size-xxs: 0.625rem;
--radius-sm: 0.25rem;
--radius-md: 0.5rem;
--radius-lg: 0.75rem;
}
Container Query Breakpoints
Tailwind v4 includes container query variants:
@xs - 20rem (320px)
@sm - 24rem (384px)
@md - 28rem (448px)
@lg - 32rem (512px)
@xl - 36rem (576px)
@2xl - 42rem (672px)
Common Patterns
Responsive Card with Container Queries
<div class="@container">
<article class="flex flex-col @md:flex-row gap-4 p-4 bg-card rounded-lg border">
<img class="w-full @md:w-48 aspect-video object-cover rounded" />
<div class="flex-1">
<h3 class="font-semibold text-card-foreground">Title</h3>
<p class="text-muted-foreground text-sm">Description</p>
</div>
</article>
</div>
Responsive Grid
<div class="@container">
<div class="grid grid-cols-1 @sm:grid-cols-2 @lg:grid-cols-3 gap-4">
</div>
</div>
Theme-Aware Component
<div class="bg-background text-foreground border-border rounded-[--radius]">
<h2 class="text-primary">Heading</h2>
<p class="text-muted-foreground">Supporting text</p>
<button class="bg-primary text-primary-foreground hover:bg-primary/90 px-4 py-2 rounded-md">
Action
</button>
</div>
Best Practices Summary
- Container queries by default - Use
@container for component responsiveness
- Media queries sparingly - Only for true viewport dependencies
- Mobile-first - Base styles for mobile, enhance upward
- Use shadcn tokens - Leverage the semantic color system
- Tailwind v4 features - CSS-first config, native container queries
- Semantic colors - Use
primary, secondary, muted over raw colors
- Consistent spacing - Use Tailwind's spacing scale
- Dark mode ready - Always consider both light and dark themes
Notes
- Container queries provide better component encapsulation than media queries
- shadcn/ui tokens ensure consistent theming across components
- Tailwind v4's CSS-first approach simplifies configuration
- Always test responsive behavior in both container and viewport contexts
Converted and distributed by TomeVault — claim your Tome and manage your conversions.