inset-block
is a shorthand logical CSS property that sets the length that an element is offset in the block direction combining inset-block-start
and inset-block-end
. It’s sort of like declaring top
and bottom
except its starting and ending points are determined by the element’s direction
, text-orientation
and writing-mode
, just like other logical properties.
The property is part of the CSS Logical Properties and Values Level 1 specification which is currently in Editor’s Draft status. That means the definition and information about it can change between now and official recommendation.
.element {
inset-block: 50px 15%;
position: relative; /* Apples to positioned elements */
writing-mode: vertical-rl; /* Determines the block start direction */
}
So, for example, if the writing mode is set to horizontal-lr
the inset-block
property will act just like setting top
and bottom
and set the element’s offset from the bottom edge. You even need to specify an explicit position
on the same element for it to take effect, just like physical offset properties.
But change the element’s writing-mode
to something like vertical-lr
and the “bottom” edge is rotated in the vertical direction, acting more like the left
and right
properties.
Syntax
inset-block: <'top'> <'bottom'>;
- Initial value:
auto
- Applies to: positioned elements
- Inherited: no
- Percentages: as for the corresponding physical property
- Computed value: same as corresponding
top
andbottom
properties - Animation type: by computed value type
Values
inset-block
takes a length value and supports global keywords. Its default value is auto
.
/* Length values */
inset-block: 50px;
inset-block: 4em;
inset-block: 3.5rem
inset-block: 25vh;
/* Percentage values */
inset-block: 50%;
/* Keyword values */
inset-block: auto; /* initial value */
/* Global values */
inset-block: initial
inset-block: inherit;
inset-block: unset;
Browser support
IE | Edge | Firefox | Chrome | Safari | Opera |
---|---|---|---|---|---|
No | No | 63+ | No | No | No |
Android Chrome | Android Firefox | Android Browser | iOS Safari | Opera Mini |
---|---|---|---|---|
No | 79+ | No | No | No |
Demo
Further reading
- CSS Logical Properties and Values Level 1 specification (Editor’s Draft)
- MDN Documentation
- Understanding Logical Properties And Values (Smashing Magazine)
- CSS Logical Properties (Adrian Roselli)
- Bidirectional horizontal rules in CSS (Hussein Al Hammad)