TIL – CSS inset property shorthand

evanwinter

Evan Winter

Posted on February 16, 2022

TIL – CSS inset property shorthand

I recently learned about inset, a CSS shorthand for top, right, left, and bottom properties.

I've used it a lot as a more expressive way of saying, "this thing is full-screen".

For example, to make an element take over the entire screen:

.fullscreen {
  position: fixed;
  inset: 0;
}
Enter fullscreen mode Exit fullscreen mode

It's effectively the same thing as:

.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

// or, what I always used to do...

.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
}
Enter fullscreen mode Exit fullscreen mode

MDN Docs: https://developer.mozilla.org/en-US/docs/Web/CSS/inset

💖 💪 🙅 🚩
evanwinter
Evan Winter

Posted on February 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Today I learned about "place-items"
todayilearned Today I learned about "place-items"

October 5, 2022

TIL – CSS inset property shorthand
todayilearned TIL – CSS inset property shorthand

February 16, 2022

TIL CSS conic gradient
todayilearned TIL CSS conic gradient

January 23, 2022

A CSS container queries example
css A CSS container queries example

January 11, 2022