Back to journal
Frontend

5 CSS Tricks That Make Senior Devs Say 'Wait, That Works?'

From container queries to the :has() selector — these CSS features feel like cheating. Copy-paste these into your next project and watch your team's reaction.

PMML Engineering · Studio 19 May 2026 7 min read 0 views
5 CSS Tricks That Make Senior Devs Say 'Wait, That Works?'

Every few months, CSS ships something that makes you rethink everything. Here are 5 features that consistently surprise experienced developers — with copy-paste examples you can use right now.

1. The :has() Selector (CSS's "Parent Selector")

CSS selector visualization

For years, developers said "CSS will never have a parent selector." Well, it does now.

/* Style a card differently when it contains an image */
.card:has(img) {
  grid-template-rows: 200px 1fr;
}

/* Style a form when any input is invalid */
form:has(:invalid) {
  border-left: 3px solid #ef4444;
}

/* Style a nav item when its dropdown is open */
.nav-item:has(.dropdown:target) {
  background: rgba(0, 0, 0, 0.1);
}

This changes everything. No more JavaScript for parent-based styling. No more extra classes. Just CSS doing what CSS should do.

2. Container Queries — Responsive Components, Not Pages

Media queries respond to the viewport. Container queries respond to the parent container. This is the difference between responsive pages and responsive components.

.card-grid {
  container-type: inline-size;
  container-name: cards;
}

@container cards (min-width: 400px) {
  .card {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 1rem;
  }
}

@container cards (min-width: 700px) {
  .card {
    grid-template-columns: 200px 1fr;
  }
  .card__title {
    font-size: 1.5rem;
  }
}

Responsive design across devices

Drop a component into a sidebar? It adapts. Move it to a full-width section? It adapts. No props, no JavaScript.

3. Subgrid — Finally, Aligned Nested Grids

Before subgrid, aligning items across nested grid children was a nightmare of fragile hacks. Now:

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
}

.card {
  display: grid;
  grid-template-rows: subgrid;
  grid-row: span 3; /* title, body, footer */
}

Every card's title, body, and footer now align perfectly across the row — regardless of content length. One CSS property replaces dozens of lines of JavaScript height-syncing logic.

4. Scroll-Driven Animations — No JavaScript Required

@keyframes reveal {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section {
  animation: reveal linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 40%;
}

Animation visualization

This replaces IntersectionObserver + GSAP/Framer Motion for most scroll animations. Zero JavaScript. Zero bundle size. Buttery smooth 60fps because it's compositor-driven.

Parallax in 3 Lines

.hero-bg {
  animation: parallax linear;
  animation-timeline: scroll();
}

@keyframes parallax {
  to { transform: translateY(-20%); }
}

5. View Transitions API — Page Transitions in 2 Lines

@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: fade-out 0.3s ease;
}

::view-transition-new(root) {
  animation: fade-in 0.3s ease;
}

With Next.js or any MPA/SPA framework, this gives you native app-like page transitions. No library needed. You can even name specific elements for shared-element transitions:

.product-image {
  view-transition-name: product-hero;
}

The Takeaway

CSS in 2026 is a fundamentally different language than CSS in 2020. If you're still reaching for JavaScript for layout, scroll effects, parent selection, or page transitions — check if CSS can do it first. You might be surprised.

Which trick surprised you most? Share this with your team and find out which ones they didn't know about.

#css#webdev#tips#frontend

Keep reading

You might also like