| name | css |
| description | Expert-level CSS development with modern features and best practices. Use when asked to (1) write or debug CSS, (2) implement layouts with flexbox, grid, or container queries, (3) create animations and transitions, (4) optimize CSS performance, (5) work with CSS preprocessors or CSS-in-JS, (6) implement responsive design, or when phrases like "style", "CSS", "stylesheet", "design", "layout", "animation" appear. |
Expert CSS Development
Write modern, performant, maintainable CSS following current best practices with deep knowledge of browser compatibility and CSS specifications.
Documentation Lookup with context7
IMPORTANT: When you need to look up CSS properties, syntax, browser compatibility, or spec details, use the context7 MCP tool to query MDN and other documentation sources.
How to use context7 for CSS
context7 "CSS flexbox properties"
context7 "CSS grid-template-areas syntax"
context7 "CSS custom properties inheritance"
context7 "CSS container queries browser support"
context7 "CSS :has() selector compatibility"
context7 "CSS performance optimization"
context7 "CSS naming conventions BEM"
context7 "CSS cascade layers @layer"
context7 "CSS subgrid"
context7 "CSS color-mix function"
Use context7 whenever:
- You're unsure about exact syntax or property values
- You need to verify browser support for a feature
- You want to find the most current best practices
- You're working with cutting-edge CSS features
- You need to understand spec details or edge cases
Core Principles
- Mobile-first responsive design - Start with mobile layout, scale up
- Progressive enhancement - Core functionality works everywhere, enhancements where supported
- CSS cascade and specificity - Understand and leverage, don't fight against it
- Performance matters - Minimize reflows, optimize animations, reduce file size
- Maintainability - Use consistent naming, logical organization, clear documentation
Modern Layout Techniques
Flexbox for One-Dimensional Layouts
.container {
display: flex;
gap: 1rem;
}
.centered {
display: flex;
justify-content: center;
align-items: center;
}
.flex-wrap {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.flex-wrap > * {
flex: 1 1 300px;
}
.flex-1 { flex: 1; }
.flex-none { flex: none; }
.flex-auto { flex: auto; }
Grid for Two-Dimensional Layouts
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 2rem;
}
.layout {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 250px 1fr;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
.masonry {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-auto-flow: dense;
gap: 1rem;
}
Container Queries (Modern Alternative to Media Queries)
.card-container {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 150px 1fr;
}
}
@container card (min-width: 600px) {
.card {
grid-template-columns: 200px 1fr;
}
}
Modern CSS Features
Custom Properties (CSS Variables)
:root {
--color-primary: #0066cc;
--color-primary-dark: #004499;
--color-surface: #ffffff;
--color-text: #1a1a1a;
--space-xs: 0.25rem;
--space-sm: 0.5rem;
--space-md: 1rem;
--space-lg: 2rem;
--space-xl: 4rem;
--font-sans: system-ui, -apple-system, sans-serif;
--font-mono: 'Fira Code', monospace;
--bg: var(--color-surface);
--fg: var(--color-text);
}
[data-theme="dark"] {
--color-surface: #1a1a1a;
--color-text: #e5e5e5;
}
.button {
background: var(--color-primary);
padding: var(--space-sm) var(--space-md);
font-family: var(--font-sans);
}
Cascade Layers (@layer)
@layer reset, base, components, utilities;
@layer reset {
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
}
@layer base {
body {
font-family: system-ui, sans-serif;
line-height: 1.5;
}
}
@layer components {
.button {
padding: 0.5rem 1rem;
border-radius: 0.25rem;
}
}
@layer utilities {
.text-center { text-align: center; }
.hidden { display: none; }
}
Modern Selectors
:is(h1, h2, h3) {
font-weight: 700;
line-height: 1.2;
}
:where(.card, .panel) > :where(h2, h3) {
margin-top: 0;
}
.card:has(img) {
display: grid;
grid-template-columns: 200px 1fr;
}
.form:has(:invalid) .submit-button {
opacity: 0.5;
pointer-events: none;
}
.element {
margin-inline-start: 1rem;
padding-block: 2rem;
border-inline-end: 1px solid;
}
Animations and Transitions
Performant Animations
.smooth-animation {
will-change: transform;
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.smooth-animation:hover {
transform: translateY(-4px);
}
.smooth-animation:not(:hover) {
will-change: auto;
}
@keyframes slideInFade {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-in {
animation: slideInFade 0.4s ease-out;
}
View Transitions API
::view-transition-old(root),
::view-transition-new(root) {
animation-duration: 0.3s;
}
.hero {
view-transition-name: hero-image;
}
::view-transition-old(hero-image),
::view-transition-new(hero-image) {
animation-duration: 0.5s;
}
Scroll-Driven Animations
@keyframes fade-in {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.scroll-reveal {
animation: fade-in linear;
animation-timeline: view();
animation-range: entry 0% cover 30%;
}
Responsive Design Patterns
Modern Media Query Strategy
.component {
padding: 1rem;
}
@media (min-width: 768px) {
.component {
padding: 2rem;
}
}
@media (min-width: 1024px) {
.component {
padding: 3rem;
}
}
@media (min-width: 1440px) {
.component {
padding: 4rem;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #1a1a1a;
--fg: #e5e5e5;
}
}
Fluid Typography
h1 {
font-size: clamp(2rem, 4vw + 1rem, 4rem);
}
body {
font-size: clamp(1rem, 0.5vw + 0.875rem, 1.125rem);
}
:root {
--fluid-min-width: 320;
--fluid-max-width: 1140;
--fluid-min-size: 16;
--fluid-max-size: 20;
--fluid-size: calc(
(var(--fluid-min-size) * 1px) +
(var(--fluid-max-size) - var(--fluid-min-size)) *
((100vw - (var(--fluid-min-width) * 1px)) /
(var(--fluid-max-width) - var(--fluid-min-width)))
);
}
body {
font-size: clamp(
var(--fluid-min-size) * 1px,
var(--fluid-size),
var(--fluid-max-size) * 1px
);
}
Performance Optimization
Critical Performance Rules
.avoid {
box-shadow: ...;
filter: ...;
}
.card {
contain: layout style paint;
}
.isolated-component {
content-visibility: auto;
}
.button { }
.nav-item { }
div.container ul li a.link { }
[class*="btn-"] { }
CSS Loading Strategies
<style>
</style>
<link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'">
<link rel="preload" href="fonts.woff2" as="font" type="font/woff2" crossorigin>
Naming Conventions and Organization
BEM (Block Element Modifier)
.card { }
.card__title { }
.card__body { }
.card__footer { }
.card--featured { }
.card--large { }
.card__title--primary { }
Utility-First (Tailwind-style)
.p-4 { padding: 1rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.flex { display: flex; }
.grid { display: grid; }
.hidden { display: none; }
.text-lg { font-size: 1.125rem; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
File Organization
styles/
├── base/
│ ├── reset.css
│ ├── typography.css
│ └── utilities.css
├── components/
│ ├── button.css
│ ├── card.css
│ └── nav.css
├── layout/
│ ├── grid.css
│ ├── header.css
│ └── footer.css
├── themes/
│ ├── light.css
│ └── dark.css
└── main.css (imports all)
Modern Color Functions
:root {
--primary: oklch(60% 0.2 250);
--surface: color-mix(in oklch, var(--primary) 10%, white);
--primary-light: oklch(from var(--primary) calc(l + 20%) c h);
--primary-dark: oklch(from var(--primary) calc(l - 20%) c h);
--text-color: color-contrast(
var(--surface) vs black, white
);
}
Browser Compatibility Strategies
Feature Queries (@supports)
.grid {
display: flex;
flex-wrap: wrap;
}
@supports (display: grid) {
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
}
.button {
background: blue;
}
@supports (backdrop-filter: blur(10px)) {
.button {
background: rgba(0, 0, 255, 0.8);
backdrop-filter: blur(10px);
}
}
Common Patterns and Solutions
Aspect Ratio
.video {
aspect-ratio: 16 / 9;
}
img {
aspect-ratio: 16 / 9;
object-fit: cover;
}
Truncation
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
Smooth Scrolling
html {
scroll-behavior: smooth;
}
.carousel {
scroll-snap-type: x mandatory;
overflow-x: auto;
}
.carousel > * {
scroll-snap-align: start;
}
Accessibility Considerations
:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
@media (prefers-contrast: high) {
.button {
border: 2px solid currentColor;
}
}
CSS Reset / Normalize
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
}
html {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
min-height: 100vh;
line-height: 1.5;
}
img,
picture,
video,
canvas,
svg {
display: block;
max-width: 100%;
}
input,
button,
textarea,
select {
font: inherit;
}
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
Quick Reference
See references/ for detailed guides on:
- Modern layout techniques (flexbox, grid, container queries)
- Animation and transition best practices
- Performance optimization strategies
- Responsive design patterns
- Accessibility guidelines
Workflow
- Start with context7 - Look up unfamiliar properties or modern features
- Mobile-first - Design and code for mobile, enhance for larger screens
- Use feature queries - Progressive enhancement with @supports
- Test across browsers - Verify in Chrome, Firefox, Safari, Edge
- Validate - Use W3C CSS Validator for standard compliance
- Optimize - Minimize reflows, use contain, leverage GPU acceleration
- Document - Comment complex calculations, magic numbers, browser hacks
Tools and Resources
- context7 - Primary documentation lookup tool
- MDN Web Docs - Comprehensive CSS reference (via context7)
- Can I Use - Browser compatibility data (via context7)
- CSS Specifications - W3C specs for detailed behavior (via context7)
- PostCSS - Transform CSS with JavaScript plugins
- CSS Modules - Scoped CSS for components
- Sass/SCSS - CSS preprocessor with variables, nesting, mixins
- Lightning CSS - Fast CSS parser, transformer, and minifier
Remember: When in doubt about any CSS feature, syntax, or browser support, use context7 to look it up in real-time documentation.