CSS inset Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The inset property is a shorthand for top, right, bottom, and left. It uses the same 1–4 value pattern as margin.

It only affects positioned elements (relative, absolute, fixed, or sticky). The offsets are physical, not logical — for writing-mode-aware sides use inset-block and inset-inline.

Baseline · Widely available.

Not deprecated and not experimental. Supported in modern browsers since April 2021. Internet Explorer does not support inset.

CSS Syntax

syntax.css
inset: <length> | <percentage> | auto | initial | inherit;

Like margin: one value = all sides; two = top/bottom then left/right; three = top, left/right, bottom; four = top, right, bottom, left. Each longhand starts as auto. The property is not inherited.

Property Values

ValueDescriptionTry it
One valueSame offset on all four sidesTry it
Two valuesTop/bottom, then left/rightTry it
Four valuesTop, right, bottom, leftTry it
0Pin all sides; absolute box can fill the containing blockTry it
Needs positionWithout a positioned value, inset does nothingTry it
initialResets each side to autoTry it
inheritUses the parent’s inset valueTry it

How to Use inset

Position the element first, then set offsets with inset.

  1. Make a containing block if needed (often position: relative on the parent).
  2. Set the child to position: absolute (or fixed / sticky / relative).
  3. Apply inset with one to four length or percentage values.
  4. Use inset: 0 when you want an absolute child to stretch and fill the parent.
PieceRequired?Role
position ≠ staticYesWithout it, inset is ignored
Containing blockUsuallyRelative parent for absolute children
1–4 inset valuesYesSame mapping as margin shorthand
Logical alternativeOptionalinset-block / inset-inline follow writing mode

Live Preview

The blue box is position: absolute inside a relative stage. Change only inset.

inset: 0 stretches the absolute box to the stage edges.

Box

inset: 16px

CSS Examples

Each snippet focuses on inset. Position is required so the offsets apply. Use Try It Yourself for a live editor.

Example 1 — Same Offset on All Sides

Pull an absolute box 16px in from every edge.

CSS
<style>
  .stage { position: relative; height: 140px; border: 1px dashed #94a3b8; }
  .box {
    position: absolute;
    inset: 16px;
    background: #2563eb;
    color: #fff;
  }
</style>

<div class="stage">
  <div class="box">inset: 16px</div>
</div>
Try It Yourself

How It Works

  1. Create a containing block. position: relative on the stage.
  2. Position the child. position: absolute enables inset.
  3. One length for all sides. inset: 16px equals top/right/bottom/left of 16px.
  4. Box shrinks inward. With auto width/height it fills the space inside those offsets.

Example 2 — Fill the Parent (inset: 0)

Stretch an absolute child to cover the whole stage.

CSS
<style>
  .stage { position: relative; height: 140px; border: 1px dashed #94a3b8; }
  .box {
    position: absolute;
    inset: 0;
    background: #2563eb;
    color: #fff;
  }
</style>

<div class="stage">
  <div class="box">inset: 0</div>
</div>
Try It Yourself

How It Works

  1. Keep absolute positioning. Same stage pattern as before.
  2. Zero every offset. inset: 0 sets top, right, bottom, and left to 0.
  3. Stretch to edges. The box fills the containing block.
  4. Common overlay pattern. Useful for full-area layers and backdrops.

Example 3 — Four Different Sides

Set top, right, bottom, and left independently.

CSS
<style>
  .stage { position: relative; height: 140px; border: 1px dashed #94a3b8; }
  .box {
    position: absolute;
    inset: 10px 20px 30px 40px;
    background: #2563eb;
    color: #fff;
  }
</style>

<div class="stage">
  <div class="box">T R B L</div>
</div>
Try It Yourself

How It Works

  1. Order matters. Four values mean top, right, bottom, left.
  2. Top 10px, right 20px. First two numbers set those edges.
  3. Bottom 30px, left 40px. Last two finish the rectangle.
  4. Same as longhands. Equivalent to setting each of top/right/bottom/left alone.

Edge Cases & Pitfalls

If inset seems ignored, check these first.

position

Static elements ignore inset

Set position to relative, absolute, fixed, or sticky first.

physical

inset is not logical

It always means top/right/bottom/left. For writing-mode-aware offsets use inset-block and inset-inline.

margin

Do not confuse with margin

margin spaces boxes in flow. inset offsets a positioned box against its containing block.

width

Fixed width fights stretch

If you set both inset: 0 and a fixed width/height, the size may not fill the parent the way you expect. Prefer auto size when stretching.

order

Four values are clockwise from top

Remember: top → right → bottom → left — the same order as margin and padding shorthands.

Browser Support

inset is a browser CSS property for positioned offsets. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

inset

Chrome 87+, Edge 87+, Firefox 66+, Safari 14.1+. Internet Explorer has no support — fall back to top/right/bottom/left there.

96% Modern browser support
Google Chrome 87+
Full support
Mozilla Firefox 66+
Full support
Apple Safari 14.1+
Full support
Microsoft Edge 87+
Full support
Opera 73+
Full support
Samsung Internet 14+
Full support
Internet Explorer No support
Not supported
inset Widely supported

Bottom line: Safe for modern sites. For Internet Explorer, write top, right, bottom, and left instead. It is not a runtime API.

Key Takeaways

  • Role: shorthand for physical top, right, bottom, and left.
  • Needs position: relative, absolute, fixed, or sticky.
  • Handy pattern: inset: 0 fills a positioned containing block.
  • Not logical: use inset-block / inset-inline for writing-mode sides.

One line: positioned box + inset: 16px; = four physical offsets in one rule.

Frequently Asked Questions

It is a shorthand for top, right, bottom, and left. One declaration can set all four physical offsets on a positioned element.
Each side defaults to auto, the same as the longhand properties. That leaves placement to other rules such as static position.
No. inset has no effect unless position is relative, absolute, fixed, or sticky.
No. Despite living near logical inset-* properties in the specs, inset always maps to physical top, right, bottom, and left. For logical sides use inset-block and inset-inline.
It sets every offset to 0, so the absolute element stretches to fill its positioned containing block (when width and height are auto).
It is Baseline Widely available. Chrome 87+, Edge 87+, Firefox 66+, and Safari 14.1+ support it. Internet Explorer does not. It is a browser CSS property, not a Node.js feature.

Next: inset-block

Set logical block-start and block-end offsets in one go.

inset-block tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful