Modern CSS Features: Custom Properties, Nesting, :has(), :is(), clamp(), aspect-ratio, Cascade Layers and Dark Mode
Support check Many of these features are now supported in current versions of the major browsers (container queries, :has() and nesting are widely available). Before using any feature, check a support table such as MDN or Can I Use for the browsers your visitors use, and add fallbacks if needed.
Custom Properties (Variables)
css
:root {
--brand: #0b5cff;
--radius: 10px;
}
.btn {
background: var(--brand);
border-radius: var(--radius);
}
.btn--danger { --brand: #c1121f; } /* local override */
Variables follow the cascade, so you can change them for one section, one component or for dark mode, and everything inside updates.
Native Nesting
css
.card {
padding: 1rem;
border-radius: 12px;
h3 { margin: 0 0 .5rem; }
&:hover { box-shadow: 0 6px 18px rgb(0 0 0 / .12); }
@media (min-width: 700px) {
padding: 1.5rem;
}
}
:is(), :where() and :has()
css
:is(h1, h2, h3) { text-wrap: balance; } /* group selectors */
:where(.prose) a { color: var(--brand); } /* zero specificity */
.card:has(img) { grid-template-columns: 120px 1fr; } /* parent selector */
label:has(input:invalid) { color: #c1121f; }
form:has(:focus-visible) { outline: 2px solid var(--brand); }
Handy Properties
css
.thumb { aspect-ratio: 16 / 9; object-fit: cover; width: 100%; }
.title { margin-inline: auto; padding-block: 2rem; } /* logical properties */
.stack { display: grid; gap: 1rem; }
html { scroll-behavior: smooth; }
img { max-width: 100%; height: auto; }
| Property | Why |
|---|---|
aspect-ratio | Stops layout jumps and replaces old padding hacks |
margin-inline, padding-block | Work for any writing direction |
text-wrap: balance | Makes headings wrap evenly where supported |
gap | Spacing in flex and grid without margins |
Cascade Layers
@layer lets you order groups of CSS so that, for example, your component styles always beat a base reset or a framework, no matter the specificity.
css
@layer reset, base, components, utilities;
@layer reset { *, *::before, *::after { box-sizing: border-box; } }
@layer base { body { font: 1rem/1.6 system-ui, sans-serif; } }
@layer components { .btn { padding: .75rem 1.25rem; } }
@layer utilities { .hidden { display: none; } }
Dark Mode
css
:root { color-scheme: light dark; }
body {
background: light-dark(#ffffff, #12141a);
color: light-dark(#1b1b1f, #f2f3f5);
}
Practice
- Convert two colors in your project to custom properties
- Nest the styles of a card
- Use :has() to style a label when its input is invalid
Conclusion
Modern CSS gives variables, nesting, parent selectors, layers and dark mode. Use them, check support and keep a fallback when needed.
Quick Summary: Variables; nesting; selectors; properties; layers; dark mode.

