CSS has evolved significantly, introducing powerful features that simplify styling, improve responsiveness, and enhance accessibility. If you’ve been relying on frameworks like Tailwind, it’s time to explore native CSS capabilities that make development smoother.
✅ Clamp() – Combines min()
and max()
to create perfectly fluid typography. ✅ Min() – Ensures elements don’t exceed a maximum width. ✅ Max() – Prevents elements from shrinking too much on small screens.
✅ Example:
.dashboard-title {
font-size: clamp(1.5rem, 5vw, 3rem);
}
✅ Make elements adapt to their parent container instead of the viewport. ✅ Perfect for reusable UI components that need dynamic styling.
✅ Example:
.cards {
container-type: inline-size;
}
@container (width > 200px) {
.card {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
✅ Balance – Creates even line lengths for better visual appeal. ✅ Pretty – Prevents orphaned words at the end of paragraphs.
✅ Example:
.section-title {
text-wrap: balance;
}
.card-description {
text-wrap: pretty;
}
✅ Properly animate elements from display: none
without hacks.
✅ Example:
.modal {
display: none;
opacity: 1;
}
.modal.open {
display: block;
transition: opacity 300ms;
opacity: 1;
}
@starting-style {
.modal.open {
opacity: 0;
}
}
✅ Select parent elements based on child conditions—previously impossible in CSS.
✅ Example:
.card:has(.error-message) {
border-color: red;
background: rgb(255 0 0 / 0.05);
}
✅ Use comparison operators instead of verbose min-width
/ max-width
.
✅ Example:
@media (768px <= width <= 1199px) {
.card {
width: 65ch;
}
}
✅ Apply different colors based on user preferences without separate media queries.
✅ Example:
.card {
background: light-dark(#f1f5f9, #0f172a);
color: light-dark(#0f172a, #f1f5f9);
}
✅ Eliminate preprocessors and write cleaner, structured CSS.
✅ Example:
.card {
padding: 1rem;
& .header {
font-size: 1.7rem;
}
& :hover {
background: #f1f5f9;
}
}
✅ New units (dvh
, svh
, lvh
) adjust for mobile browser UI elements.
✅ Example:
.container {
height: dvh;
}
✅ Explicitly order style groups to control priority.
✅ Example:
@layer reset, components, utilities;
@layer reset {
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
}
@layer components {
.button {
padding: 0.5rem 1rem;
background: blue;
}
}
@layer utilities {
.p-4 {
padding: 1.25rem;
}
}
These modern CSS features reduce reliance on preprocessors, making CSS more powerful and future-proof.
🔥 Which modern CSS feature excites you the most? Let’s discuss! 🚀
Join Shikhil on Peerlist!
Join amazing folks like Shikhil and thousands of other people in tech.
Create ProfileJoin with Shikhil’s personal invite link.
0
8
0