How to Use CSS inset-inline for Logical Positioning
The CSS inset-inline property is a modern logical
shorthand that defines the start and end offsets of a positioned element
along its inline axis. Instead of binding element placement to rigid
physical directions like left and right, inset-inline
adapts dynamically to the document’s writing mode and text direction.
This article explains how inset-inline works, breaks down
its syntax, demonstrates its interaction with international layouts, and
outlines why it is essential for modern web design.
What Is inset-inline?
The inset-inline property acts as a shorthand for two
distinct logical properties: inset-inline-start and
inset-inline-end. It functions identically to traditional
offset properties—such as left and right—with
the critical difference that it is aware of text flow rather than screen
geometry.
For inset-inline to take effect, the targeted element
must have a defined position context other than
static (such as relative,
absolute, fixed, or sticky).
Syntax and Value Assignment
The property accepts standard CSS length units, percentages, or the
auto keyword. It can be declared using either one or two
values:
Single value: Applying one value sets both the inline-start and inline-end edges equally.
.modal { position: absolute; inset-inline: 0; /* Sets both start and end to 0 */ }Two values: The first value defines
inset-inline-start, while the second value definesinset-inline-end..tooltip { position: absolute; inset-inline: 1rem 2rem; /* start: 1rem, end: 2rem */ }
Managing Horizontal Direction: LTR vs. RTL
In standard horizontal layouts
(writing-mode: horizontal-tb), the inline axis runs
horizontally across the screen. The mapping of inset-inline
changes automatically based on the direction property:
- Left-to-Right (
direction: ltr):inset-inline-startmaps to the physicalleft.inset-inline-endmaps to the physicalright.
- Right-to-Left (
direction: rtl):inset-inline-startflips to the physicalright.inset-inline-endflips to the physicalleft.
Using physical properties like left: 10px; forces
developers to manually override values using separate RTL stylesheets or
conditional CSS selectors like [dir="rtl"]. With
inset-inline: 10px auto;, the element sits at the beginning
of the reading line regardless of whether the language is English,
Arabic, or Hebrew, eliminating redundant code.
Behavior in Vertical Writing Modes
While commonly used for horizontal adjustments,
inset-inline strictly tracks the inline axis—the direction
in which text wraps within a single line.
If a document or container uses a vertical writing mode (such as
writing-mode: vertical-rl or
writing-mode: vertical-lr), the inline axis rotates ninety
degrees to run vertically from top to bottom. In these contexts:
inset-inline-startmaps totop.inset-inline-endmaps tobottom.
To manage the perpendicular axis (the block axis), CSS provides the
companion shorthand inset-block, which governs the stack
direction of lines.
Practical Advantages
Using inset-inline streamlines stylesheet maintenance
by:
- Simplifying Centering: Combining
inset-inline: 0;withmargin-inline: auto;creates a horizontally centered absolute element without requiring transform hacks or explicit left/right definitions. - Facilitating Internationalization (i18n): User interfaces can switch between multilingual layouts seamlessly without requiring direction-specific layout overrides.
- Reducing Code Redundancy: Two physical declarations
(
left: 0; right: 0;) are condensed into a single logical declaration (inset-inline: 0;).