CSS inset Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Positioning

What You’ll Learn

The inset property is a shorthand for setting all four offset sides at once. It simplifies absolute, fixed, and sticky positioning in modern CSS.

01

Shorthand

Four sides.

02

auto

Default value.

03

absolute

Common use.

04

inset: 0

Full stretch.

05

fixed

Viewport pin.

06

Offsets

px, %, rem.

Introduction

The inset property in CSS is a shorthand for setting the top, right, bottom, and left properties all at once. It reduces repetition and makes positioning rules easier to read.

The property is especially useful with position: absolute and position: fixed, where you need precise control over how far an element sits from each edge of its containing block.

Definition and Usage

Apply inset on positioned elements inside a containing block. The parent usually needs position: relative for absolute children, or the viewport acts as the containing block for fixed elements.

💡
Beginner Tip

inset: 0 is a popular pattern that stretches an element to fill its positioned parent — perfect for overlays and full-bleed backgrounds.

📝 Syntax

The syntax for the inset property follows the same value-count rules as margin and padding:

syntax.css
element {
  inset: top right bottom left;
}
  • One value — applies to all four sides.
  • Two values — first applies to top and bottom; second to left and right.
  • Three values — first to top; second to left and right; third to bottom.
  • Four values — top, right, bottom, left (clockwise).

Basic Example

inset-basic.css
.box {
  position: absolute;
  inset: 10px 20px 30px 40px;
}
inset: 0; inset: 1rem; inset: 20px 40px; inset: 1rem auto auto 1rem;

Default Value

The default value of the inset property is auto for all sides, meaning no explicit offset is applied until you set one.

Syntax Rules

  • Only works when position is not static.
  • Shorthand for top, right, bottom, and left.
  • The property is not inherited.
  • Accepts length, percentage, and auto values.
  • Also maps to logical inset longhands in supporting browsers.

⚡ Quick Reference

QuestionAnswer
Initial valueauto (each side)
Applies toPositioned elements (relative, absolute, fixed, sticky)
InheritedNo
AnimatableYes, as a length
Common useOverlays, pinned UI, and absolutely positioned layout boxes

💎 Property Values

ValueDescription
lengthA fixed offset such as 10px, 1rem, or 2em.
percentageAn offset relative to the containing block size, such as 50%.
autoLets the browser determine the offset based on other positioning rules.

Requires Positioned Elements

inset controls offset distances from the edges of a containing block. It works with these position values:

  • position: absolute — offsets relative to the nearest positioned ancestor.
  • position: fixed — offsets relative to the viewport.
  • position: sticky — offsets apply when the element becomes stuck.
  • position: relative — offsets shift the element from its normal position.
Not the Same as Margin

inset positions an element inside its containing block. margin adds outer spacing and works on non-positioned elements too.

👀 Live Preview

An absolutely positioned box with inset: 12px 20px 28px 36px inside a dashed container:

Examples Gallery

Set four offset values, stretch with inset: 0, use two-value shorthand, and pin a fixed toast to the viewport.

🔢 Offset Shorthand

Start with the reference example — four different offsets on an absolutely positioned box.

Example 1 — Four-Value Inset

Position a box 10px from the top, 20px from the right, 30px from the bottom, and 40px from the left.

inset-four.css
.box {
  position: absolute;
  inset: 10px 20px 30px 40px;
  background-color: #fb923c;
}
Try It Yourself

How It Works

Values are applied clockwise: top, right, bottom, left. The orange box sits inset from every edge of the gray container.

Example 2 — Stretch with inset: 0

Make an overlay fill its positioned parent completely.

inset-zero.css
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.85);
}
Try It Yourself

How It Works

inset: 0 sets all four sides to zero, so the element stretches to match the container edges.

📈 Shorthand & Fixed UI

Use two-value shorthand and fixed positioning for real UI patterns.

Example 3 — Two-Value Inset

Set vertical and horizontal offsets with just two values.

inset-two.css
.box {
  position: absolute;
  inset: 20px 40px;
}
Try It Yourself

How It Works

The first value applies to top and bottom. The second applies to left and right.

Example 4 — Fixed Toast Notification

Pin a toast to the top-right corner of the viewport with position: fixed.

inset-fixed.css
.toast {
  position: fixed;
  inset: 1rem 1rem auto auto;
}
Try It Yourself

How It Works

inset: 1rem 1rem auto auto sets top and right offsets while leaving bottom and left on auto, pinning the toast to the top-right corner.

♿ Accessibility

  • Fixed overlays can trap focus — Ensure modals and dialogs manage keyboard focus correctly.
  • Do not cover essential content — Toasts and pinned UI should not hide critical page controls.
  • Support zoom and small screens — Test inset values on mobile viewports.
  • Announce dynamic toasts — Use role="status" or live regions for notifications.
  • Keep logical tab order — Positioning with inset does not change DOM reading order.

🧠 How inset Works

1

Element is positioned

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

Position
2

inset sets four offsets

One declaration replaces separate top, right, bottom, and left rules.

CSS rule
3

Browser places the box

The element is offset from the edges of its containing block or viewport.

Layout
=

Precise placement

Overlays, cards, and UI elements land exactly where you want them.

🖥 Browser Compatibility

The inset property is supported in modern browsers including Chrome 87+, Firefox 66+, Safari 14.1+, and Edge 87+.

Baseline · Modern browsers

Shorthand positioning in today’s browsers

All major browsers support inset as a cleaner alternative to four separate offset properties.

94% Modern browser support
Google Chrome 87+ · Desktop & Mobile
Full support
Mozilla Firefox 66+ · Desktop & Mobile
Full support
Apple Safari 14.1+ · macOS & iOS
Full support
Microsoft Edge 87+ · Chromium
Full support
Opera 73+ · Modern versions
Full support
inset property 94% supported

Bottom line: Safe to use in modern projects. For very old browsers, expand to individual top, right, bottom, and left declarations.

🎉 Conclusion

The inset property is a convenient shorthand for setting offset distances on positioned elements. It makes absolute and fixed layouts cleaner, especially for overlays, pinned UI, and responsive components.

For beginners, remember the essentials: set a non-static position, use inset: 0 to fill a container, and apply one to four values just like margin shorthand.

💡 Best Practices

✅ Do

  • Use inset: 0 for full-bleed overlays
  • Pair absolute children with a relative parent
  • Use two-value shorthand for equal vertical and horizontal offsets
  • Combine with position: fixed for pinned UI
  • Test offsets on mobile and zoomed views

❌ Don’t

  • Apply inset without setting position
  • Confuse inset with margin or padding
  • Cover important controls with fixed overlays
  • Forget containing block context for absolute elements
  • Overuse fixed positioning for main page content

Key Takeaways

Knowledge Unlocked

Five things to remember about inset

Use these points when positioning elements with CSS.

5
Core concepts
auto 02

Default auto

No offset.

Default
0 03

inset: 0

Full fill.

Syntax
fixed 04

Positioned

Required.

Pattern
TRBL 05

Clockwise

Top to left.

Values

❓ Frequently Asked Questions

inset is a shorthand that sets top, right, bottom, and left offsets in one declaration for positioned elements.
The default is auto for each side, which lets the browser determine placement based on other positioning rules.
No. inset only affects elements with position set to relative, absolute, fixed, or sticky.
inset moves a positioned element relative to its containing block. margin adds space outside an element in normal document flow.
No. inset is not inherited.

Practice in the Live Editor

Open the HTML editor, try inset values with absolute and fixed positioning, and build your own overlay layout.

HTML Editor →

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.

5 people found this page helpful