Modern CSS Features Every Developer Should Know in 2026 (Grid, Container Queries, :has() and More)
A practical, no-fluff guide to modern CSS - CSS Grid, subgrid, container queries, and the :has() selector - for beginners and experienced developers alike.

Author
Shalimar Mehra
The Basics You Still Need (Even If You Skip Everything Else)
Before Grid, before container queries, before any of the shiny stuff - there are three ideas that everything else in CSS is built on. If these feel shaky, the advanced sections won't stick.
The Box Model
Every element on a page is a rectangle (yes, even that circular avatar - it's a rectangle with rounded corners pretending). That rectangle is made of four layers, from the inside out: content, padding, border, and margin. Padding pushes the border outward from the content; margin pushes everything else away from the border.
The single most useful line of CSS you'll ever write is this one:
*, *::before, *::after {
box-sizing: border-box;
}
Without it, setting width: 200px on an element and then adding padding: 20px gives you an element that's actually 240px wide, because padding gets added on top of your width by default. With border-box, the padding eats into the width instead, so your element stays exactly 200px. It sounds small. It will save you from so much confusion later.
Selectors and Specificity
CSS decides which rule "wins" using a scoring system: inline styles beat IDs, IDs beat classes, classes beat element selectors. When two rules tie, whichever one is written last in the stylesheet wins.
Most real-world bugs where "my CSS isn't applying" trace back to specificity a rule you wrote is technically correct, but something else is scoring higher. The fix is almost never !important (please, resist the urge). The fix is understanding which selector is winning and adjusting from there.
Flexbox, Briefly
Flexbox solved one-dimensional layout rows or columns and it's still exactly the right tool for things like navbars, button groups, or centering a single item:
.nav {
display: flex;
justify-content: space-between;
align-items: center;
}
If you only remember one thing: Flexbox is for lines. For anything two-dimensional rows and columns together you want Grid, which brings us to the good stuff.
CSS Grid: The Layout Tool That Actually Thinks in Two Dimensions
Grid gets treated like an "advanced" feature, but honestly, beginners should learn it earlier than they usually do. It's more intuitive than the float-and-clearfix hacks it replaced.
Here's a basic three-column layout:
.gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
}
That's a fully responsive-ready grid in four lines. Compare that to the pre-Grid era, where the same result meant floated columns, manual width percentages, and clearing floats with a pseudo-element hack that nobody fully understood but everyone copy-pasted.
Subgrid: The Feature That Fixes Grid's Biggest Annoyance
Here's the gotcha that used to drive me up the wall. Say you have a grid of cards, and each card has its own internal header, body, and footer. You want all the headers to align across cards, even if their content is different heights. With regular Grid, each card is its own isolated grid there's no way for a card's internal rows to line up with its siblings.
Subgrid fixes exactly this:
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
}
Now the card's internal rows inherit the sizing from its parent grid, so everything lines up automatically, even with wildly uneven content. Before subgrid, people solved this with JavaScript that measured element heights and forced them to match fragile, layout-thrashing, and annoying to maintain. Subgrid does it natively, with zero JS.
Container Queries: Finally, Components That Respond to Themselves
This is the one that changed how I think about component design entirely.
Media queries respond to the viewport the browser window. That's fine until you build a reusable card component and drop it into a wide main column in one place and a narrow sidebar in another. A media query can't tell the difference; it only knows the screen is, say, 1400px wide. But your sidebar card might only have 300px of actual space.
Container queries solve this by letting an element respond to its own container's size, not the viewport:
.card-wrapper {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 400px) {
.card {
grid-template-columns: 120px 1fr;
}
}
Now the exact same .card component automatically switches to a horizontal layout when it has 400px of room, and stacks vertically when it's squeezed into a narrow sidebar regardless of the actual screen size. This is the difference between designing pages and designing components, and it's a genuinely big deal for anyone building a design system or component library.
The :has() Selector: CSS Finally Gets a "Parent Selector"
For as long as CSS has existed, there's been one glaring gap: you could style a child based on its parent, but never the reverse. Want to style a .form-group differently if it contains an invalid input? That used to require JavaScript, full stop.
:has() closes that gap:
.form-group:has(input:invalid) {
border-color: crimson;
}
.card:has(img) {
grid-template-columns: 200px 1fr;
}
The first rule highlights a form group the moment its input becomes invalid no JS event listeners required. The second gives cards an image column only if they actually contain an image, so image-less cards don't leave an awkward empty gap. People have started calling :has() the "parent selector," and honestly, that undersells it it's more like CSS gaining conditional logic.
Putting It Together: A Small Real-World Example
Let's say you're building a responsive card grid that also handles cards with and without images, and needs to work inside both a wide blog layout and a narrow sidebar widget.
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
gap: 1.5rem;
}
.card-wrapper {
container-type: inline-size;
}
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 2;
border: 1px solid #e2e2e2;
border-radius: 8px;
overflow: hidden;
}
.card:has(img) {
grid-template-rows: auto 1fr;
}
@container (min-width: 380px) {
.card {
grid-template-columns: 140px 1fr;
}
}
Four modern CSS features, working together, with no JavaScript. Ten years ago this same behavior would've meant a layout library, a resize observer, and probably a headache.
Beginner vs. Advanced: Quick Reference
Feature | Skill Level | Solves |
|---|---|---|
Box model + | π’ Beginner | Predictable sizing |
Flexbox | π’ Beginner | One-dimensional layout |
CSS Grid | π’π΄ Both | Two-dimensional layout |
Subgrid | π΄ Advanced | Aligning nested grid items |
Container queries | π΄ Advanced | Component-based responsiveness |
| π΄ Advanced | Parent/conditional styling without JS |
FAQ
Do I still need Flexbox if I learn CSS Grid? Yes. They solve different problems. Flexbox is best for one-dimensional layouts like navbars or button rows; Grid is best when you need to control both rows and columns at once. Most real projects use both.
Are container queries supported in all browsers? As of 2026, container queries have solid support across all major evergreen browsers (Chrome, Firefox, Safari, Edge). Always check current support on caniuse.com before relying on them in production for older browser targets.
What's the difference between :has() and a regular pseudo-class? Regular pseudo-classes like :hover or :first-child describe the element's own state or position. :has() lets an element's style depend on its descendants something CSS genuinely couldn't do before.
Is subgrid the same as nested Grid? No. A nested grid creates a completely independent grid inside a cell, with no relationship to the parent's rows or columns. Subgrid explicitly inherits the parent grid's track sizing, so children align across separate grid items.
Do I need to learn all of this at once? No. Get comfortable with the box model and Flexbox first. Add Grid once you're building actual layouts. Container queries and :has() are worth learning as soon as you're building reusable components which, honestly, is most real projects.
Further reading: MDN - CSS Grid Layout, MDN - CSS Containment, web.dev - New to the web platform.
Further Reading - Is WordPress Still Worth It in 2026? Pros, Cons, Costs & Best Tools
Community Discussion
Loading comments...
Join the Conversation
Log in to post your thoughts, ask questions, and engage with authors and developers.
Log in to Comment