← All blog posts
🎨
css

10 Modern CSS Techniques Every Developer Should Know in 2026

From container queries to :has() selector, modern CSS has changed how we build layouts. Here are 10 techniques that will make your code cleaner and faster.

10 Modern CSS Techniques for 2026

CSS has evolved dramatically in the last few years. What used to require JavaScript or complex workarounds can now be done with a single line of CSS. Let's explore 10 techniques that will level up your styling game.

1. Container Queries

Container queries let you style elements based on their parent's size, not the viewport. This is a game-changer for component-based design.

css
.card-container {
  container-type: inline-size;
}

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

2. The :has() Selector

Often called the "parent selector", :has() lets you style an element based on what it contains.

css
/* Highlight a form that has an invalid input */
form:has(input:invalid) {
  border: 2px solid red;
}

/* Card with image gets extra padding */
.card:has(img) {
  padding: 24px;
}

3. CSS Nesting

No more repeating parent selectors. Nesting is now native CSS.

css
.nav {
  padding: 16px;

  & > a {
    color: blue;

    &:hover {
      color: darkblue;
    }
  }
}

4. Logical Properties

Use margin-inline, padding-block, inset-inline-start instead of physical left/right. They automatically flip for RTL languages like Urdu.

css
.alert {
  padding-inline: 16px;
  margin-block: 8px;
  inset-inline-start: 0;
}

5. Aspect Ratio

Control element proportions without padding hacks.

css
.thumbnail {
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: cover;
}

6. clamp() for Fluid Typography

Make text scale smoothly between min and max sizes based on viewport width.

css
h1 {
  font-size: clamp(1.5rem, 4vw, 3rem);
}

7. CSS Layers

Control cascade specificity with @layer. Useful when combining multiple CSS frameworks.

css
@layer reset, base, components, utilities;

@layer components {
  .btn { /* component styles */ }
}

8. Subgrid

Let grid items align with the parent grid. Perfect for card layouts.

css
.card {
  grid-column: span 2;
  grid-template-rows: subgrid;
}

9. View Transitions API

Smooth animations between page states, native CSS.

css
@view-transition {
  navigation: auto;
}

.card {
  view-transition-name: card-image;
}

10. Color-mix() and OKLCH

Mix colors and use perceptually-uniform color spaces.

css
.button {
  background: color-mix(in oklch, var(--brand) 80%, white);
  color: oklch(0.95 0.05 200);
}

Conclusion

These techniques are supported in all modern browsers (Chrome, Firefox, Safari, Edge). Start using them today to write cleaner, more maintainable CSS. The w3primecode CSS Effects library has live demos of all of these — explore them in the CSS Effects section!