Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
AI-powered UI styling skill with 67 UI styles and 161 reasoning rules for professional interface design.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/tailwind-responsive.md
1# Tailwind CSS Responsive Design23Mobile-first breakpoints, responsive utilities, and adaptive layouts.45## Mobile-First Approach67Tailwind uses mobile-first responsive design. Base styles apply to all screen sizes, then use breakpoint prefixes to override at larger sizes.89```html10<!-- Base: 1 column (mobile)11sm: 2 columns (tablet)12lg: 4 columns (desktop) -->13<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">14<div>Item 1</div>15<div>Item 2</div>16<div>Item 3</div>17<div>Item 4</div>18</div>19```2021## Breakpoint System2223**Default breakpoints:**2425| Prefix | Min Width | CSS Media Query |26|--------|-----------|-----------------|27| `sm:` | 640px | `@media (min-width: 640px)` |28| `md:` | 768px | `@media (min-width: 768px)` |29| `lg:` | 1024px | `@media (min-width: 1024px)` |30| `xl:` | 1280px | `@media (min-width: 1280px)` |31| `2xl:` | 1536px | `@media (min-width: 1536px)` |3233## Responsive Patterns3435### Layout Changes3637```html38<!-- Vertical on mobile, horizontal on desktop -->39<div class="flex flex-col lg:flex-row gap-4">40<div>Left</div>41<div>Right</div>42</div>4344<!-- 1 column -> 2 columns -> 3 columns -->45<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">46<div>Item 1</div>47<div>Item 2</div>48<div>Item 3</div>49</div>50```5152### Visibility5354```html55<!-- Hide on mobile, show on desktop -->56<div class="hidden lg:block">57Desktop only content58</div>5960<!-- Show on mobile, hide on desktop -->61<div class="block lg:hidden">62Mobile only content63</div>6465<!-- Different content per breakpoint -->66<div class="lg:hidden">Mobile menu</div>67<div class="hidden lg:flex">Desktop navigation</div>68```6970### Typography7172```html73<!-- Responsive text sizes -->74<h1 class="text-2xl md:text-4xl lg:text-6xl font-bold">75Heading scales with screen size76</h1>7778<p class="text-sm md:text-base lg:text-lg">79Body text scales appropriately80</p>81```8283### Spacing8485```html86<!-- Responsive padding -->87<div class="p-4 md:p-6 lg:p-8">88More padding on larger screens89</div>9091<!-- Responsive gap -->92<div class="flex gap-2 md:gap-4 lg:gap-6">93<div>Item 1</div>94<div>Item 2</div>95</div>96```9798### Width99100```html101<!-- Full width on mobile, constrained on desktop -->102<div class="w-full lg:w-1/2 xl:w-1/3">103Responsive width104</div>105106<!-- Responsive max-width -->107<div class="max-w-sm md:max-w-2xl lg:max-w-4xl mx-auto">108Centered with responsive max width109</div>110```111112## Common Responsive Layouts113114### Sidebar Layout115116```html117<div class="flex flex-col lg:flex-row min-h-screen">118<!-- Sidebar: Full width on mobile, fixed on desktop -->119<aside class="w-full lg:w-64 bg-gray-100 p-4">120Sidebar121</aside>122123<!-- Main content -->124<main class="flex-1 p-4 md:p-8">125Main content126</main>127</div>128```129130### Card Grid131132```html133<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 md:gap-6">134<div class="bg-white rounded-lg shadow p-6">Card 1</div>135<div class="bg-white rounded-lg shadow p-6">Card 2</div>136<div class="bg-white rounded-lg shadow p-6">Card 3</div>137<div class="bg-white rounded-lg shadow p-6">Card 4</div>138</div>139```140141### Hero Section142143```html144<section class="py-12 md:py-20 lg:py-32">145<div class="container mx-auto px-4">146<div class="flex flex-col lg:flex-row items-center gap-8 lg:gap-12">147<div class="flex-1 text-center lg:text-left">148<h1 class="text-4xl md:text-5xl lg:text-6xl font-bold mb-4">149Hero Title150</h1>151<p class="text-lg md:text-xl mb-6">152Hero description153</p>154<button class="px-6 py-3 md:px-8 md:py-4">155CTA Button156</button>157</div>158<div class="flex-1">159<img src="hero.jpg" class="w-full rounded-lg" />160</div>161</div>162</div>163</section>164```165166### Navigation167168```html169<nav class="bg-white shadow">170<div class="container mx-auto px-4">171<div class="flex items-center justify-between h-16">172<div class="text-xl font-bold">Logo</div>173174<!-- Desktop navigation -->175<div class="hidden md:flex gap-6">176<a href="#">Home</a>177<a href="#">About</a>178<a href="#">Services</a>179<a href="#">Contact</a>180</div>181182<!-- Mobile menu button -->183<button class="md:hidden">184<svg class="w-6 h-6">...</svg>185</button>186</div>187</div>188</nav>189```190191## Max-Width Queries192193Apply styles only below certain breakpoint using `max-*:` prefix:194195```html196<!-- Only on mobile and tablet (below 1024px) -->197<div class="max-lg:text-center">198Centered on mobile/tablet, left-aligned on desktop199</div>200201<!-- Only on mobile (below 640px) -->202<div class="max-sm:hidden">203Hidden only on mobile204</div>205```206207Available: `max-sm:` `max-md:` `max-lg:` `max-xl:` `max-2xl:`208209## Range Queries210211Apply styles between breakpoints:212213```html214<!-- Only on tablets (between md and lg) -->215<div class="md:block lg:hidden">216Visible only on tablets217</div>218219<!-- Between sm and xl -->220<div class="sm:grid-cols-2 xl:grid-cols-4">2212 columns on tablet, 4 on extra large222</div>223```224225## Container Queries226227Style elements based on parent container width:228229```html230<div class="@container">231<div class="@md:grid-cols-2 @lg:grid-cols-3">232Responds to parent width, not viewport233</div>234</div>235```236237Container query breakpoints: `@sm:` `@md:` `@lg:` `@xl:` `@2xl:`238239## Custom Breakpoints240241Define custom breakpoints in theme:242243```css244@theme {245--breakpoint-3xl: 120rem; /* 1920px */246--breakpoint-tablet: 48rem; /* 768px */247}248```249250```html251<div class="tablet:grid-cols-2 3xl:grid-cols-6">252Uses custom breakpoints253</div>254```255256## Responsive State Variants257258Combine responsive with hover/focus:259260```html261<!-- Hover effect only on desktop -->262<button class="lg:hover:scale-105">263Scale on hover (desktop only)264</button>265266<!-- Different hover colors per breakpoint -->267<a class="hover:text-blue-600 lg:hover:text-purple-600">268Link269</a>270```271272## Best Practices273274### 1. Mobile-First Design275276Start with mobile styles, add complexity at larger breakpoints:277278```html279<!-- Good: Mobile first -->280<div class="text-base md:text-lg lg:text-xl">281282<!-- Avoid: Desktop first -->283<div class="text-xl lg:text-base">284```285286### 2. Consistent Breakpoint Usage287288Use same breakpoints across related elements:289290```html291<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6 lg:gap-8">292Spacing scales with layout293</div>294```295296### 3. Test at Breakpoint Boundaries297298Test at exact breakpoint widths (640px, 768px, 1024px, etc.) to catch edge cases.299300### 4. Use Container for Content Width301302```html303<div class="container mx-auto px-4 sm:px-6 lg:px-8">304<div class="max-w-7xl">305Content with consistent max width306</div>307</div>308```309310### 5. Progressive Enhancement311312Ensure core functionality works on mobile, enhance for larger screens:313314```html315<!-- Core layout works on mobile -->316<div class="p-4">317<!-- Enhanced spacing on desktop -->318<div class="lg:p-8">319Content320</div>321</div>322```323324### 6. Avoid Too Many Breakpoints325326Use 2-3 breakpoints per element for maintainability:327328```html329<!-- Good: 2 breakpoints -->330<div class="grid-cols-1 md:grid-cols-2 lg:grid-cols-4">331332<!-- Avoid: Too many breakpoints -->333<div class="grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6">334```335336## Common Responsive Utilities337338### Responsive Display339340```html341<div class="block md:flex lg:grid">342Changes display type per breakpoint343</div>344```345346### Responsive Position347348```html349<div class="relative lg:absolute">350Positioned differently per breakpoint351</div>352```353354### Responsive Order355356```html357<div class="flex flex-col">358<div class="order-2 lg:order-1">First on desktop</div>359<div class="order-1 lg:order-2">First on mobile</div>360</div>361```362363### Responsive Overflow364365```html366<div class="overflow-auto lg:overflow-visible">367Scrollable on mobile, expanded on desktop368</div>369```370371## Testing Checklist372373- [ ] Test at 320px (small mobile)374- [ ] Test at 640px (mobile breakpoint)375- [ ] Test at 768px (tablet breakpoint)376- [ ] Test at 1024px (desktop breakpoint)377- [ ] Test at 1280px (large desktop breakpoint)378- [ ] Test landscape orientation379- [ ] Verify touch targets (min 44x44px)380- [ ] Check text readability at all sizes381- [ ] Verify navigation works on mobile382- [ ] Test with browser zoom383