CSS inset-block Property

The CSS inset-block property is a logical shorthand that sets the block-start and block-end positioning offsets of an element.

It combines inset-block-start and inset-block-end into one declaration. Unlike the physical top and bottom properties, the sides it controls depend on the element's writing mode. This makes it useful for positioning content in layouts that support horizontal and vertical writing systems.

inset-block Syntax

The inset-block property accepts one or two values. Each value may be a length, percentage, auto, or a supported positioning expression.

Basic Syntax

selector {
  inset-block: 20px;
}

Two Values

.box {
  inset-block: 10px 30px;
}

Percentage Values

.box {
  inset-block: 5% 10%;
}

Mixed Values

.box {
  inset-block: 20px auto;
}

Calculated Values

.box {
  inset-block: calc(1rem + 10px) 5%;
}

CSS-Wide Keywords

.box {
  inset-block: initial;
}
.box {
  inset-block: inherit;
}
.box {
  inset-block: unset;
}
.box {
  inset-block: revert;
}
.box {
  inset-block: revert-layer;
}

The initial value of each longhand property is auto. The physical sides represented by block-start and block-end depend on the element's writing mode.

Property Values

The inset-block shorthand sets two logical positioning offsets.

Value Description
auto Allows the applicable positioning rules to determine the offset.
<length> Sets an offset using units such as px, rem, em, or viewport units.
<percentage> Sets an offset as a percentage of the relevant containing block dimension.
calc(...) Calculates an offset using compatible CSS values.
min(...) Uses the smallest result from the supplied expressions.
max(...) Uses the largest result from the supplied expressions.
clamp(...) Constrains an offset between minimum and maximum values.
anchor(...) Uses an anchor-positioning expression where supported and permitted.
initial Resets both longhand offsets to auto.
inherit Inherits both computed offset values from the parent.
unset Resets both offsets to auto because the longhands are not inherited.
revert Reverts both offsets according to cascade origin rules.
revert-layer Reverts both offsets according to cascade layer rules.

Shorthand Assignment

Number of Values Assignment
One The same value is assigned to block-start and block-end.
Two The first value sets block-start; the second sets block-end.

Property Characteristics

Characteristic Value
Initial value auto for both longhands
Inherited No
Applies to Positioned elements
Computed value Determined separately for each longhand
Animation type Determined separately for each longhand
Percentages Relative to the corresponding containing block dimension
Longhand properties inset-block-start, inset-block-end

The shorthand does not have a separate computed value or animation type. Its behavior is determined by the two longhand properties.

How It Works

The inset-block property sets positioning offsets along the block axis. The block axis is perpendicular to the direction in which inline text progresses.

Equivalent Longhand Declarations

.box {
  inset-block: 10px 30px;
}

This is equivalent to:

.box {
  inset-block-start: 10px;
  inset-block-end: 30px;
}

Horizontal Writing Mode

.box {
  writing-mode: horizontal-tb;
  position: absolute;
  inset-block: 10px 30px;
}

In horizontal writing mode, block-start maps to the top and block-end maps to the bottom.

Vertical Writing Mode

.box {
  writing-mode: vertical-rl;
  position: absolute;
  inset-block: 10px 30px;
}

In vertical right-to-left writing mode, block-start maps to the right and block-end maps to the left.

Important Consideration

The inset-block property does not establish positioning by itself. Its offsets affect positioned elements according to their position value.

One Value

When one value is supplied, it is assigned to both block-start and block-end.

Example

.box {
  position: absolute;
  inset-block: 20px;
}

Equivalent Longhands

.box {
  inset-block-start: 20px;
  inset-block-end: 20px;
}

Equal Block Offsets

.panel {
  position: absolute;
  inset-block: 15px;
  inset-inline: 20px;
}

This applies equal offsets at both block edges and separate offsets along the inline axis.

Important Consideration

Equal offsets do not necessarily mean the element is centered. Its dimensions, margins, and positioning rules determine the final placement.

Two Values

When two values are supplied, the first sets block-start and the second sets block-end.

Example

.box {
  position: absolute;
  inset-block: 10px 30px;
}

Equivalent Longhands

.box {
  inset-block-start: 10px;
  inset-block-end: 30px;
}

Mixed Values

.badge {
  position: absolute;
  inset-block: 10px auto;
}

This establishes the block-start offset while leaving the block-end offset automatic.

Important Consideration

The first value always represents block-start, even when block-start corresponds to the right or left physical side.

The Block Axis

CSS logical properties use two axes: the inline axis and the block axis. The block axis describes the direction in which lines of text are stacked.

Horizontal Writing

