CSS inline-size Property

The CSS inline-size property sets the size of an element along its logical inline axis, which depends on the element's writing mode.

In horizontal writing modes, inline-size corresponds to width. In vertical writing modes, it corresponds to height. This makes it useful for layouts that need to support different languages, writing directions, and text orientations without changing physical sizing properties.

inline-size Syntax

The inline-size property accepts length values, percentages, automatic sizing, intrinsic sizing keywords, and supported sizing functions.

Basic Syntax

selector {
  inline-size: 300px;
}

Percentage Size

.content {
  inline-size: 80%;
}

Automatic Size

.content {
  inline-size: auto;
}

Intrinsic Size

.content {
  inline-size: max-content;
}

Responsive Size

.content {
  inline-size: min(100%, 600px);
}

CSS-Wide Keywords

.content {
  inline-size: initial;
}
.content {
  inline-size: inherit;
}
.content {
  inline-size: unset;
}
.content {
  inline-size: revert;
}
.content {
  inline-size: revert-layer;
}

The initial value is auto. The property's physical equivalent depends on the element's writing mode.

Property Values

The available values provide fixed, relative, automatic, and content-based sizing along the inline axis.

Value Description
auto Determines the inline size according to the element's layout rules.
<length> Sets a size using units such as px, rem, em, or viewport units.
<percentage> Sets the inline size relative to the corresponding size of the containing block, subject to layout rules.
min-content Uses the element's minimum intrinsic inline size.
max-content Uses the element's maximum intrinsic inline size.
fit-content Uses content-based sizing constrained by the available space.
fit-content(...) Constrains intrinsic sizing using a supplied length or percentage.
stretch Sizes the element's margin box to fill the available inline space, where supported.
calc(...) Calculates an inline size using compatible CSS values.
min(...) Uses the smallest result from the supplied sizing expressions.
max(...) Uses the largest result from the supplied sizing expressions.
clamp(...) Constrains a preferred inline size between minimum and maximum values.
initial Resets the property to auto.
inherit Inherits the computed value from the parent element.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Some newer sizing keywords have limited browser support. Check compatibility before relying on them in production layouts.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Elements that accept the corresponding physical sizing property
Computed value As specified for keywords, or an absolute length or percentage as applicable
Animation type Length, percentage, or calc() interpolation when compatible
Percentages Relative to the corresponding size of the containing block
Related properties block-size, min-inline-size, max-inline-size, width, height, writing-mode

How It Works

CSS provides two ways to describe dimensions: physical dimensions and logical dimensions.

Physical properties such as width and height always refer to horizontal and vertical dimensions. Logical properties such as inline-size and block-size follow the writing mode of the element.

Horizontal Writing Mode

.box {
  writing-mode: horizontal-tb;
  inline-size: 300px;
}

In horizontal writing mode, the inline axis runs horizontally, so inline-size: 300px sets the element's logical width.

Vertical Writing Mode

.box {
  writing-mode: vertical-rl;
  inline-size: 300px;
}

In vertical writing mode, the inline axis runs vertically, so inline-size: 300px sets the element's logical height.

Important Consideration

The property follows the element's writing mode, not simply the language of its content. Changing the HTML dir attribute from ltr to rtl does not, by itself, change the inline axis from horizontal to vertical.

The Inline Axis

The inline axis is the direction in which text and other inline-level content progress within a line.

Horizontal Text

.horizontal-text {
  writing-mode: horizontal-tb;
  inline-size: 240px;
}

The inline axis is horizontal, so the element has a logical width of 240 pixels.

Vertical Text

.vertical-text {
  writing-mode: vertical-rl;
  inline-size: 240px;
}

The inline axis is vertical, so the element has a logical height of 240 pixels.

The Block Axis

The block axis runs perpendicular to the inline axis. Its corresponding sizing property is block-size.

.box {
  inline-size: 240px;
  block-size: 120px;
}

Important Consideration

Using logical dimensions allows the same CSS rules to adapt to different writing modes without rewriting physical width and height declarations.

inline-size vs. width

The inline-size and width properties can produce identical results in horizontal writing modes, but they behave differently when the writing mode changes.

Physical Width

.physical-box {
  width: 250px;
}

The horizontal dimension is 250 pixels regardless of the writing mode.

Logical Inline Size

