Actionable rules for building responsive, accessible, high-performance web UIs.
Your responsive designs break on real devices. You test on Chrome DevTools, ship to production, then discover your "responsive" site fails on iPhone SE, Android tablets, or when users zoom to 200%. Time to fix this permanently.
Every developer knows responsive design matters, but most implementations fall short where it counts:
!important overridesYou're not just building for "mobile and desktop" anymore. You're building for foldable phones, tablets in portrait mode, users with motor disabilities, and everything in between.
These Cursor Rules implement a battle-tested responsive development workflow that eliminates common pitfalls and delivers consistent results across all devices. Instead of guessing at breakpoints or copying framework defaults, you get a systematic approach that works.
What you get:
No more "it works on my machine" responsive issues. The rules enforce testing across real device matrices and implement proper fallbacks for experimental CSS features.
/* Instead of this brittle approach */
.hero {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
/* You get this with proper fallbacks */
.hero {
display: block; /* fallback for older browsers */
display: grid;
grid-template-columns: repeat(auto-fit, minmax(18.75rem, 1fr));
}
Automatic image optimization and critical CSS inlining means your mobile users get sub-2-second load times, not 5+ second waits.
<!-- Optimized responsive images generated automatically -->
<picture>
<source srcset="hero-320.webp 320w, hero-768.webp 768w" type="image/webp">
<img src="hero-768.jpg" alt="Product demo" loading="lazy"
style="max-width:100%;height:auto;">
</picture>
Content-driven breakpoints mean you add media queries only when your design actually needs them, not at arbitrary device widths.
/* Instead of device-based breakpoints */
@media (min-width: 768px) { /* iPad width */ }
@media (min-width: 1024px) { /* Desktop */ }
/* You get content-driven breakpoints */
@media (min-width: 48em) { /* When text becomes hard to read */ }
@media (min-width: 64em) { /* When sidebar has room to appear */ }
WCAG AA compliance happens automatically through proper contrast ratios, focus management, and zoom-friendly sizing—not as an afterthought.
Before: You create a card grid that looks perfect in Chrome DevTools but breaks on real devices.
/* Brittle approach - breaks on many devices */
.card-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
@media (max-width: 768px) {
.card-grid {
grid-template-columns: 1fr;
}
}
After: Using the rules, you build mobile-first with proper fallbacks and content-driven breakpoints.
/* Mobile-first with proper fallbacks */
.card-grid {
display: block; /* fallback */
display: grid;
grid-template-columns: 1fr;
gap: 1.25rem; /* 20px */
}
@media (min-width: 32em) { /* when cards have enough room */
.card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 64em) { /* when 3 columns fit comfortably */
.card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
Before: Fixed font sizes that become unreadable on small screens or when zoomed.
/* Fixed sizes that don't scale */
h1 { font-size: 48px; }
h2 { font-size: 32px; }
p { font-size: 16px; }
After: Fluid typography that adapts to screen size and user preferences.
/* Fluid typography using clamp() */
h1 { font-size: clamp(1.75rem, 2vw + 1rem, 3rem); }
h2 { font-size: clamp(1.5rem, 1.5vw + 1rem, 2rem); }
p { font-size: clamp(1rem, 0.5vw + 0.875rem, 1.125rem); }
With Tailwind CSS:
<!-- Mobile-first utility classes -->
<div class="block p-4 text-lg md:grid md:grid-cols-2 lg:p-8">
<div class="space-y-4 md:space-y-6">
<!-- Content scales naturally -->
</div>
</div>
With Bootstrap 5:
// Override before importing to avoid !important
$container-max-widths: (
sm: 100%,
md: 720px,
lg: 960px,
xl: 1140px
);
@import "bootstrap/scss/grid";
.cursorrules filenpm install stylelint stylelint-config-standard
npm install --save-dev cypress percy
/* styles/reset.css */
:root {
--font-size-base: 1rem;
--line-height-base: 1.5;
--spacing-unit: 1rem;
--max-width: 75rem; /* 1200px */
}
* {
box-sizing: border-box;
}
img {
max-width: 100%;
height: auto;
}
<meta name="viewport" content="width=device-width,initial-scale=1">
{
"scripts": {
"lint:css": "stylelint 'src/**/*.{css,scss}'",
"test:visual": "percy exec -- cypress run",
"test:responsive": "cypress run --spec 'cypress/integration/responsive.spec.js'"
}
}
/* Start with mobile styles */
.hero {
display: block;
padding: 1rem;
text-align: center;
}
/* Enhance for larger screens */
@media (min-width: 48em) {
.hero {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 2rem;
text-align: left;
}
}
Your responsive designs will work reliably across the full spectrum of devices and user needs. No more emergency hotfixes for broken mobile layouts or accessibility complaints.
Stop building responsive designs that only work in perfect conditions. Start shipping UIs that work everywhere, for everyone.
You are an expert in HTML5, CSS3 (Flexbox, Grid, Media Queries), modern JavaScript (ES6+), Tailwind CSS, Bootstrap 5, and responsive-design tooling.
## Key Principles
- **Mobile-first**: Write base styles for ≤ 375 px. Layer up with `min-width` media queries.
- **Fluid layouts**: Prefer relative units (`rem`, `%`, `vw`) over pixel values except for hairline borders.
- **Content-driven breakpoints**: Add breakpoints only where the design visually breaks, not at device presets.
- **Progressive enhancement**: Ship functional core without JS; enhance interactions with unobtrusive scripts.
- **Accessibility first**: Color-contrast ≥ WCAG AA, keyboard focus rings visible, text resizable to 200 %.
- **Performance budget**: ≤ 100 KB critical CSS, FCP < 1.8 s on 3G, CLS < 0.1.
- **Reusable atomic components**: Follow Atomic Design; isolate atoms (buttons, inputs) before molecules/organisms.
## CSS / HTML Rules
- **File ordering**: `reset → variables → base → layout → components → utilities → overrides`.
- **Variables**: Define all colors, spacing & typography in `:root` or Tailwind config.
- **Units**:
• Font sizes: `rem` (root set to 16 px).
• Spacing: `rem` or Tailwind spacing scale.
• Media queries: `em` (use 1 em = current font-size) for breakpoint independence.
- **Selectors**: Max two levels deep; avoid descendant selectors (`.card .title`) in favor of BEM (`.card__title`).
- **Media Query Syntax**:
```css
@media (min-width: 48em) { /* 768 px */ }
@media (min-width: 64em) { /* 1024 px */ }
```
- **Layout**:
• Use Flexbox for 1-D flow (rows/columns), Grid for 2-D (rows + cols).
• Always declare an explicit fallback (`display:block`) above experimental properties.
- **Images & media**:
```html
<picture>
<source srcset="hero.webp" type="image/webp" />
<img src="hero.jpg" alt="Product screenshot" loading="lazy" style="max-width:100%;height:auto;" />
</picture>
```
- **Clamp utility**: Apply fluid typography.
```css
h1 { font-size: clamp(1.75rem, 2vw + 1rem, 3rem); }
```
## Error Handling & Validation
- **Viewport meta**: Always include `<meta name="viewport" content="width=device-width,initial-scale=1" />`; test zoom at 400 %.
- **Cross-device testing**: Every pull request must pass BrowserStack matrix: iOS Safari, Android Chrome, Firefox, Edge (last 2 versions).
- **CSS linting**: Use `stylelint` with `stylelint-config-standard` + `stylelint-config-recommended-vue` (if Vue) to catch invalid properties and unit mistakes.
- **Visual regression**: Integrate Percy/Cypress screenshot diffing for breakpoints (320, 768, 1024, 1440 px).
- **Fallbacks**: Provide solid colors behind gradients; include SVGO-optimized inline SVG fallback PNG ≤ 10 KB.
## Framework-Specific Rules
### Tailwind CSS
- Enable `@tailwindcss/aspect-ratio` & `@tailwindcss/typography` plugins.
- Extend theme only in `/src/styles/tailwind.config.js`; never inline `!important`.
- Group utility classes mobile-first → breakpoint order: `block p-4 text-lg md:grid md:grid-cols-2 lg:p-8`.
- Use `container` class with `screens` config `{ sm:"100%", md:"720px", lg:"960px", xl:"1140px" }`.
### Bootstrap 5
- Import only required modules with SCSS: `@import "bootstrap/scss/{functions,variables,utilities,grid,images}";`.
- Override variables _before_ importing components to avoid `!important`.
- Replace `.container` widths when design requires custom breakpoints: `$container-max-widths: (sm:100%, md:720px, lg:960px, xl:1140px);`.
- Use `row-cols-*` utilities instead of manual media queries for responsive grids.
## Testing
- **Unit**: Jest + Testing Library; test width changes via `window.matchMedia` mocks.
- **E2E**: Cypress `cy.viewport()` for 320, 768, 1024 px; assert no horizontal scroll: `cy.document().its('documentElement.scrollWidth').should('eq', cy.document().its('documentElement.clientWidth'))`.
## Performance
- Lazy-load images (`loading="lazy"`) & dangerously large components (`import("./Chart")` with React lazy).
- Critical CSS: inline `<style id="critical-css">` in `<head>` ≤ 10KB; remainder deferred via `media="print" onload="this.media='all'"`.
- Enable `font-display:swap` for @font-face; preload largest WOFF2 only.
## Accessibility
- Always provide visible focus (`outline-offset:2px;`), skip-nav link, ARIA landmarks.
- Responsive ≠ accessible: test with VoiceOver at 320 px & 200 % zoom.
## Tooling
- VSCode extensions: `Tailwind IntelliSense`, `CSS Peek`, `Live Server`.
- NPM scripts:
```json
"scripts": {
"lint:css": "stylelint 'src/**/*.{css,scss,vue,js}'",
"test:visual": "percy exec -- cypress run",
"build:css": "postcss src/styles/index.css -o dist/styles.css --env production"
}
```