.horizontal {
  writing-mode: horizontal-tb;
  inset-block: 10px 20px;
}

The block axis runs vertically from top to bottom.

Vertical Writing

.vertical {
  writing-mode: vertical-rl;
  inset-block: 10px 20px;
}

The block axis runs horizontally from right to left.

The Inline Axis

The inline axis is perpendicular to the block axis. Its corresponding positioning shorthand is inset-inline.

.box {
  position: absolute;
  inset-block: 10px 20px;
  inset-inline: 30px 40px;
}

Important Consideration

The element's writing mode determines the physical sides represented by logical inset properties. The text direction alone does not change which sides are block-start and block-end in a given writing mode.

Writing Modes

The writing-mode property determines how logical block offsets map to physical sides.

Writing Mode Block-Start Block-End
horizontal-tb Top Bottom
vertical-rl Right Left
vertical-lr Left Right
sideways-rl Right Left
sideways-lr Left Right

Horizontal Writing Example

.box {
  writing-mode: horizontal-tb;
  position: absolute;
  inset-block: 10px 20px;
}

Vertical Right-to-Left Example

.box {
  writing-mode: vertical-rl;
  position: absolute;
  inset-block: 10px 20px;
}

Vertical Left-to-Right Example

.box {
  writing-mode: vertical-lr;
  position: absolute;
  inset-block: 10px 20px;
}

Important Consideration

Changing direction from ltr to rtl does not reverse the block-start and block-end sides. It primarily affects the inline direction.

Physical vs. Logical Offsets

Physical offsets always refer to fixed physical sides. Logical offsets follow the writing mode.

Physical Offsets

.box {
  position: absolute;
  top: 10px;
  bottom: 20px;
}

The offsets always refer to the top and bottom edges.

Logical Offsets

.box {
  position: absolute;
  inset-block: 10px 20px;
}

The offsets refer to block-start and block-end, which may map to top and bottom or right and left.

Comparison

Property Purpose
top Sets the physical top offset.
bottom Sets the physical bottom offset.
inset-block-start Sets the logical block-start offset.
inset-block-end Sets the logical block-end offset.
inset-block Sets both logical block offsets.

Important Consideration

A physical offset and a logical offset can target the same side. If conflicting declarations apply, the cascade determines which value wins.

Positioning Modes

The effect of inset-block depends on the element's positioning mode.

Position Value How inset-block Behaves
static Offsets have no positioning effect.
relative Offsets visually shift the element along the block axis while preserving its original layout space.
absolute Offsets position the element relative to its absolute-positioning containing block.
fixed Offsets position the element relative to its fixed-positioning containing block.
sticky Offsets establish sticky positioning thresholds along the block axis.

Important Consideration

Absolute and fixed positioning remove elements from normal flow. Relative and sticky positioning preserve their normal layout space.

Absolute Positioning

Absolutely positioned elements use logical offsets to establish their position relative to a containing block.

Position Near Block-Start

.container {
  position: relative;
}
.badge {
  position: absolute;
  inset-block: 10px auto;
  inset-inline-end: 10px;
}

The badge is positioned 10 pixels from the logical block-start edge and 10 pixels from the inline-end edge.

Stretch Along the Block Axis

.container {
  position: relative;
}
.panel {
  position: absolute;
  inset-block: 20px;
  inset-inline: 10px;
}

With automatic dimensions and no conflicting constraints, the panel can stretch between the specified block offsets.

Important Consideration

The containing block is commonly established by a positioned ancestor, but other properties can also establish containing blocks for absolutely positioned descendants.

Fixed Positioning

Fixed positioning allows an element to remain at a specified logical offset relative to its fixed-positioning containing block, usually the viewport.

Fixed Notification

.notification {
  position: fixed;
  inset-block: auto 20px;
  inset-inline-end: 20px;
}

In horizontal writing mode, the notification is positioned near the bottom and inline-end edges of the viewport.

Fixed Header

.fixed-header {
  position: fixed;
  inset-block: 0 auto;
  inset-inline: 0;
  block-size: 70px;
}

Important Consideration

Certain ancestor properties, including transforms, can establish a containing block for fixed-positioned descendants. Fixed positioning is therefore not always relative to the viewport.

Relative Positioning

Relatively positioned elements can be visually shifted along the block axis without leaving normal document flow.

Move Toward Block-End

.box {
  position: relative;
  inset-block: 15px auto;
}

In horizontal writing mode, this moves the element downward by 15 pixels.

Move Toward Block-Start

.box {
  position: relative;
  inset-block: auto 15px;
}

In horizontal writing mode, this moves the element upward by 15 pixels.

