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

The next post can go straight to your inbox!

I don't post on a schedule, so the best way to see new stuff is to subscribe. Grab an RSS feed for just the things you care about, or subscribe to the newsletter to get them right in your inbox.