.logical-box {
  inline-size: 250px;
}

The inline dimension is 250 pixels. It maps to the physical width or height depending on the writing mode.

Comparison

Writing Mode inline-size Maps To width Controls
horizontal-tb Width Width
vertical-rl Height Width
vertical-lr Height Width
sideways-rl Height Width
sideways-lr Height Width

Important Consideration

Avoid setting both width and inline-size on the same element unless their interaction is intentional. In horizontal writing modes, both control the same physical dimension, and the cascade determines which declaration takes precedence.

Writing Modes

The writing-mode property determines whether text flows horizontally or vertically, which also determines the physical dimension represented by inline-size.

Horizontal Writing

.horizontal {
  writing-mode: horizontal-tb;
  inline-size: 200px;
}

Vertical Right-to-Left Writing

.vertical-right {
  writing-mode: vertical-rl;
  inline-size: 200px;
}

Vertical Left-to-Right Writing

.vertical-left {
  writing-mode: vertical-lr;
  inline-size: 200px;
}

Right-to-Left Text Direction

<div dir="rtl" class="text-box">
  Right-to-left text content
</div>
.text-box {
  writing-mode: horizontal-tb;
  inline-size: 240px;
}

The dir="rtl" attribute changes the text direction, but the inline axis remains horizontal because the writing mode is horizontal-tb.

Length Values

The inline-size property accepts CSS length units, including absolute and relative units.

Pixels

.box {
  inline-size: 300px;
}

Root-Relative Units

.box {
  inline-size: 20rem;
}

Font-Relative Units

.text-box {
  inline-size: 40ch;
}

The ch unit is useful for controlling approximate text measure, although the number of characters that fit depends on the font and actual text.

Viewport-Relative Units

.box {
  inline-size: 50vw;
}

Logical Viewport Units

.box {
  inline-size: 50vi;
}

The vi unit represents a percentage of the viewport's inline dimension, based on the writing mode of the root element.

Important Consideration

Length values must include an appropriate unit unless the value is zero. A declaration such as inline-size: 300; is invalid.

Percentage Values

Percentage values size an element relative to the corresponding dimension of its containing block, subject to the applicable layout rules.

Percentage Inline Size

.child {
  inline-size: 75%;
}

Parent and Child Example

.parent {
  inline-size: 400px;
}
.child {
  inline-size: 50%;
}

In a straightforward horizontal layout, the child's content-box inline size is 200 pixels when the percentage resolves against the parent's 400-pixel content box.

Full Available Inline Size

.child {
  inline-size: 100%;
}

Important Consideration

Percentages depend on the containing block and layout context. Padding, borders, margins, and box-sizing can also affect whether the element fits within its container.

Automatic Sizing

The auto value allows the browser to determine the inline size according to the element's formatting context and layout rules.

Automatic Inline Size

.box {
  inline-size: auto;
}

Block-Level Element

.content {
  display: block;
  inline-size: auto;
}

In a typical horizontal block formatting context, a non-replaced block element with automatic width fills the available inline space after accounting for its margins, borders, and padding.

Automatic Size in Flexbox

.flex-item {
  inline-size: auto;
}

Flexbox sizing rules determine the item's size using its content, flex basis, available space, and other constraints.

Important Consideration

The auto value does not always mean the element fills its container. Its behavior depends on the element's display type and layout context.

Intrinsic Sizing

Intrinsic sizing keywords allow an element's content to influence its inline size.

min-content

.box {
  inline-size: min-content;
}

The element uses its minimum intrinsic inline size, which may cause text to wrap at available breaking opportunities.

max-content

.box {
  inline-size: max-content;
}

The element uses its maximum intrinsic inline size, generally avoiding soft wrapping opportunities.

fit-content

.box {
  inline-size: fit-content;
}

The element uses a content-based size constrained by the available inline space.

fit-content() Function

.box {
  inline-size: fit-content(300px);
}

The function limits the preferred intrinsic size using the supplied value, subject to the minimum intrinsic size. Support for this function in sizing properties should be checked separately.

Important Consideration

Intrinsic sizing does not guarantee that content will remain within the viewport. Long unbreakable content can still cause overflow.

Box Sizing

The box-sizing property determines whether a declared inline size applies to the content box or includes padding and borders.

Content-Box Sizing

