CSS contain-intrinsic-size Property
The contain-intrinsic-size property is a shorthand that specifies fallback intrinsic sizes for an element's logical inline and block dimensions when size containment applies.
It sets the contain-intrinsic-inline-size and contain-intrinsic-block-size properties together. These fallback dimensions allow browsers to estimate an element's intrinsic size without measuring its descendants during applicable containment.
The property is particularly useful with content-visibility: auto, where fallback sizes can reserve space while rendering is skipped. The auto keyword also allows browsers to reuse previously remembered intrinsic sizes when available.
contain-intrinsic-size Syntax
The contain-intrinsic-size shorthand accepts one or two intrinsic size values. Each value can be none, a nonnegative length, or auto followed by none or a nonnegative length.
selector {
contain-intrinsic-size: 300px 200px;
}
General Syntax
selector {
contain-intrinsic-size: [ auto? [ none | <length> ] ]{1,2};
}
One Length
.component {
contain-intrinsic-size: 300px;
}
The same 300-pixel fallback applies to both logical dimensions.
Two Lengths
.component {
contain-intrinsic-size: 300px 200px;
}
The first value sets the inline-size fallback, and the second sets the block-size fallback.
Remembered Sizes
.component {
contain-intrinsic-size: auto 300px auto 200px;
}
Mixed Values
.component {
contain-intrinsic-size: 300px auto 200px;
}
No Fallback
.component {
contain-intrinsic-size: none;
}
CSS-Wide Keywords
.component {
contain-intrinsic-size: inherit;
}
.component {
contain-intrinsic-size: initial;
}
.component {
contain-intrinsic-size: unset;
}
.component {
contain-intrinsic-size: revert;
}
.component {
contain-intrinsic-size: revert-layer;
}
CSS-wide keywords must appear alone. The auto keyword cannot be used without a following length or none.
Property Values
The shorthand supports the following common value combinations:
| Value | Description |
|---|---|
none |
Provides no specified fallback intrinsic size in either logical dimension. This is the initial value. |
300px |
Uses 300 pixels as the fallback intrinsic inline size and block size. |
300px 200px |
Uses 300 pixels for the inline dimension and 200 pixels for the block dimension. |
20rem 15rem |
Uses relative lengths for the two logical dimensions. |
0 |
Specifies zero-length fallbacks for both dimensions. |
300px none |
Provides a 300-pixel inline-size fallback and no block-size fallback. |
none 200px |
Provides no inline-size fallback and a 200-pixel block-size fallback. |
auto 300px |
Uses remembered intrinsic sizes when available, otherwise 300 pixels for both dimensions. |
auto 300px auto 200px |
Uses remembered sizes when available, with separate inline and block fallback lengths. |
auto none |
Uses remembered sizes when available, otherwise no specified fallback in either dimension. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the parent's computed values for both longhand properties. |
initial |
Resets both longhand properties to none. |
unset |
Resets both longhand properties to none because they are not inherited. |
revert |
Reverts both longhand properties according to cascade origin rules. |
revert-layer |
Reverts both longhand properties according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Property type | Shorthand |
| Initial value | none for both longhands |
| Inherited | No |
| Applies to | Elements for which size containment can apply |
| Longhand properties | contain-intrinsic-inline-size and contain-intrinsic-block-size |
| Computed value | As specified for the individual longhand properties |
| Animation type | As defined for the individual longhand properties |
| Percentages | Not accepted |
| Negative lengths | Not accepted |
| Dimensions | Logical inline and block sizes |
The shorthand does not directly set an element's used width or height. It supplies intrinsic sizing fallbacks when the corresponding dimensions are subject to containment.
How It Works
Size containment prevents an element's descendants from contributing to its intrinsic dimensions. The contain-intrinsic-size property provides substitute intrinsic dimensions when the relevant containment applies.
Step 1: Create a Component
<div class="component">
<h3>CSS Reference</h3>
<p>Explore CSS properties and examples.</p>
</div>
Step 2: Apply Size Containment
.component {
contain: size;
}
The element's descendants no longer contribute to its intrinsic inline or block size.
Step 3: Provide Fallback Dimensions
.component {
contain: size;
contain-intrinsic-size: 300px 200px;
}
The browser can use 300 pixels as the intrinsic inline-size contribution and 200 pixels as the intrinsic block-size contribution.
Step 4: Use Intrinsic Sizing
.component {
display: inline-block;
contain: size;
contain-intrinsic-size: 300px 200px;
}
An inline-block can use intrinsic sizing to determine its inline dimension, while the block-size fallback contributes to its automatic block size.
Step 5: Compare Normal Sizing
.component {
display: inline-block;
contain: none;
contain-intrinsic-size: 300px 200px;
}
Without relevant size containment, the fallback dimensions do not replace the normal intrinsic sizes determined by the contents.
Important Distinction
The shorthand supplies intrinsic sizing contributions. It does not enforce fixed dimensions or override the normal box model, available space, or other sizing constraints.
Shorthand Behavior
The contain-intrinsic-size shorthand sets two logical longhand properties:
contain-intrinsic-inline-sizecontain-intrinsic-block-size
Equivalent Longhand Declarations
.component {
contain-intrinsic-inline-size: 300px;
contain-intrinsic-block-size: 200px;
}
Equivalent Shorthand
.component {
contain-intrinsic-size: 300px 200px;
}
One Value Sets Both Dimensions
.component {
contain-intrinsic-size: 300px;
}
This is equivalent to setting both longhands to 300px.
Resetting an Existing Longhand
.component {
contain-intrinsic-inline-size: 400px;
contain-intrinsic-block-size: 200px;
contain-intrinsic-size: 300px;
}
The final shorthand declaration sets both logical dimensions to 300 pixels, replacing the earlier longhand values.
Overriding One Dimension
.component {
contain-intrinsic-size: 300px 200px;
contain-intrinsic-block-size: 250px;
}
The inline-size fallback remains 300 pixels, while the block-size fallback becomes 250 pixels.
Resetting Both Dimensions
.component {
contain-intrinsic-size: none;
}
Both longhand properties are set to none.
Practical Consideration
Use the shorthand when both logical dimensions need fallback values. Use the individual longhands when only one dimension needs to change.
One-Value Syntax
When one intrinsic size value is supplied, it applies to both the inline and block dimensions.
Single Length
.component {
contain-intrinsic-size: 300px;
}
Both longhands receive a 300-pixel fallback.
Single Relative Length
.component {
contain-intrinsic-size: 20rem;
}
Single Zero Value
.component {
contain-intrinsic-size: 0;
}
Single none Value
.component {
contain-intrinsic-size: none;
}
Single Remembered-Size Value
.component {
contain-intrinsic-size: auto 300px;
}
Both dimensions can use remembered intrinsic sizes when available, otherwise the 300-pixel fallback.
When to Use
Use one value when the same fallback is appropriate for both logical dimensions or when both dimensions should use the same remembered-size fallback.
Two-Value Syntax
When two intrinsic size values are supplied, the first applies to the inline dimension and the second applies to the block dimension.
Different Lengths
.component {
contain-intrinsic-size: 400px 250px;
}
Inline Size Only
.component {
contain-intrinsic-size: 400px none;
}
Block Size Only
.component {
contain-intrinsic-size: none 250px;
}
Remembered Inline Size
.component {
contain-intrinsic-size: auto 400px 250px;
}
The inline dimension uses a remembered size when available, otherwise 400 pixels. The block dimension uses a 250-pixel fallback.
Remembered Block Size
.component {
contain-intrinsic-size: 400px auto 250px;
}
Remembered Sizes in Both Dimensions
.component {
contain-intrinsic-size: auto 400px auto 250px;
}
Separate Fallbacks
Two-value syntax is useful when a component is expected to be wider than it is tall, or when its inline and block dimensions require different estimates.
Practical Consideration
Remember that the values follow logical inline and block dimensions, not necessarily physical width and height.
The auto Keyword
The auto keyword allows a browser to use a remembered intrinsic size instead of the supplied fallback when a remembered value is available.
Both Dimensions
.component {
contain-intrinsic-size: auto 300px auto 200px;
}
One Value for Both Dimensions
.component {
contain-intrinsic-size: auto 300px;
}
Inline Dimension Only
.component {
contain-intrinsic-size: auto 300px 200px;
}
Block Dimension Only
.component {
contain-intrinsic-size: 300px auto 200px;
}
Remembered Size with No Fallback
.component {
contain-intrinsic-size: auto none;
}
Invalid Standalone auto
.component {
contain-intrinsic-size: auto;
}
The standalone auto keyword is invalid because it must be followed by none or a nonnegative length.
When to Use
Use remembered-size syntax when an element may alternate between normal rendering and size-contained rendering, allowing the browser to reuse previously measured intrinsic dimensions.
Remembered Intrinsic Sizes
The remembered-size feature allows the browser to retain intrinsic dimensions determined during normal rendering and reuse them when size containment later applies.
Initial Fallback
.article-section {
content-visibility: auto;
contain-intrinsic-size: auto 600px auto 400px;
}
Before remembered dimensions are available, the browser can use 600 pixels for the inline dimension and 400 pixels for the block dimension while rendering is skipped.
Normal Rendering
When the browser renders the element without size containment, its contents can determine the element's actual intrinsic dimensions.
Remembering the Dimensions
The browser may retain the intrinsic inline and block sizes for subsequent use.
Reusing Remembered Dimensions
When size containment applies again, remembered dimensions can replace the original fallback estimates.
Independent Dimensions
The inline and block dimensions can have separate remembered values. Each dimension uses its own fallback when a remembered value is unavailable.
Content Changes
Changes to text, images, fonts, or other content can affect the actual intrinsic dimensions. Remembered values may not immediately reflect those changes.
Browser Management
Remembered intrinsic sizes are managed by the browser. Authors cannot assume that remembered values will always be available.
Practical Consideration
Provide realistic fallback dimensions even when using auto, especially for elements that have not yet been rendered.
none Value
The none value specifies that no fallback intrinsic size is provided for the corresponding logical dimension.
Both Dimensions
.component {
contain-intrinsic-size: none;
}
Both longhand properties are set to none.
Inline Dimension Only
.component {
contain-intrinsic-size: none 200px;
}
No inline-size fallback is provided, while the block-size fallback is 200 pixels.
Block Dimension Only
.component {
contain-intrinsic-size: 300px none;
}
The inline-size fallback is 300 pixels, while no block-size fallback is provided.
Difference from Zero
.component {
contain-intrinsic-size: 0;
}
The value 0 explicitly provides zero-length fallbacks, while none provides no specified fallback intrinsic size.
Remembered Sizes with none
.component {
contain-intrinsic-size: auto none;
}
The browser may use remembered intrinsic dimensions when available, but no fallback lengths are provided otherwise.
When to Use
Use none when no fallback is required or when other sizing constraints determine the element's dimensions.
Length Values
Each dimension accepts nonnegative CSS lengths, including absolute and relative units.
Pixels
.component {
contain-intrinsic-size: 400px 250px;
}
rem Units
.component {
contain-intrinsic-size: 25rem 15rem;
}
em Units
.component {
contain-intrinsic-size: 20em 12em;
}
Viewport Units
.component {
contain-intrinsic-size: 40vw 30vh;
}
Logical Viewport Units
.component {
contain-intrinsic-size: 40vi 30vb;
}
Zero Values
.component {
contain-intrinsic-size: 0 0;
}
Invalid Negative Lengths
.component {
contain-intrinsic-size: -100px 200px;
}
Negative lengths are invalid.
Invalid Percentages
.component {
contain-intrinsic-size: 50% 30%;
}
Percentage values are not accepted.
Practical Consideration
Choose fallback lengths based on the expected intrinsic dimensions of the element. For content that changes with viewport width, responsive estimates may be more appropriate than fixed values.
Writing Modes and Logical Dimensions
The contain-intrinsic-size shorthand uses logical inline and block dimensions. These dimensions depend on the element's writing mode.
Horizontal Writing Mode
.component {
writing-mode: horizontal-tb;
contain: size;
contain-intrinsic-size: 400px 250px;
}
In horizontal writing mode, the inline dimension corresponds to width and the block dimension corresponds to height.
Vertical Right-to-Left Writing
.component {
writing-mode: vertical-rl;
contain: size;
contain-intrinsic-size: 400px 250px;
}
In vertical writing mode, the inline dimension corresponds to height and the block dimension corresponds to width.
Vertical Left-to-Right Writing
.component {
writing-mode: vertical-lr;
contain: size;
contain-intrinsic-size: 400px 250px;
}
Dimension Mapping
| Writing Mode | First Value | Second Value |
|---|---|---|
horizontal-tb |
Inline size (width) | Block size (height) |
vertical-rl |
Inline size (height) | Block size (width) |
vertical-lr |
Inline size (height) | Block size (width) |
Physical Alternatives
.component {
contain-intrinsic-width: 400px;
contain-intrinsic-height: 250px;
}
The physical properties always refer to width and height, regardless of writing mode.
Practical Consideration
Use the logical shorthand when fallback dimensions should adapt automatically to horizontal or vertical writing modes.
Working with Size Containment
The shorthand provides fallback intrinsic dimensions when size containment prevents descendants from contributing to the relevant intrinsic sizes.
Full Size Containment
.component {
contain: size;
contain-intrinsic-size: 400px 250px;
}
Full size containment affects both the inline and block dimensions.
Strict Containment
.component {
contain: strict;
contain-intrinsic-size: 400px 250px;
}
The strict keyword includes size, layout, paint, and style containment.
Inline-Size Containment
.component {
contain: inline-size;
contain-intrinsic-size: 400px 250px;
}
Inline-size containment isolates intrinsic sizing only in the inline dimension. The inline fallback can apply, while the block dimension continues to use normal content-based sizing.
Size and Layout Containment
.component {
contain: size layout;
contain-intrinsic-size: 400px 250px;
}
Size and Paint Containment
.component {
contain: size paint;
contain-intrinsic-size: 400px 250px;
}
Layout Containment Alone
.component {
contain: layout;
contain-intrinsic-size: 400px 250px;
}
Layout containment alone does not prevent descendants from contributing to intrinsic sizing.
Content Containment
.component {
contain: content;
contain-intrinsic-size: 400px 250px;
}
The content keyword does not include size containment, so the intrinsic fallback dimensions do not replace normal intrinsic sizing.
Practical Consideration
Determine which logical dimensions are subject to containment before selecting fallback values. Not every containment mode isolates both dimensions.
Working with content-visibility
The content-visibility property allows browsers to skip rendering work for suitable content. The contain-intrinsic-size shorthand can reserve estimated intrinsic dimensions while rendering is skipped.
Basic Example
.article-section {
content-visibility: auto;
contain-intrinsic-size: 600px 400px;
}
Remembered Sizes
.article-section {
content-visibility: auto;
contain-intrinsic-size: auto 600px auto 400px;
}
Skipped Rendering
When the browser skips rendering the element's contents, size containment applies. The fallback intrinsic dimensions can then contribute to the element's sizing.
Rendered Content
When the contents are rendered normally, their actual intrinsic dimensions can determine the element's size.
Full-Width Sections
.documentation-section {
content-visibility: auto;
contain-intrinsic-size: auto none auto 500px;
}
For a normal block element that fills its available inline space, a block-size fallback is often more important than an inline-size fallback.
Content-Sized Components
.preview-card {
display: inline-block;
content-visibility: auto;
contain-intrinsic-size: auto 300px auto 220px;
}
Content-sized components may benefit from fallback dimensions in both directions.
Practical Consideration
Use auto with realistic fallback dimensions when the browser may skip and later render the same content.
Intrinsic Fallbacks vs. Explicit Sizes
The contain-intrinsic-size property supplies fallback intrinsic dimensions. It does not directly specify the element's used inline or block size.
Explicit Logical Dimensions
.component {
inline-size: 400px;
block-size: 250px;
}
These declarations specify logical dimensions according to normal CSS sizing rules.
Intrinsic Fallback Dimensions
.component {
contain: size;
contain-intrinsic-size: 400px 250px;
}
These declarations provide substitute intrinsic dimensions while size containment applies.
Key Differences
| Property | Purpose |
|---|---|
contain-intrinsic-size |
Supplies fallback intrinsic dimensions during applicable size containment. |
inline-size |
Specifies the logical inline dimension. |
block-size |
Specifies the logical block dimension. |
min-inline-size |
Establishes a minimum logical inline size. |
min-block-size |
Establishes a minimum logical block size. |
Combined Example
.component {
display: inline-block;
min-inline-size: 200px;
min-block-size: 150px;
contain: size;
contain-intrinsic-size: 400px 250px;
}
The intrinsic fallback dimensions contribute to sizing, while the minimum dimensions remain separate constraints.
Box Model Considerations
Padding, borders, and the box-sizing property can affect the final outer dimensions of the element.
Practical Consideration
Use explicit dimensions when an element requires specified sizes. Use intrinsic fallbacks when a contained element needs substitute content-based dimensions.
Layout Stability
Fallback intrinsic dimensions can help reduce layout movement when previously skipped content becomes rendered.
Without Fallback Dimensions
.article-section {
content-visibility: auto;
}
When rendering is skipped, the browser may not have enough information to reserve space comparable to the element's eventual rendered dimensions.
With Fallback Dimensions
.article-section {
content-visibility: auto;
contain-intrinsic-size: 600px 400px;
}
With Remembered Dimensions
.article-section {
content-visibility: auto;
contain-intrinsic-size: auto 600px auto 400px;
}
Choosing Estimates
Choose fallback values based on the expected intrinsic dimensions of the element rather than arbitrary measurements.
Different Component Types
.summary-card {
contain-intrinsic-size: auto 280px auto 180px;
}
.reference-card {
contain-intrinsic-size: auto 360px auto 300px;
}
.example-panel {
contain-intrinsic-size: auto 500px auto 350px;
}
Overestimated Dimensions
Oversized fallbacks can reserve unnecessary space while content is skipped.
Underestimated Dimensions
Undersized fallbacks can cause components to expand when their contents become rendered.
Practical Consideration
Test realistic content, different viewport widths, and browser zoom levels. Accurate estimates can improve layout stability but do not guarantee that layout shifts will be eliminated.
Related Intrinsic Size Properties
The shorthand sets the logical inline-size and block-size fallback properties. CSS also provides physical alternatives for width and height.
| Property | Purpose |
|---|---|
contain-intrinsic-size |
Shorthand for logical inline-size and block-size fallbacks. |
contain-intrinsic-inline-size |
Provides a fallback intrinsic logical inline size. |
contain-intrinsic-block-size |
Provides a fallback intrinsic logical block size. |
contain-intrinsic-width |
Provides a fallback intrinsic physical width. |
contain-intrinsic-height |
Provides a fallback intrinsic physical height. |
Logical Shorthand
.component {
contain-intrinsic-size: 400px 250px;
}
Logical Longhands
.component {
contain-intrinsic-inline-size: 400px;
contain-intrinsic-block-size: 250px;
}
Physical Longhands
.component {
contain-intrinsic-width: 400px;
contain-intrinsic-height: 250px;
}
Remembered Sizes
.component {
contain-intrinsic-size: auto 400px auto 250px;
}
Practical Consideration
Use logical properties when dimensions should adapt to writing modes. Use physical properties when the fallback must refer specifically to width or height.
Calculated Values and Variables
The shorthand accepts CSS math functions and custom properties when they produce valid nonnegative lengths.
Using calc()
.component {
contain-intrinsic-size: calc(200px + 5rem) calc(150px + 3rem);
}
Using clamp()
.component {
contain-intrinsic-size: clamp(250px, 40vw, 600px) clamp(200px, 30vh, 450px);
}
Using min()
.component {
contain-intrinsic-size: min(500px, 60vw) min(350px, 40vh);
}
Using max()
.component {
contain-intrinsic-size: max(250px, 25vw) max(200px, 20vh);
}
Using Custom Properties
:root {
--fallback-inline: 400px;
--fallback-block: 250px;
}
.component {
contain-intrinsic-size: var(--fallback-inline) var(--fallback-block);
}
Custom Properties with auto
.component {
--fallback-inline: 400px;
--fallback-block: 250px;
contain-intrinsic-size: auto var(--fallback-inline) auto var(--fallback-block);
}
Component Variants
.component {
--fallback-inline: 300px;
--fallback-block: 200px;
contain-intrinsic-size: auto var(--fallback-inline) auto var(--fallback-block);
}
.component.large {
--fallback-inline: 500px;
--fallback-block: 350px;
}
Practical Consideration
CSS math functions and custom properties help keep fallback dimensions consistent while allowing different components to use appropriate estimates.
Responsive Layouts
Fallback intrinsic dimensions can change with viewport or container size to better approximate the element's rendered dimensions.
Desktop Layout
.preview-card {
content-visibility: auto;
contain-intrinsic-size: auto 400px auto 250px;
}
Tablet Layout
@media (max-width: 900px) {
.preview-card {
contain-intrinsic-size: auto 320px auto 300px;
}
}
Mobile Layout
@media (max-width: 600px) {
.preview-card {
contain-intrinsic-size: auto 260px auto 400px;
}
}
Narrower layouts may require a smaller inline-size estimate and a larger block-size estimate because text wraps onto additional lines.
Using clamp()
.preview-card {
contain-intrinsic-size: auto clamp(200px, 35vw, 500px) auto clamp(200px, 30vh, 450px);
}
Container Queries
.card-wrapper {
container-type: inline-size;
}
.preview-card {
contain-intrinsic-size: auto 400px auto 250px;
}
@container (max-width: 500px) {
.preview-card {
contain-intrinsic-size: auto 260px auto 350px;
}
}
Custom Property Approach
.preview-card {
--fallback-inline: 400px;
--fallback-block: 250px;
contain-intrinsic-size: auto var(--fallback-inline) auto var(--fallback-block);
}
@media (max-width: 600px) {
.preview-card {
--fallback-inline: 260px;
--fallback-block: 400px;
}
}
Practical Consideration
Adjust fallback estimates when a component's expected dimensions change meaningfully between layouts. The shorthand does not replace normal responsive sizing constraints.
Practical Uses
The contain-intrinsic-size property is useful for components that need estimated intrinsic dimensions during size containment or skipped rendering.
Documentation Sections
.documentation-section {
content-visibility: auto;
contain-intrinsic-size: auto none auto 500px;
}
Preview Cards
.preview-card {
display: inline-block;
content-visibility: auto;
contain-intrinsic-size: auto 300px auto 220px;
}
Code Example Panels
.code-example {
content-visibility: auto;
contain-intrinsic-size: auto 500px auto 300px;
}
Contained Components
.contained-component {
display: inline-block;
contain: size;
contain-intrinsic-size: 350px 200px;
}
Reference Cards
.reference-card {
display: inline-block;
content-visibility: auto;
contain-intrinsic-size: auto 320px auto 280px;
}
Reusable Component Sizes
.component {
--fallback-inline: 300px;
--fallback-block: 200px;
contain-intrinsic-size: auto var(--fallback-inline) auto var(--fallback-block);
}
When Not to Use
The property is generally unnecessary when relevant size containment is not active or the element's dimensions are already determined independently of intrinsic sizing.
Practical Consideration
Use the shorthand when both logical dimensions need fallback values. For normal full-width document sections, a block-size fallback alone may be sufficient.
contain-intrinsic-size Example
The following example compares two size-contained inline-block elements. The first has no intrinsic size fallback, while the second provides a 240-pixel inline-size fallback and a 140-pixel block-size fallback.
Both elements use contain: size, preventing their descendants from contributing to intrinsic sizing in either dimension.
<div class="intrinsic-size-demo">
<div class="intrinsic-example">
<h3>Without Fallback Dimensions</h3>
<div class="intrinsic-box no-fallback">
<p>CSS Reference</p>
</div>
</div>
<div class="intrinsic-example">
<h3>With 240px by 140px Fallback</h3>
<div class="intrinsic-box with-fallback">
<p>CSS Reference</p>
</div>
</div>
</div>
.intrinsic-size-demo {
display: grid;
gap: 20px;
}
.intrinsic-size-demo .intrinsic-example {
padding: 15px;
border: 1px solid #cccccc;
background-color: #f8f9fa;
}
.intrinsic-size-demo h3 {
margin: 0 0 12px;
font-size: 1.125rem;
}
.intrinsic-size-demo .intrinsic-box {
display: inline-block;
contain: size;
box-sizing: border-box;
max-width: 100%;
padding: 15px;
border: 2px solid #336699;
background-color: #ffffff;
}
.intrinsic-size-demo .intrinsic-box p {
margin: 0;
}
.intrinsic-size-demo .no-fallback {
contain-intrinsic-size: none;
}
.intrinsic-size-demo .with-fallback {
contain-intrinsic-size: 240px 140px;
}
Without Fallback Dimensions
CSS Reference
With 240px by 140px Fallback
CSS Reference
The first element has no specified fallback intrinsic dimensions. Because contain: size prevents its contents from contributing to intrinsic sizing, its dimensions are determined by the remaining sizing rules, including padding and borders.
The second element uses contain-intrinsic-size: 240px 140px, providing a 240-pixel intrinsic inline-size contribution and a 140-pixel intrinsic block-size contribution. Padding and borders are added according to the box model, subject to other sizing constraints.
This demonstrates that contain-intrinsic-size provides substitute intrinsic dimensions rather than directly assigning fixed width and height values.
Accessibility
Fallback intrinsic dimensions can affect the space reserved for content, so realistic estimates and responsive sizing are important for accessible layouts.
Avoid Content Overlap
Choose fallback dimensions that provide sufficient space for the expected content when containment applies.
Support Text Resizing
Test enlarged text and increased browser zoom. Content may require larger dimensions than the original estimates.
Prevent Horizontal Overflow
Check narrow viewports and apply appropriate sizing constraints so fallback inline dimensions do not cause unnecessary horizontal scrolling.
Reduce Layout Movement
Realistic fallback dimensions can reduce unexpected movement when skipped content becomes rendered.
Preserve Reading Order
The property does not change the HTML source order or semantic document structure.
Test Keyboard Navigation
When combined with content-visibility, verify that interactive content remains accessible as previously skipped elements become rendered.
Practical Consideration
Test realistic content, different font sizes, writing modes, and viewport widths to ensure fallback sizing does not interfere with readability or interaction.
Important Considerations
Keep the following points in mind when using contain-intrinsic-size:
- Purpose: Provides fallback intrinsic dimensions when relevant size containment applies.
- Property type: Shorthand for two logical intrinsic size fallback properties.
- Longhands: Sets
contain-intrinsic-inline-sizeandcontain-intrinsic-block-size. - Initial value:
nonefor both longhands. - Inheritance: The longhand properties are not inherited.
- One value: Applies the same fallback to both logical dimensions.
- Two values: The first specifies inline size and the second specifies block size.
- Logical dimensions: Inline and block directions follow the element's writing mode.
- Horizontal writing: Inline corresponds to width and block corresponds to height.
- Vertical writing: Inline corresponds to height and block corresponds to width.
- Length values: Accepts nonnegative CSS lengths.
- Percentages: Not accepted.
- Negative values: Not accepted.
- none: Provides no specified fallback intrinsic size for the corresponding dimension.
- auto: Must be followed by a length or
none. - Remembered sizes: Can replace supplied fallback lengths when available.
- Independent dimensions: Each dimension can use its own remembered size and fallback.
- Full size containment: Isolates intrinsic sizing in both dimensions.
- Inline-size containment: Isolates intrinsic sizing only in the inline dimension.
- Strict containment: Includes full size containment.
- Layout containment: Does not activate intrinsic size fallbacks by itself.
- Content containment: Does not include size containment.
- content-visibility: Can activate size containment while rendering is skipped.
- Used dimensions: The shorthand supplies intrinsic sizing contributions rather than fixed width and height values.
- Box model: Padding and borders remain part of the final element dimensions.
- Calculated values: CSS math functions can supply valid nonnegative lengths.
- Custom properties: Can store reusable fallback dimensions.
- Responsive layouts: Fallback estimates can change with media queries or container queries.
- Layout stability: Accurate estimates can reduce movement when skipped content becomes rendered.
- Accessibility: Test text resizing, overflow, keyboard navigation, and responsive behavior.
Use contain-intrinsic-size when a size-contained element needs fallback intrinsic dimensions in both logical directions. For elements that do not rely on intrinsic sizing or are not subject to relevant size containment, the shorthand may have no visible effect.
Browser Support
The contain-intrinsic-size property is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.
Support for remembered-size behavior using the auto syntax and related containment features may vary in older browser versions.
Basic Example
.component {
contain: size;
contain-intrinsic-size: 400px 250px;
}
With content-visibility
.component {
content-visibility: auto;
contain-intrinsic-size: auto 400px auto 250px;
}
Feature Detection
@supports (contain-intrinsic-size: auto 400px auto 250px) {
.component {
content-visibility: auto;
contain-intrinsic-size: auto 400px auto 250px;
}
}
Feature queries determine whether a browser accepts the specified syntax. They do not guarantee identical remembered-size behavior across browsers.
For current compatibility information, visit Can I Use? and search for contain-intrinsic-size.
Specifications
The contain-intrinsic-size property is defined in CSS Containment Module Level 3.
CSS Containment Module Level 3
The specification defines the shorthand, its logical longhand properties, fallback intrinsic dimensions, and remembered-size behavior associated with the auto keyword.
