CSS's "isolation" property is pretty cool

by Matt Fantinel
24 Nov 2023 - 1 min read

isolation is a special property whose sole and unique purpose is to create a new stacking context on the element it is applied to, with no other side-effects. 😄

– Francesco Vetere, in The CSS property you didn't know you needed

You learn something new everyday! Today, I learned about CSS's isolation property. I learned it through this Francesco Vetere post, which I highly recommend you to read, as he explains it way better than I do.

Basically, isolation: isolate is a very simple way of creating a stacking context in CSS. Stacking context is basically a "reset" of how z-index works, so you can manage indexes in a smaller scope.

Francesco gives a perfect example of a card element with a decorative element in its background. To make that element appear below the text, you'd naturally add z-index: -1;, but that means the element would show below the card as well! By creating a new stacking context on the card, you can safely manage z-index without worrying about any child element appearing below/outside its parent.

Did this blog post change your life? Or maybe I made a mistake that ruined your day? You can always send me an email to tell me about it.

hello@fantinel.dev

Written by

Matt Fantinel

I’m a web developer trying to figure out this weird thing called the internet. I write about development, the web, games, music, and whatever else I feel like writing about!

About

Wanna get the next posts right in your (e-)mailbox?

I have a newsletter as another way to share what I write on this blog. The main goal is to be able to reach people who don't use RSS or just prefer getting their articles delivered straight into their inbox.

When subscribed, you'll receive:

  • All the blog posts I write here;
  • Monthly digests of all the cool links I share, every last day of the month;
  • No spam, no advertising. I promise.