03 // Styling & Layout Architecture Deep dive into Modern CSS
Modern CSS removes the need for preprocessors, floating-position JavaScript libraries and brittle layout hacks. Browsers now handle cascade layering, container-aware components, perceptual colour mixing and top-layer transitions natively.
CSS 01 // Architecture Native Nesting & Cascade Layers (@layer)
Native CSS Nesting (Newly available Dec 2023, Widely available June 2026) lets you write nested child selectors and conditional @media or @container blocks directly in standard CSS without Sass. Pair it with Cascade Layers (@layer reset, base, components, utilities;) so layer order controls precedence cleanly instead of specificity battles or !important.
@layer base, components;
@layer components {
.card {
border: 1px solid var(--outline);
&:hover { border-color: var(--primary); }
}
}
CSS 02 // Responsive Layouts Container Queries & CSS Subgrid
Size Container Queries (@container, Widely available Aug 2025) adapt a component based on its parent container width rather than the full viewport. Style Queries adapt visuals based on custom property values (Newly available May 2026). CSS Subgrid (Newly available Sep 2023, Widely available Mar 2026) lets nested card headers and footers snap cleanly to parent grid tracks.
.card-wrap { container-type: inline-size; }
@container (min-width: 440px) {
.card { grid-template-columns: 160px 1fr; }
}
.card-grid-item {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
}
CSS 03 // Floating Geometry CSS Anchor Positioning
Replaces Popper.js and Floating UI by tethering tooltips, menus and callouts directly to a target element using anchor-name, position-anchor and the anchor() function. This eliminates forced synchronous layout recalculations from getBoundingClientRect() inside scroll listeners. It still has Limited availability (Firefox doesn't support it yet), so wrap it in @supports (anchor-name: --a) and keep a simple fallback position.
#trigger { anchor-name: --menu-btn; }
.tooltip {
position: absolute;
position-anchor: --menu-btn;
top: anchor(bottom);
left: anchor(center);
}
CSS 04 // Perceptual Colour oklch() and color-mix()
Unlike RGB or HSL (where yellow looks much brighter than blue at identical lightness numbers), oklch(L C H) models human perception uniformly across Lightness, Chroma and Hue. Combined with color-mix(), design systems generate hover shades and subtle tints dynamically in pure CSS. Both have been Baseline Widely available since November 2025.
:root {
--brand: oklch(68% 0.17 245);
--brand-tint: color-mix(in oklch, var(--brand) 16%, transparent);
}
CSS 05 // Discrete Transitions @starting-style & allow-discrete
Previously, animating an element from display: none required JavaScript timers and forced reflows. Now transition-behavior: allow-discrete keeps top-layer dialogs and popovers visible while animating out, while @starting-style defines their initial entry frame declaratively. Both have been Baseline Newly available since August 2024.
dialog {
opacity: 0;
transition: opacity 0.25s, display 0.25s allow-discrete;
}
dialog[open] { opacity: 1; }
@starting-style { dialog[open] { opacity: 0; } }
CSS 06 // Selectors & Math :has(), sibling-count(), shape() & :paused
The :has() relational selector (Newly available Dec 2023, Widely available June 2026) styles parents based on child states. sibling-index() and sibling-count() (Newly available Aug 2026) expose integers for proportional calc() widths or staggered delays. shape() (Newly available Feb 2026) builds responsive clip-path vectors, and :paused, one of the media element pseudo-classes, styles paused <audio> and <video> elements (Newly available Nov 2026).
.item {
width: calc(100% / sibling-count());
transition-delay: calc((sibling-index() - 1) * 50ms);
}
video:paused { outline: 2px solid var(--warning); }