Skip to content
Tutorials Center
My learning

Topics

CSS Reference · Positioning and Stacking

The inset property

Reference for the CSS inset shorthand: set top, right, bottom and left in one declaration, with one to four values, plus overlay and stretch patterns.

The inset property is a shorthand for top, right, bottom and left. It accepts one to four values and follows the same pattern as margin. Like the longhands, it only affects positioned elements.

Its best-known trick is inset: 0 on an absolutely positioned element, which stretches the element to fill its containing block. That is the shortest way to build overlays, backdrops and full-bleed layers.

CSS
.overlay {
  position: absolute;
  inset: 0;
}

Try it

inset: 0 overlays and shorthand values

Syntax

CSS
inset: <'top'>{1,4};

inset: 0;               /* all four sides */
inset: 10px 20px;       /* top/bottom 10px, left/right 20px */
inset: 0 auto auto 0;   /* top, right, bottom, left */
  • Initial value: auto (for each longhand)
  • Applies to: positioned elements
  • Inherited: no
  • Percentages: vertical offsets use the containing block's height, horizontal ones its width
  • Animatable: yes, as lengths or percentages
  • Computed value: as for the longhands

Values

Number of values Meaning
One All four sides.
Two First value: top and bottom. Second: left and right.
Three Top, then left and right, then bottom.
Four Top, right, bottom, left (clockwise).

Each value can be auto, a <length>, a <percentage>, or an anchor() expression.

Usage notes

  • inset: 0 stretch. With position: absolute (or fixed) and no width/height, all four edges pin to the containing block. Use it for modal backdrops and image overlays.
  • Centering a sized box. inset: 0; margin: auto; width: 300px; height: 200px; centers an absolutely positioned element both ways.
  • Positioned only. On a static element, inset does nothing. Dialogs opened with showModal() are positioned by the user agent, and the default inset there is 0.
  • Physical, not logical. Order is top, right, bottom, left regardless of writing mode. For direction-aware offsets use inset-block and inset-inline.
  • Cascade caution. A later top: 10px overrides the top part of an earlier inset, and vice versa.

Browser support

Supported in all modern browsers since 2021 (Baseline). Very old browsers need the four separate longhands.