CSS contain-intrinsic-width Property
The contain-intrinsic-width property specifies a fallback intrinsic width for an element when size containment prevents its contents from contributing to its intrinsic width.
This property helps the browser determine an appropriate width for size-contained elements without relying on their descendants. It can be useful for content-sized components and elements whose contents may be skipped by content-visibility.
Unlike contain-intrinsic-inline-size, which follows the writing mode, contain-intrinsic-width always refers to the physical width dimension.
contain-intrinsic-width Syntax
The property accepts none, a nonnegative length, or the auto keyword followed by a length or none.
selector {
contain-intrinsic-width: 300px;
}
General Syntax
selector {
contain-intrinsic-width: auto? [ none | <length> ];
}
Length Value
.component {
contain-intrinsic-width: 300px;
}
Remembered Width with Fallback
.component {
contain-intrinsic-width: auto 300px;
}
Remembered Width Without Fallback
.component {
contain-intrinsic-width: auto none;
}
No Specified Fallback
.component {
contain-intrinsic-width: none;
}
CSS-Wide Keywords
.component {
contain-intrinsic-width: inherit;
}
.component {
contain-intrinsic-width: initial;
}
.component {
contain-intrinsic-width: unset;
}
.component {
contain-intrinsic-width: revert;
}
.component {
contain-intrinsic-width: revert-layer;
}
The standalone auto keyword is invalid. It must be followed by a valid length or none.
Property Values
| Value | Description |
|---|---|
none |
Provides no specified fallback intrinsic width. This is the initial value. |
300px |
Provides a 300-pixel fallback intrinsic width when applicable size containment is active. |
20rem |
Provides a fallback width based on the root font size. |
15em |
Provides a fallback width based on the element's font size. |
0 |
Specifies a zero-length intrinsic width fallback. |
auto 300px |
Uses a remembered intrinsic width when available, otherwise 300 pixels. |
auto none |
Uses a remembered intrinsic width when available, otherwise no specified fallback. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | No |
| Applies to | Elements for which size containment can apply |
| Computed value | Specified keyword and computed length, when present |
| Animation type | By computed value type |
| Percentages | Not accepted |
| Negative lengths | Not accepted |
| Dimension | Physical width |
The property does not directly assign an element's used width. It supplies an intrinsic width fallback when containment makes the content's intrinsic width unavailable.
How It Works
Normally, an element's contents can contribute to its intrinsic width. Size containment prevents that contribution, allowing the browser to treat the element as independently sized.
Step 1: Create a Component
<div class="component">
<p>CSS Reference Example</p>
</div>
Step 2: Apply Size Containment
.component {
contain: size;
}
Step 3: Provide a Fallback Width
.component {
contain: size;
contain-intrinsic-width: 300px;
}
The browser can use 300 pixels as the intrinsic width contribution when size containment applies.
Step 4: Use a Content-Sized Display
.component {
display: inline-block;
contain: size;
contain-intrinsic-width: 300px;
}
The fallback can influence the width of an inline-block whose width would otherwise depend on intrinsic sizing.
Step 5: Remove Containment
.component {
display: inline-block;
contain: none;
contain-intrinsic-width: 300px;
}
Without applicable size containment, the element uses normal content-based intrinsic sizing.
Important Distinction
The fallback is not a minimum width, maximum width, or fixed width. Other layout rules can still affect the final used dimensions.
Length Values
The property accepts nonnegative CSS lengths, including absolute and relative units.
Pixels
.component {
contain-intrinsic-width: 300px;
}
Root-Relative Units
.component {
contain-intrinsic-width: 20rem;
}
Font-Relative Units
.component {
contain-intrinsic-width: 18em;
}
Viewport Units
.component {
contain-intrinsic-width: 30vw;
}
Calculated Lengths
.component {
contain-intrinsic-width: calc(200px + 5rem);
}
Using clamp()
.component {
contain-intrinsic-width: clamp(200px, 30vw, 500px);
}
Using Custom Properties
.component {
--fallback-width: 300px;
contain-intrinsic-width: var(--fallback-width);
}
Invalid Values
.component {
contain-intrinsic-width: -100px;
}
.component {
contain-intrinsic-width: 50%;
}
Negative lengths and percentages are not valid values for this property.
The auto Keyword
The auto keyword allows the browser to reuse a remembered intrinsic width when one is available.
Remembered Width with Fallback
.component {
contain-intrinsic-width: auto 300px;
}
If a remembered intrinsic width is available, the browser can use it. Otherwise, the 300-pixel fallback applies.
Remembered Width Without Fallback
.component {
contain-intrinsic-width: auto none;
}
This uses a remembered intrinsic width when available but provides no fallback length otherwise.
When Width Is Remembered
Browsers can remember an element's intrinsic width when it has been rendered without size containment. That remembered value can be reused if containment later applies.
When No Width Is Remembered
If the browser has not established a remembered intrinsic width, it uses the supplied fallback length or none.
Content Changes
Changes to text, fonts, images, or other content can change the actual intrinsic width. A previously remembered value may not immediately reflect those changes.
Invalid Standalone auto
.component {
contain-intrinsic-width: auto;
}
The standalone auto keyword is invalid.
Practical Consideration
Use auto with a realistic fallback length when an element may alternate between normal rendering and size-contained rendering.
The none Value
The none value indicates that no fallback intrinsic width is specified.
.component {
contain-intrinsic-width: none;
}
Initial Value
The initial value of contain-intrinsic-width is none.
With Size Containment
.component {
contain: size;
contain-intrinsic-width: none;
}
Size containment prevents the contents from contributing to intrinsic sizing, and no substitute intrinsic width is supplied.
Difference from Zero
.component {
contain-intrinsic-width: 0;
}
The value 0 explicitly specifies a zero-length fallback, while none indicates that no fallback intrinsic width is provided.
With auto
.component {
contain-intrinsic-width: auto none;
}
This allows a remembered width to be used when available, without supplying a fallback length.
Working with Size Containment
The contain-intrinsic-width property affects intrinsic width calculations when containment isolates the corresponding physical dimension.
Full Size Containment
.component {
contain: size;
contain-intrinsic-width: 300px;
}
Full size containment isolates both physical dimensions, allowing the width fallback to apply.
Strict Containment
.component {
contain: strict;
contain-intrinsic-width: 300px;
}
The strict keyword includes size, layout, paint, and style containment.
Inline-Size Containment in Horizontal Writing
.component {
writing-mode: horizontal-tb;
contain: inline-size;
contain-intrinsic-width: 300px;
}
In horizontal writing mode, the inline dimension corresponds to physical width, so the fallback can apply.
Inline-Size Containment in Vertical Writing
.component {
writing-mode: vertical-rl;
contain: inline-size;
contain-intrinsic-width: 300px;
}
In vertical writing mode, inline-size containment affects physical height rather than width. The width fallback therefore does not apply through inline-size containment alone.
Layout Containment Alone
.component {
contain: layout;
contain-intrinsic-width: 300px;
}
Layout containment alone does not activate the intrinsic width fallback.
Content Containment
.component {
contain: content;
contain-intrinsic-width: 300px;
}
The content keyword does not include size containment, so it does not activate the width fallback by itself.
Working with content-visibility
The content-visibility property allows browsers to skip rendering work for content that does not currently need to be displayed.
Basic Example
.preview-card {
content-visibility: auto;
contain-intrinsic-width: 300px;
}
Remembered Width
.preview-card {
content-visibility: auto;
contain-intrinsic-width: auto 300px;
}
When Rendering Is Skipped
When the browser skips rendering an element's contents, size containment applies. The fallback intrinsic width can contribute to sizing calculations.
When Content Is Rendered
When the element's contents are rendered normally, their intrinsic width can be determined from the actual content.
Content-Sized Cards
.preview-card {
display: inline-block;
content-visibility: auto;
contain-intrinsic-width: auto 280px;
}
The fallback is particularly useful when a component's width depends on its contents.
Full-Width Sections
For ordinary block elements that automatically fill their available width, an intrinsic width fallback may not visibly affect layout. A block-size or height fallback may be more useful for reserving vertical space.
Writing Modes
The contain-intrinsic-width property always refers to physical width, regardless of writing mode.
Horizontal Writing
.component {
writing-mode: horizontal-tb;
contain: size;
contain-intrinsic-width: 300px;
}
Vertical Right-to-Left Writing
.component {
writing-mode: vertical-rl;
contain: size;
contain-intrinsic-width: 300px;
}
Vertical Left-to-Right Writing
.component {
writing-mode: vertical-lr;
contain: size;
contain-intrinsic-width: 300px;
}
Physical and Logical Dimensions
| Writing Mode | Physical Width Corresponds To |
|---|---|
horizontal-tb |
Inline dimension |
vertical-rl |
Block dimension |
vertical-lr |
Block dimension |
Logical Alternative
.component {
contain-intrinsic-inline-size: 300px;
}
Use contain-intrinsic-inline-size when the fallback should follow the logical inline dimension instead of physical width.
contain-intrinsic-width vs. width
The two properties serve different purposes.
width
.component {
width: 300px;
}
The width property specifies the element's width according to normal CSS sizing rules.
contain-intrinsic-width
.component {
contain: size;
contain-intrinsic-width: 300px;
}
This supplies a fallback intrinsic width rather than directly setting the element's used width.
Comparison
| Property | Purpose |
|---|---|
width |
Specifies the physical width of an element. |
contain-intrinsic-width |
Provides a fallback intrinsic width when applicable size containment is active. |
min-width |
Specifies a minimum width constraint. |
max-width |
Specifies a maximum width constraint. |
Combined Example
.component {
display: inline-block;
contain: size;
contain-intrinsic-width: 300px;
max-width: 100%;
}
The fallback contributes to intrinsic sizing, while max-width can constrain the element's final used width.
Related Intrinsic Size Properties
CSS provides physical and logical intrinsic size fallback properties.
| Property | Purpose |
|---|---|
contain-intrinsic-width |
Provides a fallback intrinsic physical width. |
contain-intrinsic-height |
Provides a fallback intrinsic physical height. |
contain-intrinsic-inline-size |
Provides a fallback intrinsic logical inline size. |
contain-intrinsic-block-size |
Provides a fallback intrinsic logical block size. |
contain-intrinsic-size |
Shorthand for logical inline and block fallback sizes. |
Physical Width and Height
.component {
contain-intrinsic-width: 400px;
contain-intrinsic-height: 250px;
}
Logical Inline and Block Sizes
.component {
contain-intrinsic-inline-size: 400px;
contain-intrinsic-block-size: 250px;
}
Logical Shorthand
.component {
contain-intrinsic-size: 400px 250px;
}
In horizontal writing mode, the logical shorthand corresponds to a 400-pixel inline width and a 250-pixel block height. In vertical writing mode, those logical dimensions map differently.
Responsive Layouts
Fallback intrinsic widths can be adjusted for different viewport and container sizes.
Desktop
.preview-card {
contain-intrinsic-width: auto 400px;
}
Tablet
@media (max-width: 900px) {
.preview-card {
contain-intrinsic-width: auto 320px;
}
}
Mobile
@media (max-width: 600px) {
.preview-card {
contain-intrinsic-width: auto 240px;
}
}
Using clamp()
.preview-card {
contain-intrinsic-width: auto clamp(200px, 30vw, 450px);
}
Using Custom Properties
.preview-card {
--fallback-width: 350px;
contain-intrinsic-width: auto var(--fallback-width);
}
@media (max-width: 600px) {
.preview-card {
--fallback-width: 240px;
}
}
Responsive fallback values should approximate the component's expected intrinsic width at each layout size.
Practical Uses
The property is most useful when a size-contained component depends on intrinsic width calculations.
Preview Cards
.preview-card {
display: inline-block;
content-visibility: auto;
contain-intrinsic-width: auto 300px;
}
Contained Panels
.contained-panel {
display: inline-block;
contain: size;
contain-intrinsic-width: 400px;
contain-intrinsic-height: 250px;
}
Reference Examples
.reference-example {
display: inline-block;
contain: inline-size;
contain-intrinsic-width: 320px;
}
Reusable Components
.component {
--intrinsic-width: 280px;
display: inline-block;
contain: size;
contain-intrinsic-width: var(--intrinsic-width);
}
When Not to Use
The property is generally unnecessary when the element is not subject to applicable size containment or its width is determined independently of intrinsic sizing.
contain-intrinsic-width Example
This example compares two size-contained inline-block elements. The first provides no fallback intrinsic width, while the second supplies a 240-pixel fallback.
<div class="intrinsic-width-demo">
<div class="demo-item">
<h3>Without a Fallback</h3>
<div class="demo-box no-fallback">
<p>CSS Reference</p>
</div>
</div>
<div class="demo-item">
<h3>With a 240px Fallback</h3>
<div class="demo-box with-fallback">
<p>CSS Reference</p>
</div>
</div>
</div>
.intrinsic-width-demo {
display: grid;
gap: 20px;
}
.intrinsic-width-demo .demo-item {
padding: 15px;
border: 1px solid #cccccc;
background-color: #f8f9fa;
}
.intrinsic-width-demo h3 {
margin: 0 0 12px;
font-size: 1.125rem;
}
.intrinsic-width-demo .demo-box {
display: inline-block;
contain: size;
box-sizing: border-box;
max-width: 100%;
padding: 15px;
border: 2px solid #336699;
background-color: #ffffff;
}
.intrinsic-width-demo .demo-box p {
margin: 0;
}
.intrinsic-width-demo .no-fallback {
contain-intrinsic-width: none;
}
.intrinsic-width-demo .with-fallback {
contain-intrinsic-width: 240px;
}
Without a Fallback
CSS Reference
With a 240px Fallback
CSS Reference
Both boxes use contain: size, which prevents their contents from contributing to intrinsic sizing.
The first box has no fallback intrinsic width, so its width is determined by the remaining sizing rules, including padding and borders.
The second box supplies a 240-pixel intrinsic width contribution. Padding and borders are accounted for separately according to the box model and the available sizing constraints.
The example illustrates that contain-intrinsic-width supplies an intrinsic sizing fallback rather than directly setting a fixed width.
Accessibility
Fallback intrinsic widths can influence the space available for content, so realistic estimates and responsive sizing are important.
Support Text Resizing
Test enlarged text and browser zoom. Text may require more width or additional lines than the original estimate.
Avoid Horizontal Overflow
Use appropriate sizing constraints and test narrow viewports to prevent unnecessarily wide components.
Preserve Content Visibility
Ensure containment-related sizing and clipping do not obscure important content.
Maintain Reading Order
The property does not change HTML source order or semantic structure.
Test Interactive Content
When combined with content-visibility, verify that interactive content remains usable as skipped elements become rendered.
Important Considerations
Keep the following points in mind when using contain-intrinsic-width:
- Purpose: Provides a fallback intrinsic physical width during applicable size containment.
- Initial value:
none. - Inheritance: The property is not inherited.
- Physical dimension: Always refers to width, regardless of writing mode.
- Length values: Accepts nonnegative CSS lengths.
- Percentages: Not accepted.
- Negative lengths: Not accepted.
- auto: Must be followed by a length or
none. - Remembered widths: Can replace the fallback when available.
- none: Provides no specified fallback intrinsic width.
- Size containment: Must affect the physical width dimension for the fallback to apply.
- Full size containment: Isolates intrinsic sizing in both dimensions.
- Inline-size containment: Affects physical width in horizontal writing modes.
- content-visibility: Can activate size containment while rendering is skipped.
- Used width: The property does not directly assign a fixed width.
- Box model: Padding and borders still affect final dimensions.
- Responsive layouts: Fallback widths can be adjusted with media queries and CSS math functions.
- Accessibility: Test zoom, text resizing, overflow, and interactive content.
Use contain-intrinsic-width when a size-contained element needs a predictable intrinsic width contribution. For normal block elements that fill the available width, the property may have no visible effect.
Browser Support
The contain-intrinsic-width property is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.
Support for remembered-size behavior using the auto syntax may vary in older browser versions.
Basic Example
.component {
contain: size;
contain-intrinsic-width: 300px;
}
Feature Detection
@supports (contain-intrinsic-width: auto 300px) {
.component {
contain-intrinsic-width: auto 300px;
}
}
Feature queries determine whether a browser accepts the specified syntax, but do not guarantee identical remembered-size behavior.
For current compatibility information, visit Can I Use? and search for contain-intrinsic-width.
Specifications
The contain-intrinsic-width property is defined in CSS Containment Module Level 3.
CSS Containment Module Level 3
The specification defines physical and logical intrinsic size fallback properties, their accepted values, and remembered-size behavior.
