::before, ::after, :has(), :is(), :where(), :focus-visible, :user-invalid, ::backdrop & initial-letter
Using pseudo-elements to render decorative geometry behind images using z-index: -1 and various transform/position offsets.
isolation: isolate to .relative, each element forms its own independent stacking context. This ensures the khaki ::before circles sit behind the <img> but stay in front of the card background, rather than disappearing underneath the container!
.relative {
position: relative;
border: 2px solid red;
isolation: isolate; /* Creates independent stacking context */
}
.relative::before {
content: "";
background-color: khaki;
width: 100%;
padding-bottom: 100%;
border-radius: 50%;
position: absolute;
top: 50%; left: 50%;
z-index: -1;
transform: scale(1.5);
}
Style parent containers based on the status of their internal children or form validation states.
Click the checkbox above. Notice how the parent card border lights up with a teal shadow via .card:has(input:checked)!
form:has(input:invalid:not(:placeholder-shown))
/* Styles card when internal checkbox is checked */
.card:has(input[type="checkbox"]:checked) {
border-color: #008080;
background-color: #f0fdfa;
box-shadow: 0 4px 12px rgba(0, 128, 128, 0.18);
}
/* Styles form container when email field is invalid */
form:has(input:invalid) {
border: 2px solid #ef4444;
}
:is() simplifies compound selectors (taking the highest specificity), while :where() always has zero (0) specificity for hassle-free defaults.
Because :where() has 0 specificity, any utility class can easily override it without needing !important.
/* Zero-specificity baseline styles */
:where(h1, h2, h3) { margin: 0; }
/* Accessible keyboard-only focus indicator */
button:focus { outline: none; }
button:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
Unlike :invalid (which turns red immediately upon page load before the user even types), :user-invalid only displays validation feedback after user interaction and blur!
input:user-valid { border-color: #10b981; background-color: #f0fdf4; }
input:user-invalid { border-color: #ef4444; background-color: #fef2f2; }
HTML5 native <dialog> elements reside in the browser's Top Layer. Style the background scrim directly with dialog::backdrop.
dialog::backdrop {
background-color: rgba(15, 23, 42, 0.65);
backdrop-filter: blur(6px); /* Blurs page content behind modal! */
}
Cascading Style Sheets have evolved dramatically in recent specifications, giving developers fine-grained control over typography and layout.
Hover over this keyword to trigger a tooltip created with attr(data-tooltip) and ::after.
/* Custom bullet markers */
ul li::marker { content: "⚡ "; color: #008080; }
/* Magazine-style initial letter (Drop Cap) */
p::first-letter { initial-letter: 3 2; color: #008080; }