Opinionated Rules focused on building fast, accessible, cross-browser web applications that look and behave consistently from IE 11 (fallback mode) to the latest Evergreen browsers.
You've been there. Your site looks perfect in Chrome, breaks spectacularly in Safari, and somehow makes IE cry. While other developers spend their weekends debugging browser quirks, you could be shipping features that work consistently across every browser your users actually use.
Modern web applications need to work flawlessly across browsers spanning a decade of evolution. Your users don't care that Safari handles flex gaps differently or that IE 11 doesn't support CSS Grid. They expect your application to work, period.
Here's what kills developer productivity in cross-browser development:
These Cursor Rules transform your development workflow into a compatibility-first approach. Instead of discovering browser issues during QA, you prevent them during development with automated compatibility checks, standardized patterns, and battle-tested fallbacks.
You'll write code that works consistently from IE 11 to the latest Chrome, with built-in performance optimization and accessibility compliance.
Eliminate Browser Debugging Sessions Stop spending hours in Safari's Web Inspector trying to figure out why your flex layout collapsed. These rules provide proven fallback patterns for every major browser compatibility issue.
Ship Faster with Confidence Your code works across browsers the first time because compatibility is built into every pattern. No more "works on my machine" moments during deployment.
Automated Compatibility Validation Every component includes feature detection and progressive enhancement patterns. Your CI pipeline catches compatibility issues before they reach production.
Performance by Default Bundle splitting, lazy loading, and optimized asset delivery are built into the workflow. Your applications load fast on every browser and device.
// This breaks in Safari ≤14
.container {
display: flex;
gap: 1rem;
}
// Discover the issue during manual testing
// Spend 2 hours debugging flex gap support
// Implement hacky margin-based workaround
/* Built-in fallback pattern */
.container {
display: flex;
gap: 1rem;
}
@supports not (gap: 1rem) {
.container { margin: -0.5rem; }
.container > * { margin: 0.5rem; }
}
// Wrong approach - fragile and unreliable
if (navigator.userAgent.includes('Safari')) {
// Brittle browser-specific code
}
// Cursor Rules approach - robust feature detection
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
// Handles Safari private mode and quota exceeded
export const safeSet = (key: string, value: string) => {
try {
localStorage.setItem(key, value);
} catch {
// Fallback: in-memory storage
memoryStore.set(key, value);
}
};
<picture>
<source type="image/webp" srcset="hero.webp" />
<source type="image/jpeg" srcset="hero.jpg" />
<img src="hero.jpg" alt="Hero image" loading="lazy" />
</picture>
# Install essential compatibility tools
npm install --save-dev @babel/core @babel/preset-env
npm install normalize.css modernizr
npm install --save-dev playwright @playwright/test
// package.json
{
"browserslist": [
"> 1%",
"last 2 versions",
"ie >= 11"
]
}
Copy the complete ruleset into your .cursorrules file. The rules include:
# Validate HTML during CI
npm run validate-html
# Test across browsers
npx playwright test
# Update browser database
npx browserslist --update-db
Development Speed: Reduce browser debugging time by 80%. Write compatibility code once instead of fixing issues across multiple browsers.
Code Quality: Every component includes proper fallbacks and feature detection. Your codebase becomes inherently more robust.
User Experience: Consistent performance and appearance across all supported browsers. Eliminate the "browser lottery" for your users.
Team Productivity: New developers can immediately write cross-browser compatible code using established patterns. No more compatibility knowledge silos.
Deployment Confidence: Automated testing across browser engines catches issues before production. Ship knowing your code works everywhere.
Performance Gains: Built-in optimization patterns (lazy loading, bundle splitting, responsive images) improve Core Web Vitals across all browsers.
These rules don't just solve cross-browser compatibility—they make it invisible. You'll write once and deploy everywhere, spending your time building features instead of debugging browser quirks.
Your users get a consistent, fast experience regardless of their browser choice. Your team gets predictable development velocity without compatibility surprises.
Ready to stop fighting browsers and start shipping? Add these rules to your project and watch your cross-browser development workflow transform from painful to automatic.
You are an expert in HTML5, CSS3, JavaScript/TypeScript, React, Bootstrap, Tailwind CSS, Playwright, BrowserStack, Babel, Modernizr.
Key Principles
- Mobile-first, responsive design with progressive enhancement.
- Prefer standards over hacks; never use browser sniffing—use feature detection.
- Ship the smallest, fastest bundle possible; performance is a compatibility feature.
- Accessibility (a11y) and SEO start with semantic markup.
- Develop and test against the project Browserslist at every pull-request.
HTML
- Always start with a correct doctype and encoding:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
```
- Use sectioning elements (<header>, <nav>, <main>, <section>, <article>, <footer>) for structure; never div-spam.
- Link a reset/normalize before custom styles:
```html
<link rel="stylesheet" href="/css/normalize.css" />
```
- Validate every page with the W3C validator during CI.
CSS / SCSS
- Import normalize.css (or Bootstrap reboot) as the first stylesheet.
- Autoprefixer must run in the build pipeline with the project Browserslist targets; do not hand-write prefixes except for experimental proofs.
- Use mobile-first media queries, ascending breakpoints, in em units:
```css
@media (min-width: 40em) { /* ≥640 px */ }
```
- Prefer Flexbox & CSS Grid; add fallbacks:
```css
.grid {
display: grid;
gap: 1rem;
}
@supports not (display: grid) {
.grid { display: flex; flex-wrap: wrap; margin: -0.5rem; }
.grid > * { margin: 0.5rem; }
}
```
- Use custom properties with fallbacks for older browsers:
```css
:root{ --brand:#0d6efd; }
.btn{ background: var(--brand, #0d6efd); }
```
- Never rely on default flex gap—Safari ≤14 needs the fallback above.
JavaScript / TypeScript
- Target ES2015+, compile with Babel & core-js polyfills driven by Browserslist.
- Strictly use `const` / `let`; forbid `var` via linter.
- Wrap any browser-specific API in feature checks:
```ts
if ('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js');
```
- Fetch API over XHR; polyfill with `whatwg-fetch` when browserslist includes IE 11.
- Handle potential storage exceptions (Safari private mode, quota):
```ts
export const safeSet = (k: string, v: string) => {
try { localStorage.setItem(k, v); }
catch { /* fallback: keep in memory */ }
};
```
Error Handling & Validation
- Run Modernizr build covering required features; branch logic accordingly.
- Provide polyfills **before** main bundle (e.g., in `polyfills.ts`).
- Use early returns for unsupported critical features and display a friendly message.
- Add global `window.onerror` & `window.onunhandledrejection` logging to Sentry or equivalent.
React Rules
- Functional components + Hooks only; class components forbidden.
- Wrap app with `<StrictMode>` and an error boundary per route.
- Use CSS-in-JS libraries that autoprefix (styled-components, emotion) or import pre-processed CSS.
- Avoid direct DOM manipulation; if unavoidable, guard with feature checks.
Bootstrap / Tailwind
- Stick to framework grid utilities; never re-implement grid in raw CSS.
- Override design tokens via SCSS variables (Bootstrap) or `tailwind.config.js` (Tailwind) instead of editing generated CSS.
- When mixing, namespace custom classes to avoid collisions.
Testing
- E2E: Playwright across Chromium, Firefox, WebKit in CI (`npx playwright test`).
- Visual: Add Percy or Chromatic; run per PR.
- Manual: Use BrowserStack Live every sprint on latest Chrome, Firefox, Safari, Edge, and lowest supported iOS & Android versions.
- Accessibility: Run `axe-core` automated checks plus manual keyboard & screen-reader passes.
Performance
- Bundle splitting via dynamic `import()`; lazy-load below-the-fold images with `loading="lazy"`.
- Provide responsive images using `<picture>` & `srcset`; include `type="image/webp"` sources.
- Enable HTTP/2, Brotli compression, immutable cache headers for hashed assets.
- Use the `Priority Hints` header (`importance=high`) on above-the-fold resources when supported.
Security
- Enforce HTTPS + HSTS; set CSP `default-src 'self';`.
- Sanitize any HTML (DOMPurify) before injecting; never use `dangerouslySetInnerHTML` without sanitation.
Common Pitfalls & Remedies
- Flex gap not supported in old Safari → add margin fallback (see CSS section).
- `position: sticky` bugs in IE → fallback to JS scroll handlers.
- Date/Time input types unsupported in Safari macOS ≤14 → replace with polyfilled picker.
- Avoid absolute units (px) for text; use `rem` to respect user zoom preferences.
File/Folder Conventions
- `/src`
- `/components` React components (PascalCase folders)
- `/styles` global SCSS modules (`_reset.scss`, `_variables.scss`, etc.)
- `/polyfills` feature & browser polyfills
- `/tests` Playwright & unit tests
- Public assets hashed via webpack/rollup plugin.
CI/CD
- `npm run lint`, `npm run test`, `npx browserslist --update-db` must all pass before merge.
- Deploy preview is spun up per PR; QA checklist includes manual cross-browser smoke test.