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.
Fundamentals
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.
Foundation
📝 Syntax
The syntax for the inset property follows the same value-count rules as margin and padding:
syntax.css
element{inset:toprightbottomleft;}
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:10px20px30px40px;}
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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
auto (each side)
Applies to
Positioned elements (relative, absolute, fixed, sticky)
Inherited
No
Animatable
Yes, as a length
Common use
Overlays, pinned UI, and absolutely positioned layout boxes
Reference
💎 Property Values
Value
Description
length
A fixed offset such as 10px, 1rem, or 2em.
percentage
An offset relative to the containing block size, such as 50%.
auto
Lets the browser determine the offset based on other positioning rules.
Scope
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.
Preview
👀 Live Preview
An absolutely positioned box with inset: 12px 20px 28px 36px inside a dashed container:
Hands-On
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: 1rem 1rem auto auto sets top and right offsets while leaving bottom and left on auto, pinning the toast to the top-right corner.
A11y
♿ 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.
Compatibility
🖥 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 Chrome87+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari14.1+ · macOS & iOS
Full support
Microsoft Edge87+ · Chromium
Full support
Opera73+ · Modern versions
Full support
inset property94% supported
Bottom line: Safe to use in modern projects. For very old browsers, expand to individual top, right, bottom, and left declarations.
Wrap Up
🎉 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.