Responsive layouts with Tailwind v4: mobile-first breakpoints, max-* and range variants, built-in container queries, aspect ratio, responsive type and touch-friendly targets.
.cursor/rules/tailwind-responsive-design.mdc. Downloaded files need to be placed in that repository path.---
description: "Responsive layouts with Tailwind v4: mobile-first breakpoints, max-* and range variants, built-in container queries, aspect ratio, responsive type and touch-friendly targets."
globs: "**/*"
alwaysApply: false
---
Apply these rules when building responsive layouts with Tailwind CSS (v4 unless the project says otherwise).
## Mobile first
- Write the mobile layout with unprefixed utilities, then add changes at larger sizes: `sm:` (40rem / 640px), `md:` (48rem), `lg:` (64rem), `xl:` (80rem), `2xl:` (96rem). A prefix means "from this width up", not "only on this device".
- Target ranges with stacked variants (`md:max-xl:flex`) or below a breakpoint with `max-md:`.
- Add or change breakpoints with `--breakpoint-*` variables in `@theme`, not with arbitrary media queries scattered through markup.
```html
<section class="grid grid-cols-1 gap-4 p-4 md:grid-cols-2 lg:grid-cols-3 lg:gap-8">
<article class="@container rounded-lg border p-4">
<div class="flex flex-col gap-3 @md:flex-row">
<img class="aspect-video w-full object-cover @md:w-48" src="/cover.jpg" alt="Product photo" />
<h2 class="text-lg font-semibold md:text-xl">Product name</h2>
</div>
</article>
</section>
```
## Container queries
- Use container queries for reusable components (cards, sidebars, widgets) that appear in containers of different widths: mark the parent with `@container` and use `@sm:`, `@md:`, ... on children. They are built into Tailwind v4; v3 needs the `@tailwindcss/container-queries` plugin.
## Flexible layouts
- Prefer `flex`/`grid` with `gap-*`, `min-w-0` on flex children that contain long text, and `max-w-*` containers over fixed widths.
## Typography and media
- Step font sizes at breakpoints (`text-base md:text-lg`); keep body text readable on small screens and limit line length (`max-w-prose`).
- Use `aspect-video`, `aspect-square` or `aspect-[4/3]` to reserve space for images and embeds; set `width`/`height` on images to avoid layout shift.
## Touch devices
- Make tap targets large enough (about 44×44 CSS px is a common guideline) with padding, not only icon size.
- Do not hide essential actions behind hover. In v4, `hover:` styles apply only on devices that support hover; use `pointer-coarse:` to enlarge controls for touch input.
## Testing
- Check each breakpoint you style plus the widths between them (device toolbar or by resizing), with zoom at 200%, and on at least one real touch device for gesture and tap issues.
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor
styling
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A product card grid uses fixed widths and md:-only classes; on mid-size tablets cards overflow, and the card component looks wrong inside a narrow sidebar.
Apply the Tailwind Responsive Design rule to ProductGrid.tsx and ProductCard.tsx (Tailwind v4).
A mobile-first grid (grid-cols-1 → md:grid-cols-2 → lg:grid-cols-3), the card marked @container with @md: layout changes so it adapts inside the sidebar, aspect-video images with dimensions, min-w-0 on text columns, larger touch targets via padding/pointer-coarse:, and a list of widths to test.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/tailwind-responsive-design.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
---
description: "Tailwind Responsive Design project conventions"
globs: "**/*"
alwaysApply: false
---
Apply these rules when building responsive layouts with Tailwind CSS (v4 unless the project says otherwise).
## Mobile first
- Write the mobile layout with unprefixed utilities, then add changes at larger sizes: `sm:` (40rem / 640px), `md:` (48rem), `lg:` (64rem), `xl:` (80rem), `2xl:` (96rem). A prefix means "from this width up", not "only on this device".
- Target ranges with stacked variants (`md:max-xl:flex`) or below a breakpoint with `max-md:`.
- Add or change breakpoints with `--breakpoint-*` variables in `@theme`, not with arbitrary media queries scattered through markup.
```html
<section class="grid grid-cols-1 gap-4 p-4 md:grid-cols-2 lg:grid-cols-3 lg:gap-8">
<article class="@container rounded-lg border p-4">
<div class="flex flex-col gap-3 @md:flex-row">
<img class="aspect-video w-full object-cover @md:w-48" src="/cover.jpg" alt="Product photo" />
<h2 class="text-lg font-semibold md:text-xl">Product name</h2>
</div>
</article>
</section>
```
## Container queries
- Use container queries for reusable components (cards, sidebars, widgets) that appear in containers of different widths: mark the parent with `@container` and use `@sm:`, `@md:`, ... on children. They are built into Tailwind v4; v3 needs the `@tailwindcss/container-queries` plugin.
## Flexible layouts
- Prefer `flex`/`grid` with `gap-*`, `min-w-0` on flex children that contain long text, and `max-w-*` containers over fixed widths.
## Typography and media
- Step font sizes at breakpoints (`text-base md:text-lg`); keep body text readable on small screens and limit line length (`max-w-prose`).
- Use `aspect-video`, `aspect-square` or `aspect-[4/3]` to reserve space for images and embeds; set `width`/`height` on images to avoid layout shift.
## Touch devices
- Make tap targets large enough (about 44×44 CSS px is a common guideline) with padding, not only icon size.
- Do not hide essential actions behind hover. In v4, `hover:` styles apply only on devices that support hover; use `pointer-coarse:` to enlarge controls for touch input.
## Testing
- Check each breakpoint you style plus the widths between them (device toolbar or by resizing), with zoom at 200%, and on at least one real touch device for gesture and tap issues.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.