.box {
  inline-size: 300px;
  padding: 20px;
  border: 2px solid #333333;
  box-sizing: content-box;
}

In horizontal writing mode, the content box is 300 pixels wide. Padding and borders increase the overall border-box width to 344 pixels.

Border-Box Sizing

.box {
  inline-size: 300px;
  padding: 20px;
  border: 2px solid #333333;
  box-sizing: border-box;
}

The declared 300-pixel inline size includes the padding and borders.

Responsive Box

.responsive-box {
  box-sizing: border-box;
  inline-size: 100%;
  padding: 20px;
}

Important Consideration

Using border-box often makes percentage-based and responsive sizing easier to manage because padding and borders are included within the declared dimension.

Minimum and Maximum Inline Size

The min-inline-size and max-inline-size properties provide logical minimum and maximum constraints.

Minimum Inline Size

.box {
  min-inline-size: 200px;
}

Maximum Inline Size

.box {
  max-inline-size: 600px;
}

Combined Constraints

.content {
  inline-size: 100%;
  min-inline-size: 200px;
  max-inline-size: 600px;
}

Flexible Container

.content {
  inline-size: 100%;
  max-inline-size: 65ch;
  box-sizing: border-box;
}

This is useful for readable text layouts because it allows the content to shrink with the available space while limiting its maximum line length.

Important Consideration

Minimum and maximum constraints can override the preferred inline size. A minimum that exceeds the available space may cause overflow.

Responsive Layouts

Logical sizing properties can help responsive layouts adapt to different writing modes while preserving the intended content dimensions.

Responsive Content Container

.content-container {
  inline-size: 100%;
  max-inline-size: 960px;
  margin-inline: auto;
  box-sizing: border-box;
}

Responsive Card

.card {
  inline-size: min(100%, 320px);
  padding: 20px;
  box-sizing: border-box;
}

Fluid Sizing with clamp()

.panel {
  inline-size: clamp(240px, 60%, 600px);
}

Responsive Image

.responsive-image {
  display: block;
  max-inline-size: 100%;
  block-size: auto;
}

Important Consideration

When using fixed minimum sizes, check smaller viewports. A responsive layout should avoid horizontal or vertical overflow unless scrolling is intentional.

Flexbox and Grid

The inline-size property can be used on flex and grid items, although their final sizes also depend on the layout algorithms.

Flexbox Item

.flex-container {
  display: flex;
  gap: 16px;
}
.flex-item {
  inline-size: 200px;
}

Flex items may grow or shrink depending on their flex properties and available space.

Prevent Flex Shrinking

.flex-item {
  inline-size: 200px;
  flex-shrink: 0;
}

Grid Item