Opposing Offsets

.box {
  position: relative;
  inset-block: 10px 20px;
}

When both opposing offsets are specified for a relatively positioned element, CSS resolves the over-constrained axis rather than applying both shifts independently.

Important Consideration

Relative positioning preserves the element's original layout space. Nearby content is laid out as though the element had not been visually shifted.

Sticky Positioning

Sticky positioning uses logical offsets as thresholds that constrain an element while scrolling.

Sticky Section Heading

.section-heading {
  position: sticky;
  inset-block-start: 0;
}

Sticky Element with Shorthand

.sticky-panel {
  position: sticky;
  inset-block: 20px auto;
}

The element uses a 20-pixel threshold at the logical block-start edge in the relevant scrolling context.

Important Consideration

Sticky positioning depends on the scroll container, available space, and containing block. A non-auto offset is needed on the relevant axis for sticky positioning to take effect on that axis.

Percentage Values

Percentage values are resolved against the relevant containing block dimension, based on the physical side to which the logical offset maps.

Percentage Block Offsets

.box {
  position: absolute;
  inset-block: 10% 20%;
}

Horizontal Writing Mode

.box {
  writing-mode: horizontal-tb;
  position: absolute;
  inset-block: 10% 20%;
}

The offsets map to top and bottom, so their percentages use the containing block's height.

Vertical Writing Mode

.box {
  writing-mode: vertical-rl;
  position: absolute;
  inset-block: 10% 20%;
}

The offsets map to right and left, so their percentages use the containing block's width.

Important Consideration

Percentage positioning depends on the containing block and applicable positioning rules. The final result may also be affected by dimensions, margins, and other constraints.

Negative Values

Negative length and percentage offsets are allowed. They can position an element beyond the corresponding logical edge of its containing block.

Negative Block-Start Offset

.badge {
  position: absolute;
  inset-block: -10px auto;
}

Negative Block-End Offset

.badge {
  position: absolute;
  inset-block: auto -15px;
}

Decorative Element

.decoration {
  position: absolute;
  inset-block: -20px auto;
  inset-inline-end: -20px;
}

Important Consideration

Negative offsets can cause content to extend outside its container or viewport. Check overflow, clipping, and visibility when using them.

inset-block and Element Sizing

For absolutely or fixed-positioned elements, opposing logical block offsets can influence the used size along the block axis when the corresponding dimension is automatic.

Stretch Along the Block Axis

.panel {
  position: absolute;
  inset-block: 20px;
  inset-inline: 10px;
}

With automatic dimensions and no conflicting constraints, the element can stretch between the specified offsets.

Explicit Block Size

.panel {
  position: absolute;
  inset-block: 20px;
  block-size: 100px;
}

The element has an explicit logical block size. If the offsets and dimensions over-constrain the layout, CSS positioning rules determine how the constraints are resolved.

Responsive Block Size

.panel {
  position: absolute;
  inset-block: 20px;
  max-block-size: 400px;
  overflow: auto;
}

Important Consideration

The final size depends on the element's offsets, dimensions, margins, padding, borders, intrinsic size, and containing block.

CSS provides logical positioning and sizing properties that adapt to writing modes and text directions.

Logical Block Offsets

.box {
  inset-block-start: 10px;
  inset-block-end: 20px;
}

Logical Inline Offsets

.box {
  inset-inline: 10px 20px;
}

Logical Dimensions

.box {
  inline-size: 300px;
  block-size: 150px;
}

Logical Margins

.box {
  margin-block: 20px;
  margin-inline: auto;
}

Comparison

Property Purpose
inset-block Sets logical block-start and block-end positioning offsets.
inset-inline Sets logical inline-start and inline-end positioning offsets.
block-size Sets the size along the logical block axis.
inline-size Sets the size along the logical inline axis.
margin-block Sets logical block-start and block-end margins.

Important Consideration

Logical properties are especially useful for multilingual layouts, but they can also improve consistency in ordinary horizontal writing modes.

Inheritance

The inset-block shorthand is not inherited. Both longhand properties have an initial value of auto.

Parent Offsets

.parent {
  position: relative;
  inset-block: 10px 20px;
}

A child does not automatically inherit these offset values.

Explicit Inheritance

.child {
  position: relative;
  inset-block: inherit;
}

Reset to Initial Values

.child {
  inset-block: initial;
}

Both longhand offsets are reset to auto.

Reset with unset

.child {
  inset-block: unset;
}

Because the longhands are not inherited, unset behaves like initial.

inset-block Example

This example compares how the same logical block offsets map to physical sides in horizontal and vertical writing modes.

