Move over Flexbox and Grid β these lesser-known modern CSS techniques can drastically improve your UI design in 2025.
π Introduction
Modern web development is evolving fast. While Flexbox, Grid, and media queries are staples, modern CSS now includes features that blur the line between design and development β allowing developers to create dynamic, responsive, and interactive UIs without writing JavaScript.
In this post, Iβll walk you through modern CSS techniques that are powerful, underutilized, and production-ready β with code examples you can start using today.
1. :has()
β Parent Selectors Are Here! π―
Until recently, selecting a parent based on its child was impossible in pure CSS. But now with :has()
supported in most modern browsers, we can finally achieve this.
π§ Example
.card:has(.selected) {
border: 2px solid #00ffae;
background: #f0fdfa;
}
π‘ Use case
Highlight cards that contain a selected checkbox or tag β no JS required.
2. @layer
β CSS Layering for Predictable Styling π
With component libraries, third-party styles, and custom styles, CSS often becomes a mess. @layer
helps organize and prioritize styles better.
π§ Example
@layer reset, base, components, utilities;
@layer base {
body {
font-family: system-ui;
background-color: #f8f9fa;
}
}
@layer utilities {
.text-shadow {
text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}
}
π‘ Use case
Prevent style collisions and override third-party CSS in a predictable way.
3. accent-color
β Native Form Controls, Now Stylish π¨
Forms have long been hard to customize, especially checkboxes and radio buttons. Enter accent-color
.
π§ Example
input[type="checkbox"],
input[type="radio"] {
accent-color: #6f42c1;
}
π‘ Use case
Style native form elements to match your brand without custom JavaScript or images.
4. container queries
β Smarter Responsive Design π±β‘οΈπ₯
Media queries are global; container queries are local. They let components adapt based on the space theyβre given β not just screen size.
π§ Example
.card {
container-type: inline-size;
}
@container (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 1fr 2fr;
}
}
π‘ Use case
Make truly responsive components in design systems or cards that adapt within sidebars or modals.
5. scroll-timeline
& View Progress Animation πΉοΈ
Now you can tie animations to the scroll position using @scroll-timeline
. A native way to do scroll animations without JS!
π§ Example
@scroll-timeline progress {
time-range: auto;
}
.progress-bar {
animation: grow linear forwards;
animation-timeline: progress;
}
@keyframes grow {
from { width: 0; }
to { width: 100%; }
}
π‘ Use case
Create scroll progress indicators or parallax effects purely with CSS.
6. :is()
+ :where()
β Write Less, Do More π
Both pseudo-selectors simplify complex selectors. :is()
applies styles, :where()
does too but with zero specificity.
π§ Example
:is(h1, h2, h3) {
font-family: 'Merriweather', serif;
}
:where(.btn, .link) {
padding: 0.5rem 1rem;
}
π‘ Use case
Cleaner code with reduced repetition and better override behavior.
7. Modern @property
β Native Custom CSS Animations π«
This allows you to define custom properties that can animate like native properties.
π§ Example
@property --angle {
syntax: '<angle>';
inherits: false;
initial-value: 0deg;
}
.rotating {
animation: rotate 2s infinite linear;
}
@keyframes rotate {
from { --angle: 0deg; }
to { --angle: 360deg; }
}
.rotating::after {
transform: rotate(var(--angle));
}
π‘ Use case
Smoother animations with fully native performance β no JS necessary.
π₯ Bonus: Use backdrop-filter
for Glassmorphism UI
.glass {
backdrop-filter: blur(10px) brightness(1.1);
background-color: rgba(255, 255, 255, 0.1);
border-radius: 1rem;
padding: 1rem;
}
Result: Stunning βfrosted glassβ effect used in macOS and iOS UIs.
π Final Tips
β
Use tools like PostCSS, modern-normalize, and autoprefixer to ensure compatibility.
β
Try out CSS Houdini for even more custom styling magic.
β
Use DevTools to experiment live with all the above.
π¬ Wrap-Up
Modern CSS is no longer just about layout β itβs about power, clarity, and performance. Embrace these modern features to write less code, eliminate JS dependencies, and build cleaner, more maintainable UIs.
Letβs make CSS exciting again in 2025 β one feature at a time.
π Bonus: Interview CSS Question
Q: How can :has()
improve accessibility or user experience in forms?
π‘ Hint: Think about styling parent containers based on child inputs (e.g., when input has :invalid
, highlight the fieldset).
Top comments (0)