.grid-container {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.grid-item {
  inline-size: 100%;
  box-sizing: border-box;
}

Prevent Content-Based Overflow

.grid-item {
  min-inline-size: 0;
}

Setting min-inline-size: 0 can allow flex or grid items to shrink below their automatic content-based minimum size when the inline axis is the relevant constrained dimension.

Important Consideration

In Flexbox and Grid, inline-size is a sizing input, not always the final rendered dimension. Flexing, stretching, minimum sizes, and available space can affect the result.

Inline Elements

Non-replaced inline elements, such as ordinary <span> elements, generally do not accept explicit width or height sizing in normal inline formatting.

Inline Span

<span class="label">Example Label</span>
.label {
  inline-size: 200px;
}

The declared inline size does not normally establish a 200-pixel dimension for a non-replaced inline span.

Use inline-block

.label {
  display: inline-block;
  inline-size: 200px;
}

The element now accepts explicit logical sizing while participating as an inline-level box.

Use block

.label {
  display: block;
  inline-size: 200px;
}

Important Consideration

Replaced inline elements, such as images, have different sizing behavior from ordinary text spans and can accept explicit dimensions.

Inheritance

The inline-size property is not inherited. Each element determines its own inline size unless inheritance is explicitly requested.

Parent Inline Size

.parent {
  inline-size: 400px;
}

A child does not automatically inherit the computed inline-size: 400px declaration, although its own layout may depend on the parent's available space.

Explicit Inheritance

.child {
  inline-size: inherit;
}

Reset to the Initial Value

.child {
  inline-size: initial;
}

The initial value is auto.

Reset with unset

.child {
  inline-size: unset;
}

Because the property is not inherited, unset behaves like initial.

inline-size Example

This example demonstrates how the same inline-size declaration maps to different physical dimensions in horizontal and vertical writing modes.

HTML Example

<div class="inline-size-demo">
  <div class="demo-panel">
    <h3>Horizontal Writing</h3>
    <div class="demo-box horizontal">HTML and CSS</div>
  </div>
  <div class="demo-panel">
    <h3>Vertical Writing</h3>
    <div class="demo-box vertical">HTML and CSS</div>
  </div>
</div>

CSS Example

.inline-size-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.inline-size-demo .demo-panel {
  flex: 1 1 180px;
  min-width: 0;
}
.inline-size-demo h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.inline-size-demo .demo-box {
  inline-size: 180px;
  block-size: 90px;
  box-sizing: border-box;
  padding: 12px;
  border: 2px solid #2563eb;
  background-color: #eff6ff;
}
.inline-size-demo .horizontal {
  writing-mode: horizontal-tb;
}
.inline-size-demo .vertical {
  writing-mode: vertical-rl;
}
Browser Result

Horizontal Writing

HTML and CSS

Vertical Writing

HTML and CSS

Both boxes use inline-size: 180px and block-size: 90px. The horizontal box is 180 pixels wide and 90 pixels tall. The vertical box is 90 pixels wide and 180 pixels tall.

Change to vertical-lr

.inline-size-demo .vertical {
  writing-mode: vertical-lr;
}

The inline dimension remains vertical, but the direction in which block lines progress changes.

Use a Responsive Inline Size

.inline-size-demo .demo-box {
  inline-size: min(100%, 180px);
}

This variation limits the logical inline size to the smaller of the available percentage or 180 pixels, subject to the containing block and writing mode.

Common Mistakes

Assuming inline-size Always Means Width

In horizontal writing modes, inline-size corresponds to width. In vertical writing modes, it corresponds to height.

Using a Unitless Length

.box {
  inline-size: 300;
}

This is invalid because nonzero CSS lengths require a unit.

Conflicting Physical and Logical Properties

.box {
  width: 200px;
  inline-size: 300px;
}

In horizontal writing mode, both declarations control the same physical dimension. The cascade determines the winning value.

Expecting the Property to Be Inherited

The inline-size property is not inherited. Descendants determine their own sizes according to their layout rules.

Applying It to a Non-Replaced Inline Element

An ordinary inline <span> does not normally accept explicit inline sizing. Use inline-block or another appropriate display type.

Ignoring Padding and Borders

With box-sizing: content-box, padding and borders increase the element's overall border-box size.

Using Fixed Sizes Without Responsive Constraints

A large fixed inline size can cause overflow in a narrow container. Consider max-inline-size, percentages, or sizing functions.

Confusing Direction with Writing Mode

The direction property changes inline text direction but does not independently switch the inline axis between horizontal and vertical.

Important Considerations

Keep the following points in mind when using inline-size:

  • The property sets an element's size along the logical inline axis.
  • The initial value is auto.
  • The property is not inherited.
  • In horizontal writing modes, it corresponds to width.
  • In vertical writing modes, it corresponds to height.
  • The writing-mode property determines the physical orientation of the inline axis.
  • The direction property does not independently change the inline axis from horizontal to vertical.
  • Length values require units unless the value is zero.
  • Percentage sizing depends on the containing block and layout context.
  • Intrinsic sizing keywords allow content to influence dimensions.
  • The box-sizing property determines whether padding and borders are included in the declared size.
  • Use min-inline-size and max-inline-size to constrain logical sizing.
  • Flexbox and Grid layout rules may affect the final rendered dimensions.
  • Non-replaced inline elements do not normally accept explicit inline sizing.
  • Logical sizing is useful for multilingual and writing-mode-aware layouts.
  • Test responsive layouts for overflow at narrow viewport sizes.

Browser Support

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

Basic logical sizing is broadly available. Support for newer sizing values, such as stretch and certain intrinsic sizing functions, may vary independently of support for the property itself.

For current compatibility information, visit Can I Use? and search for inline-size.

Specifications

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

CSS Logical Properties and Values Module Level 1: Dimension Properties

The specification defines logical sizing properties that adapt to writing modes rather than fixed physical dimensions.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: inline-size