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.

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

Newsletter? I have it!

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.

  • No fixed frequency, but at least once at month;
  • I do not plan on having content exclusive to the newsletter. Everything on it will also be on the blog;
  • I will never, ever ever ever, send you any form of spam.

You might also like

View blog

“Classic rock, Mario Kart, and why we can't agree on Tailwind”

1 min read

Great article from Josh Collinsworth explaining why Tailwind is good and bad for the exact same reasons.

Reading Recs
Read

Fantinel.dev v5 is here!

10 min read

Out with the green waves, in with the rainbow of pastel colors!

Meta
Read

Setting up Storybook on an Astro project

7 min read

I really, really thought this was gonna be easy.

Front-End
Read

text-overflow: ellipsis on multi-line text

2 min read

Adding an automatic ellipsis to some text if it overflows its content is simple enough. But what if you want your text to have multiple lines?

Front-End
Read