HTML Example

<div class="inset-block-demo">
  <div class="demo-panel">
    <h3>Horizontal Writing</h3>
    <div class="demo-container horizontal">
      <div class="demo-box">inset-block: 15px 30px</div>
    </div>
  </div>
  <div class="demo-panel">
    <h3>Vertical Writing</h3>
    <div class="demo-container vertical">
      <div class="demo-box">inset-block: 15px 30px</div>
    </div>
  </div>
</div>

CSS Example

.inset-block-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.inset-block-demo .demo-panel {
  flex: 1 1 220px;
  min-width: 0;
}
.inset-block-demo h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.inset-block-demo .demo-container {
  position: relative;
  height: 180px;
  border: 2px solid #2563eb;
  background-color: #eff6ff;
}
.inset-block-demo .demo-box {
  position: absolute;
  inset-block: 15px 30px;
  inset-inline: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 2px dashed #1d4ed8;
  background-color: #bfdbfe;
  color: #1e3a8a;
  font-weight: bold;
  font-size: 0.875rem;
  text-align: center;
  box-sizing: border-box;
}
.inset-block-demo .horizontal {
  writing-mode: horizontal-tb;
}
.inset-block-demo .vertical {
  writing-mode: vertical-rl;
}
Browser Result

Horizontal Writing

inset-block: 15px 30px

Vertical Writing

inset-block: 15px 30px

In horizontal writing mode, the first value sets the top offset and the second sets the bottom offset. In vertical right-to-left writing mode, the first value sets the right offset and the second sets the left offset.

Try Equal Block Offsets

.inset-block-demo .demo-box {
  inset-block: 20px;
}

This applies 20 pixels at both logical block edges.

Try vertical-lr

.inset-block-demo .vertical {
  writing-mode: vertical-lr;
}

The first offset now maps to the left edge, while the second maps to the right edge.

Common Mistakes

Forgetting to Set position

.box {
  inset-block: 20px;
}

The offsets have no positioning effect when the element is statically positioned.

Using More Than Two Values

.box {
  inset-block: 10px 20px 30px;
}

This is invalid. The shorthand accepts only one or two values.

Using Commas Between Values

.box {
  inset-block: 10px, 20px;
}

Values must be separated by spaces.

Assuming Block-Start Always Means Top

Block-start maps to the top in horizontal writing mode, but it maps to the right or left in vertical writing modes.

Confusing inset-block with margin-block

The inset-block property sets positioning offsets. The margin-block property sets logical outer spacing.

Mixing Conflicting Physical and Logical Offsets

.box {
  top: 10px;
  inset-block-start: 20px;
}

In horizontal writing mode, both declarations target the top offset. The cascade determines which value applies.

Expecting Both Relative Offsets to Apply Independently

When opposing relative-positioning offsets are specified, CSS resolves the over-constrained axis instead of applying both shifts independently.

Ignoring Containing Block Dimensions

Percentage offsets depend on the relevant containing block dimensions, which may differ between horizontal and vertical writing modes.

Important Considerations

Keep the following points in mind when using inset-block:

  • The property is shorthand for inset-block-start and inset-block-end.
  • It accepts one or two space-separated values.
  • One value applies to both logical block edges.
  • Two values set block-start and block-end independently.
  • The initial value of each longhand is auto.
  • The property is not inherited.
  • The physical sides depend on the element's writing mode.
  • In horizontal-tb, block-start is top and block-end is bottom.
  • In vertical-rl, block-start is right and block-end is left.
  • In vertical-lr, block-start is left and block-end is right.
  • The position property determines how the offsets are interpreted.
  • Offsets have no positioning effect on statically positioned elements.
  • Absolute and fixed positioning remove elements from normal document flow.
  • Relative positioning preserves the element's original layout space.
  • Sticky positioning uses offsets as scrolling thresholds.
  • Negative length and percentage offsets are allowed.
  • Percentage offsets depend on the corresponding containing block dimension.
  • Opposing offsets can influence the used dimensions of absolutely positioned elements.
  • Use inset-inline to control the logical inline axis.
  • Test positioned content for overlap, clipping, and overflow.

Browser Support

The CSS inset-block property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

Basic length, percentage, and auto offsets are broadly available. Newer positioning features, such as anchor positioning, may have separate browser compatibility requirements.

For current compatibility information, visit Can I Use? and search for inset-block.

Specifications

The inset-block property is defined in the CSS Logical Properties and Values Module Level 1 specification.

CSS Logical Properties and Values Module Level 1: Inset Properties

The specification defines logical positioning properties and their relationship to writing modes and physical offsets.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: inset-block