CSS contain-intrinsic-block-size Property
The contain-intrinsic-block-size property specifies a fallback intrinsic block size for an element when size containment prevents its contents from contributing to that dimension.
The block dimension follows the element's writing mode. In horizontal writing modes, it generally corresponds to height. In vertical writing modes, it generally corresponds to width.
This property is particularly useful with content-visibility: auto, where a fallback size can reserve space while the browser skips rendering an element's contents.
contain-intrinsic-block-size Syntax
The contain-intrinsic-block-size property accepts a nonnegative length, none, or an auto keyword followed by a fallback value.
selector {
contain-intrinsic-block-size: 300px;
}
General Syntax
selector {
contain-intrinsic-block-size: auto? [ none | <length> ];
}
Length Value
.component {
contain-intrinsic-block-size: 300px;
}
Relative Length
.component {
contain-intrinsic-block-size: 20rem;
}
Automatic Remembered Size
.component {
contain-intrinsic-block-size: auto 300px;
}
Automatic with No Fallback Size
.component {
contain-intrinsic-block-size: auto none;
}
No Intrinsic Size Fallback
.component {
contain-intrinsic-block-size: none;
}
Zero Length
.component {
contain-intrinsic-block-size: 0;
}
CSS-Wide Keywords
.component {
contain-intrinsic-block-size: inherit;
}
.component {
contain-intrinsic-block-size: initial;
}
.component {
contain-intrinsic-block-size: unset;
}
.component {
contain-intrinsic-block-size: revert;
}
.component {
contain-intrinsic-block-size: revert-layer;
}
The auto keyword cannot be used alone. It must be followed by none or a valid nonnegative length.
Property Values
The property supports the following values:
| Value | Description |
|---|---|
none |
Provides no specified fallback intrinsic block size. This is the initial value. |
300px |
Uses 300 pixels as the fallback intrinsic block size when applicable. |
20rem |
Uses a fallback block size relative to the root font size. |
15em |
Uses a fallback block size relative to the element's font size. |
0 |
Specifies a fallback intrinsic block size of zero. |
auto 300px |
Uses a remembered intrinsic block size when available, otherwise 300 pixels. |
auto none |
Uses a remembered intrinsic block size when available, otherwise no specified fallback intrinsic size. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the computed value of the parent element. |
initial |
Resets the property to none. |
unset |
Resets the property to none because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
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 |
| Layout effect | Provides an intrinsic block-size fallback when relevant size containment is active |
The property does not directly assign an element's used height or width. It supplies an intrinsic size used by sizing calculations under the applicable containment conditions.
How It Works
Size containment prevents descendant content from contributing to an element's intrinsic dimensions. The contain-intrinsic-block-size property supplies a substitute intrinsic size in the block dimension.
Step 1: Create a Component
<section class="component">
<h3>CSS Reference</h3>
<p>Explore CSS properties and examples.</p>
</section>
Step 2: Apply Size Containment
.component {
contain: size;
}
The element's contents no longer contribute to its intrinsic size in either dimension.
Step 3: Provide a Fallback Block Size
.component {
contain: size;
contain-intrinsic-block-size: 250px;
}
The browser uses 250 pixels as the intrinsic block-size contribution when the fallback is applicable.
Step 4: Establish the Inline Size
.component {
width: 100%;
contain: size;
contain-intrinsic-block-size: 250px;
}
The specified width establishes the physical inline dimension in a horizontal writing mode, while the intrinsic block-size fallback helps determine the component's block dimension.
Step 5: Allow Normal Content Sizing
.component {
contain: none;
contain-intrinsic-block-size: 250px;
}
Without relevant size containment, the fallback does not replace normal content-based sizing.
Important Distinction
The property supplies a sizing fallback rather than enforcing a fixed dimension. Explicit dimensions, minimum and maximum sizes, and other layout constraints still participate in determining the final used size.
Length Values
The property accepts nonnegative CSS length values, including absolute and relative units.
Pixels
.component {
contain-intrinsic-block-size: 300px;
}
rem Units
.component {
contain-intrinsic-block-size: 20rem;
}
em Units
.component {
contain-intrinsic-block-size: 18em;
}
Viewport Units
.component {
contain-intrinsic-block-size: 30vh;
}
Logical Viewport Units
.component {
contain-intrinsic-block-size: 30vb;
}
Zero Length
.component {
contain-intrinsic-block-size: 0;
}
Invalid Negative Length
.component {
contain-intrinsic-block-size: -100px;
}
Negative lengths are invalid.
Invalid Percentage
.component {
contain-intrinsic-block-size: 50%;
}
Percentage values are not accepted by this property.
Practical Consideration
Choose a fallback length that reasonably approximates the component's expected block size. An inaccurate fallback may cause noticeable layout movement when actual content dimensions become available.
The auto Keyword
The auto keyword enables the use of a remembered intrinsic block size when one is available.
Valid Syntax
.component {
contain-intrinsic-block-size: auto 300px;
}
Remembered Size
When the browser has a remembered intrinsic block size for the element, that size can be used instead of the supplied fallback.
No Remembered Size
When no remembered size is available, the browser uses the length specified after auto.
Automatic with none
.component {
contain-intrinsic-block-size: auto none;
}
This uses a remembered size when available and otherwise provides no specified fallback intrinsic block size.
Invalid Standalone auto
.component {
contain-intrinsic-block-size: auto;
}
The standalone auto keyword is invalid. A fallback length or none must follow it.
When to Use
Use the auto form when a component's actual dimensions may become known after rendering and a remembered size would be more accurate than a fixed estimate.
auto with a Length
The combination auto <length> provides both remembered-size behavior and a fallback estimate.
Basic Example
.article-section {
contain-intrinsic-block-size: auto 400px;
}
With content-visibility
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 400px;
}
Initial Estimate
Before the browser has a remembered intrinsic block size, it can use the 400-pixel estimate while the element is being skipped.
After Rendering
Once the element has been rendered without size containment, the browser may remember its intrinsic block size.
Subsequent Skipped Rendering
When the browser skips the element again, it can use the remembered size rather than the original estimate.
Different Fallback Estimates
.short-section {
contain-intrinsic-block-size: auto 200px;
}
.long-section {
contain-intrinsic-block-size: auto 600px;
}
When to Use
This form is particularly useful for long pages containing repeated sections with different expected content sizes.
none Value
The none value specifies that no fallback intrinsic block size is provided.
.component {
contain-intrinsic-block-size: none;
}
Initial Value
The initial value of contain-intrinsic-block-size is none.
With Size Containment
.component {
contain: size;
contain-intrinsic-block-size: none;
}
With no intrinsic block-size fallback, an auto-sized component may have no content-based intrinsic block-size contribution.
Difference from Zero
.component {
contain-intrinsic-block-size: 0;
}
The value 0 explicitly supplies a zero-length fallback, while none indicates that no fallback intrinsic size is specified.
With auto
.component {
contain-intrinsic-block-size: auto none;
}
The browser may use a remembered intrinsic block size, but no fallback length is provided when a remembered size is unavailable.
When to Use
Use none when no fallback is required or when another sizing mechanism establishes the element's dimensions.
Writing Modes and Block Size
The contain-intrinsic-block-size property uses a logical dimension rather than a fixed physical dimension.
Horizontal Writing Mode
.component {
writing-mode: horizontal-tb;
contain: size;
contain-intrinsic-block-size: 250px;
}
In horizontal writing mode, the block dimension generally corresponds to physical height.
Vertical Writing Mode
.component {
writing-mode: vertical-rl;
contain: size;
contain-intrinsic-block-size: 250px;
}
In vertical writing mode, the block dimension generally corresponds to physical width.
Another Vertical Writing Mode
.component {
writing-mode: vertical-lr;
contain: size;
contain-intrinsic-block-size: 250px;
}
Block vs. Inline Dimensions
| Writing Mode | Block Dimension | Inline Dimension |
|---|---|---|
horizontal-tb |
Height | Width |
vertical-rl |
Width | Height |
vertical-lr |
Width | Height |
Logical Property Advantage
Logical sizing properties adapt to writing modes without requiring separate physical width and height declarations.
Practical Consideration
Use contain-intrinsic-block-size when the intended fallback should follow the block dimension of the element's writing mode.
Working with Size Containment
The property is designed to provide an intrinsic block-size fallback when size containment prevents normal content-based intrinsic sizing.
Full Size Containment
.component {
contain: size;
contain-intrinsic-block-size: 300px;
}
Strict Containment
.component {
contain: strict;
contain-intrinsic-block-size: 300px;
}
The strict keyword includes size, layout, paint, and style containment.
Size and Layout Containment
.component {
contain: size layout;
contain-intrinsic-block-size: 300px;
}
Size and Paint Containment
.component {
contain: size paint;
contain-intrinsic-block-size: 300px;
}
Inline-Size Containment
.component {
contain: inline-size;
contain-intrinsic-block-size: 300px;
}
Inline-size containment affects only the inline dimension. It does not activate the block-size fallback because descendants can still contribute to the block dimension.
Layout Containment Alone
.component {
contain: layout;
contain-intrinsic-block-size: 300px;
}
Layout containment alone does not suppress intrinsic block sizing, so the fallback does not replace normal content-based sizing.
Content Containment
.component {
contain: content;
contain-intrinsic-block-size: 300px;
}
The content keyword does not include size containment. The fallback therefore does not override normal intrinsic block sizing.
Practical Consideration
Use this property with a containment mode that actually applies size containment to the block dimension.
Working with content-visibility
The content-visibility property allows browsers to skip rendering work for suitable content. A fallback intrinsic block size helps reserve space while rendering is skipped.
Basic Example
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: 400px;
}
Remembered Size Example
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 400px;
}
Skipped Rendering
When the browser skips rendering an element's contents, size containment applies. The intrinsic block-size fallback can then contribute to the element's layout size.
Visible Content
When the browser renders the element's contents normally, the content can determine the element's block size.
Long Pages
.documentation-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 500px;
}
Repeated Sections
.reference-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 350px;
}
Why the Fallback Matters
Without a suitable fallback, skipped sections may reserve too little space. This can cause noticeable layout movement when their actual contents are rendered.
Practical Consideration
Use realistic fallback estimates and test the page while scrolling to ensure the transition between skipped and rendered content remains stable.
Remembered Intrinsic Sizes
The auto form allows the browser to reuse a remembered intrinsic block size instead of relying permanently on a fixed estimate.
Initial Fallback
.component {
content-visibility: auto;
contain-intrinsic-block-size: auto 300px;
}
When the browser has no remembered size, the fallback length is available for sizing calculations.
Actual Content Rendering
When the element is rendered without size containment, its actual intrinsic block size can become available to the browser.
Remembering the Size
The browser may retain that intrinsic size for later use when the element becomes size-contained again.
Using the Remembered Size
When the remembered size is available, it takes precedence over the specified fallback length.
Content Changes
If the content changes, the remembered size may no longer match the element's current intrinsic dimensions until the browser updates it.
Browser Control
Remembered sizes are managed by the browser. Authors should not assume that a remembered size will always be available.
Practical Consideration
Always provide a reasonable fallback length with auto when preserving approximate layout space is important before the browser has measured the content.
Layout Stability
Providing a realistic intrinsic block-size fallback can reduce layout movement when previously skipped content becomes rendered.
Without a Fallback
.article-section {
content-visibility: auto;
}
When rendering is skipped, the browser may have insufficient size information to reserve space comparable to the eventual rendered content.
With a Fallback
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: 400px;
}
With Remembered Sizing
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 400px;
}
Choosing an Estimate
Use an estimate based on the typical rendered block size of the component rather than an arbitrary large value.
Different Content Types
.summary-section {
contain-intrinsic-block-size: auto 200px;
}
.reference-section {
contain-intrinsic-block-size: auto 500px;
}
.example-section {
contain-intrinsic-block-size: auto 350px;
}
Avoid Overestimation
An excessively large fallback can create unnecessary blank space while content is skipped.
Avoid Underestimation
An excessively small fallback can cause the page to expand noticeably when the content becomes rendered.
Practical Consideration
Test with realistic content, different viewport sizes, and browser zoom levels. Fallback sizing can improve stability but does not guarantee the elimination of layout shifts.
Related Intrinsic Size Properties
CSS provides logical and physical intrinsic size fallback properties, along with a shorthand that sets both logical dimensions.
| Property | Purpose |
|---|---|
contain-intrinsic-block-size |
Provides an intrinsic size fallback in the logical block dimension. |
contain-intrinsic-inline-size |
Provides an intrinsic size fallback in the logical inline dimension. |
contain-intrinsic-width |
Provides an intrinsic size fallback in the physical width dimension. |
contain-intrinsic-height |
Provides an intrinsic size fallback in the physical height dimension. |
contain-intrinsic-size |
Shorthand for the logical inline-size and block-size fallback properties. |
Logical Block Size
.component {
contain-intrinsic-block-size: 300px;
}
Logical Inline Size
.component {
contain-intrinsic-inline-size: 400px;
}
Physical Height
.component {
contain-intrinsic-height: 300px;
}
Physical Width
.component {
contain-intrinsic-width: 400px;
}
Shorthand
.component {
contain-intrinsic-size: 400px 300px;
}
The first shorthand value specifies the logical inline-size fallback, and the second specifies the logical block-size fallback.
Shorthand with Remembered Sizes
.component {
contain-intrinsic-size: auto 400px auto 300px;
}
Practical Consideration
Use logical properties when sizing should follow the writing mode. Use physical properties when the intended fallback must correspond specifically to physical width or height.
Calculated Values and Variables
The fallback length can use CSS math functions and custom properties, provided the resulting value is a valid nonnegative length.
Using calc()
.component {
contain-intrinsic-block-size: calc(200px + 5rem);
}
Using clamp()
.component {
contain-intrinsic-block-size: clamp(200px, 30vh, 500px);
}
Using min()
.component {
contain-intrinsic-block-size: min(400px, 50vh);
}
Using max()
.component {
contain-intrinsic-block-size: max(250px, 20vh);
}
Using a Custom Property
:root {
--section-block-size: 350px;
}
.component {
contain-intrinsic-block-size: var(--section-block-size);
}
Custom Property with auto
.component {
--fallback-block-size: 350px;
contain-intrinsic-block-size: auto var(--fallback-block-size);
}
Component-Specific Fallbacks
.component {
--fallback-block-size: 300px;
contain-intrinsic-block-size: auto var(--fallback-block-size);
}
.component.large {
--fallback-block-size: 600px;
}
Practical Consideration
Calculated values and custom properties are useful when fallback dimensions need to adapt to viewport conditions or remain consistent across repeated components.
Responsive Layouts
Fallback intrinsic block sizes can be adjusted for different viewport or container sizes.
Basic Responsive Fallback
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 400px;
}
Tablet Layout
@media (max-width: 900px) {
.article-section {
contain-intrinsic-block-size: auto 500px;
}
}
Mobile Layout
@media (max-width: 600px) {
.article-section {
contain-intrinsic-block-size: auto 650px;
}
}
Narrower layouts may produce taller content because text wraps onto additional lines. Adjusting fallback estimates can help account for this difference.
Responsive clamp()
.article-section {
contain-intrinsic-block-size: auto clamp(300px, 40vh, 600px);
}
Container Queries
.section-wrapper {
container-type: inline-size;
}
.article-section {
contain-intrinsic-block-size: auto 350px;
}
@container (max-width: 500px) {
.article-section {
contain-intrinsic-block-size: auto 500px;
}
}
Custom Property Approach
.article-section {
--fallback-size: 400px;
contain-intrinsic-block-size: auto var(--fallback-size);
}
@media (max-width: 600px) {
.article-section {
--fallback-size: 600px;
}
}
Practical Consideration
Use estimates based on the component's expected content dimensions at each breakpoint. Avoid changing fallback values unnecessarily when the existing estimate already provides stable layout behavior.
Practical Uses
The contain-intrinsic-block-size property is useful for sections whose contents may be skipped or whose intrinsic dimensions are intentionally isolated.
Long Documentation Pages
.documentation-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 500px;
}
Reference Sections
.reference-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 350px;
}
Code Example Panels
.code-example {
content-visibility: auto;
contain-intrinsic-block-size: auto 300px;
}
Fixed-Layout Components
.preview-panel {
contain: size;
contain-intrinsic-block-size: 240px;
}
Article Sections
.article-section {
content-visibility: auto;
contain-intrinsic-block-size: auto 600px;
}
Repeated Content Cards
.content-card {
content-visibility: auto;
contain-intrinsic-block-size: auto 220px;
}
When Not to Use
The property is generally unnecessary for elements that are not subject to relevant size containment and can determine their intrinsic block size normally.
Practical Consideration
Use fallback intrinsic sizing when it provides a meaningful benefit to layout stability or contained component sizing.
contain-intrinsic-block-size Example
The following example compares a size-contained element without an intrinsic block-size fallback and one with a 150-pixel fallback.
Both elements use contain: size, which prevents their descendants from contributing to intrinsic sizing. The second element reserves block space through contain-intrinsic-block-size.
<div class="intrinsic-block-demo">
<div class="intrinsic-example">
<h3>Without a Fallback</h3>
<div class="intrinsic-box no-fallback">
<p>This content does not contribute to the container's intrinsic block size.</p>
</div>
</div>
<div class="intrinsic-example">
<h3>With a 150px Fallback</h3>
<div class="intrinsic-box with-fallback">
<p>This container uses a fallback intrinsic block size of 150 pixels.</p>
</div>
</div>
</div>
.intrinsic-block-demo {
display: grid;
gap: 20px;
}
.intrinsic-block-demo .intrinsic-example {
padding: 15px;
border: 1px solid #cccccc;
background-color: #f8f9fa;
}
.intrinsic-block-demo h3 {
margin: 0 0 12px;
font-size: 1.125rem;
}
.intrinsic-block-demo .intrinsic-box {
contain: size;
display: flow-root;
box-sizing: border-box;
padding: 15px;
border: 2px solid #336699;
background-color: #ffffff;
}
.intrinsic-block-demo .intrinsic-box p {
margin: 0;
}
.intrinsic-block-demo .no-fallback {
contain-intrinsic-block-size: none;
}
.intrinsic-block-demo .with-fallback {
contain-intrinsic-block-size: 150px;
}
Without a Fallback
This content does not contribute to the container's intrinsic block size.
With a 150px Fallback
This container uses a fallback intrinsic block size of 150 pixels.
The first container has no fallback intrinsic block size. Because contain: size prevents the paragraph from contributing to intrinsic sizing, the container's block size is determined by its padding, borders, and other applicable sizing constraints.
The second container uses contain-intrinsic-block-size: 150px, providing an intrinsic block-size contribution of 150 pixels. Its padding and borders are added according to the box model.
The example demonstrates that the property supplies an intrinsic size fallback rather than directly setting the element's physical height.
Accessibility
Intrinsic size fallbacks can influence the space reserved for content, making accurate estimates important for accessible layouts.
Avoid Content Overlap
Choose fallback sizes that provide sufficient space for the component's expected contents when containment is active.
Support Text Resizing
Test components with enlarged text and increased browser zoom. Content may require more block space than the original estimate.
Reduce Unexpected Layout Movement
Realistic fallback sizes can help reduce layout movement when skipped content becomes rendered.
Preserve Reading Order
The property does not change the HTML source order or the semantic structure of the document.
Test Keyboard Navigation
When used with content-visibility, ensure interactive elements remain accessible and usable as the browser renders previously skipped content.
Avoid Unnecessary Fixed Dimensions
Intrinsic size fallbacks are often preferable to rigid physical heights when content needs to expand naturally once rendered.
Practical Consideration
Test with realistic content, different font sizes, and narrow viewports to confirm that fallback sizing does not interfere with readability or interaction.
Important Considerations
Keep the following points in mind when using contain-intrinsic-block-size:
- Purpose: Provides a fallback intrinsic block size when relevant size containment is active.
- Initial value:
none. - Inheritance: The property is not inherited.
- Logical dimension: The block dimension follows the element's writing mode.
- Horizontal writing: Block size generally corresponds to physical height.
- Vertical writing: Block size generally corresponds to physical width.
- Length values: Accepts nonnegative CSS lengths.
- Percentages: Not accepted.
- Negative values: Not accepted.
- none: Provides no specified fallback intrinsic block size.
- auto: Must be followed by a length or
none. - auto with length: Uses a remembered intrinsic size when available, otherwise the supplied fallback.
- auto none: Uses a remembered intrinsic size when available, otherwise no specified fallback.
- Size containment: The fallback is relevant when size containment affects the block dimension.
- Inline-size containment: Does not activate the block-size fallback by itself.
- Layout containment: Does not activate the fallback by itself.
- content containment: Does not include size containment.
- strict containment: Includes full size containment.
- content-visibility: Commonly used with this property to reserve space during skipped rendering.
- Remembered sizes: Managed by the browser and not guaranteed to be available.
- Used size: The property supplies an intrinsic sizing contribution rather than an enforced physical dimension.
- Box model: Padding and borders remain part of the element's final dimensions.
- Calculated values: CSS math functions can provide valid nonnegative lengths.
- Custom properties: Can store reusable fallback values.
- 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, browser zoom, and interactive content.
Use contain-intrinsic-block-size when an element needs a predictable intrinsic block-size contribution during size containment. For content that is rendered normally without relevant size containment, the property generally has no visible effect.
Browser Support
The contain-intrinsic-block-size property is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.
Support for the auto remembered-size syntax and related containment features may vary in older browser versions.
Basic Example
.component {
contain: size;
contain-intrinsic-block-size: 300px;
}
With content-visibility
.component {
content-visibility: auto;
contain-intrinsic-block-size: auto 300px;
}
Feature Detection
@supports (contain-intrinsic-block-size: auto 300px) {
.component {
content-visibility: auto;
contain-intrinsic-block-size: auto 300px;
}
}
Feature queries can detect whether a browser accepts the specified syntax. They do not guarantee identical rendering behavior in every browser.
For current compatibility information, visit Can I Use? and search for contain-intrinsic-block-size.
Specifications
The contain-intrinsic-block-size property is defined in CSS Containment Module Level 3.
CSS Containment Module Level 3
The specification defines intrinsic size fallback properties, logical and physical dimensions, and the remembered-size behavior of the auto keyword.
