CSS view-timeline-inset Property
The CSS view-timeline-inset property adjusts the effective boundaries of a scrollport used to calculate an element's view progress timeline.
It accepts length, percentage, and auto values to control where view progress begins and ends relative to the scrollport. This allows scroll-driven animations to respond to customized visibility boundaries without changing the scroll container's actual size or layout.
The property works with view-timeline, view-timeline-name, and animation-timeline. Unlike view-timeline-name and view-timeline-axis, it is not a component of the view-timeline shorthand.
view-timeline-inset Syntax
The view-timeline-inset property accepts one or two values. Each value can be auto, a CSS length, or a percentage.
Basic Syntax
.example {
view-timeline-inset: auto;
}
Single Length
.example {
view-timeline-inset: 50px;
}
Single Percentage
.example {
view-timeline-inset: 10%;
}
Two Lengths
.example {
view-timeline-inset: 50px 20px;
}
Mixed Values
.example {
view-timeline-inset: 10% 30px;
}
Automatic and Explicit Insets
.example {
view-timeline-inset: auto 40px;
}
Negative Values
.example {
view-timeline-inset: -30px;
}
CSS-Wide Keywords
.example {
view-timeline-inset: initial;
}
.example {
view-timeline-inset: inherit;
}
.example {
view-timeline-inset: unset;
}
.example {
view-timeline-inset: revert;
}
.example {
view-timeline-inset: revert-layer;
}
Invalid Values
.example {
view-timeline-inset: 10px 20px 30px;
}
.example {
view-timeline-inset: center;
}
.example {
view-timeline-inset: 2;
}
The property accepts no more than two values. The keyword center and unitless nonzero numbers are invalid.
Property Values
| Value | Description |
|---|---|
auto |
Uses the automatic inset, which takes the relevant scroll-padding into account. This is the initial value. |
<length> |
Specifies an inset using a CSS length such as 20px, 2rem, or 5vh. |
<percentage> |
Specifies an inset relative to the scrollport size along the timeline axis. |
<length-percentage> <length-percentage> |
Sets separate insets for the start and end boundaries. |
auto <length-percentage> |
Uses the automatic start inset and an explicit end inset. |
<length-percentage> auto |
Uses an explicit start inset and the automatic end inset. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | All elements |
| Computed value | Specified keywords and computed length-percentage values |
| Animation type | By computed value type |
| Percentages | Relative to the scrollport size along the selected axis |
| Shorthand | None |
| Specification | Scroll-driven Animations Module Level 1 |
Note: The view-timeline-inset property is independent of the view-timeline shorthand. It can be declared alongside the shorthand without being reset by it.
How It Works
A view progress timeline tracks the position of a subject element as it moves through the scrollport of its nearest ancestor scroll container.
By default, the timeline uses the scrollport's effective visibility boundaries. The view-timeline-inset property allows those boundaries to be adjusted for timeline calculations.
Step 1: Create a Scroll Container
<div class="scroll-container">
<div class="spacer"></div>
<div class="card">Animated Card</div>
<div class="spacer"></div>
</div>
Step 2: Enable Scrolling
.scroll-container {
height: 300px;
overflow-y: auto;
}
.spacer {
height: 250px;
}
Step 3: Create a View Timeline
.card {
view-timeline: --card-view block;
}
Step 4: Adjust the Insets
.card {
view-timeline-inset: 50px;
}
The effective start and end boundaries are moved inward by 50 pixels along the block axis.
Step 5: Attach an Animation
.card {
animation: reveal 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
How the Inset Affects Progress
Because the effective visibility boundaries have changed, the animation's entry and exit ranges are calculated relative to the adjusted scrollport.
Important Distinction
The inset does not change the element's actual position, the scroll container's dimensions, or its clipping area. It changes the boundaries used to calculate view progress.
The auto Value
The auto value uses the automatic inset for the selected boundary.
Syntax
.example {
view-timeline-inset: auto;
}
Default Behavior
The auto value is the initial value. It uses the corresponding scroll-padding value of the scroll container when determining the effective boundary.
Example Without Explicit Scroll Padding
.scroll-container {
overflow-y: auto;
}
.card {
view-timeline: --card-view block;
view-timeline-inset: auto;
}
With no effective scroll-padding inset, the timeline uses the normal scrollport boundaries.
Example With Scroll Padding
.scroll-container {
overflow-y: auto;
scroll-padding-block: 40px;
}
.card {
view-timeline: --card-view block;
view-timeline-inset: auto;
}
The automatic inset takes the scroll container's relevant scroll-padding values into account.
Mixing auto With a Length
.card {
view-timeline-inset: auto 30px;
}
The start boundary uses its automatic inset, while the end boundary uses an explicit 30-pixel inset.
When to Use It
Use auto when the timeline should follow the scroll container's existing scroll-padding configuration.
Length Values
Length values provide explicit distances for adjusting the effective scrollport boundaries.
Pixels
.card {
view-timeline-inset: 40px;
}
Both boundaries are moved inward by 40 pixels.
Relative Font Units
.card {
view-timeline-inset: 2rem;
}
The inset is calculated using the root element's font size.
Viewport Units
.card {
view-timeline-inset: 5vh;
}
The inset is based on the viewport height.
Different Start and End Lengths
.card {
view-timeline-inset: 60px 20px;
}
The start boundary moves inward by 60 pixels and the end boundary moves inward by 20 pixels.
Using calc()
.card {
view-timeline-inset: calc(20px + 2rem);
}
The calc() function can combine compatible length and percentage values.
When to Use Lengths
Use length values when a specific distance from the scrollport edge is required, such as accounting for a fixed header or creating a consistent reveal boundary.
Percentage Values
Percentage values adjust the effective boundaries relative to the size of the scrollport along the selected timeline axis.
Basic Percentage
.card {
view-timeline-inset: 10%;
}
Both boundaries move inward by 10% of the scrollport size along the selected axis.
Two Percentages
.card {
view-timeline-inset: 20% 5%;
}
The start boundary uses 20% and the end boundary uses 5%.
Mixed Percentage and Length
.card {
view-timeline-inset: 15% 30px;
}
Vertical Scrollport Example
If the scrollport is 400 pixels tall and the timeline uses the vertical axis, an inset of 10% corresponds to 40 pixels at each boundary.
Horizontal Scrollport Example
If the scrollport is 600 pixels wide and the timeline uses the horizontal axis, an inset of 10% corresponds to 60 pixels at each boundary.
Responsive Behavior
Percentage insets adjust automatically when the scrollport size changes.
When to Use Percentages
Use percentages for responsive reveal effects that should maintain proportional boundaries across different screen sizes.
Two-Value Syntax
The view-timeline-inset property accepts two values to control the start and end boundaries independently.
One Value
.card {
view-timeline-inset: 40px;
}
The same value applies to both boundaries.
Two Values
.card {
view-timeline-inset: 60px 20px;
}
The first value applies to the start boundary and the second applies to the end boundary.
Logical Boundaries
The start and end boundaries follow the selected timeline axis and its direction. They are not necessarily the physical top and bottom edges.
Start Boundary Only
.card {
view-timeline-inset: 50px 0;
}
The start boundary moves inward by 50 pixels while the end boundary remains unchanged.
End Boundary Only
.card {
view-timeline-inset: 0 50px;
}
Mixed Automatic and Explicit Values
.card {
view-timeline-inset: auto 40px;
}
Asymmetric Reveal Effects
Different start and end insets are useful when an animation should respond differently as an element enters and leaves the effective scrollport.
Positive and Negative Insets
Inset values can be positive, zero, or negative. Their sign determines whether the effective scrollport boundaries move inward or outward.
Positive Insets
.card {
view-timeline-inset: 40px;
}
Positive values move the effective boundaries inward, reducing the area used to calculate view progress.
Zero Insets
.card {
view-timeline-inset: 0;
}
Zero uses the scrollport's normal boundaries, regardless of its scroll-padding values.
Negative Insets
.card {
view-timeline-inset: -40px;
}
Negative values move the effective boundaries outward, extending the area used for timeline calculations.
Mixed Positive and Negative Values
.card {
view-timeline-inset: 30px -20px;
}
The start boundary moves inward by 30 pixels while the end boundary extends outward by 20 pixels.
Effect on Animation Timing
Changing the effective boundaries changes the scroll positions associated with the timeline's entry, exit, and cover ranges.
Important Consideration
Negative insets do not make content outside the actual scrollport visible. They only extend the boundaries used for timeline progress calculations.
Interaction With scroll-padding
The auto value of view-timeline-inset takes the scroll container's relevant scroll-padding values into account.
Scroll Padding Example
.scroll-container {
height: 300px;
overflow-y: auto;
scroll-padding-block: 40px;
}
.card {
view-timeline: --card-view block;
view-timeline-inset: auto;
}
Explicit Insets
.card {
view-timeline-inset: 20px;
}
An explicit value defines the timeline inset independently of the automatic scroll-padding-based value.
Mixed Values
.card {
view-timeline-inset: auto 20px;
}
The start boundary uses the automatic inset, while the end boundary uses 20 pixels.
Different Responsibilities
The scroll-padding property affects the optimal viewing region used by scrolling operations such as scroll snapping and scrolling an element into view.
The view-timeline-inset property adjusts the boundaries used for view progress timeline calculations.
Important Consideration
Setting view-timeline-inset does not modify the scroll container's scroll-padding or its actual layout.
View Timeline Ranges
View progress timelines provide named ranges that describe an element's movement through the effective scrollport.
Changing view-timeline-inset changes the boundaries used to calculate those ranges.
cover
The cover range represents the subject's full passage through the effective scrollport.
entry
The entry range represents the subject entering the effective scrollport.
exit
The exit range represents the subject leaving the effective scrollport.
contain
The contain range represents the interval when the subject is fully contained within the effective scrollport, or when a larger subject fully covers it.
entry-crossing
The entry-crossing range tracks the subject crossing the entry edge.
exit-crossing
The exit-crossing range tracks the subject crossing the exit edge.
Using animation-range
.card {
view-timeline: --card-view block;
view-timeline-inset: 15%;
animation: reveal 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
The animation uses the entry range calculated from the adjusted effective scrollport.
Changing the Animation Range
.card {
animation-range: cover 0% cover 100%;
}
The animation now progresses across the full cover range.
Important Distinction
The view-timeline-inset property adjusts the effective scrollport boundaries. The animation-range property selects the portion of the resulting timeline used by the animation.
Related CSS Properties
view-timeline
.card {
view-timeline: --card-view block;
}
Creates a named view progress timeline and specifies its axis.
view-timeline-name
.card {
view-timeline-name: --card-view;
}
Defines the name used to identify a view progress timeline.
view-timeline-axis
.card {
view-timeline-axis: block;
}
Specifies the axis used to calculate view progress.
animation-timeline
.card {
animation-timeline: --card-view;
}
Connects an animation to a named timeline.
animation-range
.card {
animation-range: entry 0% entry 100%;
}
Defines the portion of a timeline over which an animation runs.
scroll-padding
.scroll-container {
scroll-padding: 40px;
}
Defines padding within the scrollport's optimal viewing region and influences automatic view timeline insets.
scroll-padding-block
.scroll-container {
scroll-padding-block: 30px;
}
Defines scroll padding along the block axis.
scroll-padding-inline
.scroll-container {
scroll-padding-inline: 20px;
}
Defines scroll padding along the inline axis.
Complete Example
.scroll-container {
height: 300px;
overflow-y: auto;
scroll-padding-block: 20px;
}
.card {
view-timeline-name: --card-view;
view-timeline-axis: block;
view-timeline-inset: 10%;
animation: reveal 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
Inheritance
The view-timeline-inset property is not inherited. Child elements do not automatically receive the inset value declared on their parent.
Parent Declaration
.parent {
view-timeline-inset: 40px;
}
Child Declaration
.parent .child {
view-timeline-inset: 10%;
}
The child uses its own declared inset.
Explicit Inheritance
.parent {
view-timeline-inset: 40px;
}
.parent .child {
view-timeline-inset: inherit;
}
The child explicitly inherits the parent's computed inset value.
Restore the Initial Value
.example {
view-timeline-inset: initial;
}
This restores the initial value of auto.
Using unset
.example {
view-timeline-inset: unset;
}
Because the property is not inherited, unset behaves like initial.
Important Consideration
Inheriting an inset value does not automatically inherit a named view timeline. Timeline names, axes, and insets are separate declarations.
Practical Examples
Delay the Effective Entry Boundary
.reveal-card {
view-timeline: --card-view block;
view-timeline-inset: 50px;
animation: reveal 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
The positive inset moves the effective boundaries inward, changing when the entry animation begins and ends.
Responsive Percentage Insets
.reveal-image {
view-timeline: --image-view block;
view-timeline-inset: 15%;
}
Different Start and End Insets
.section {
view-timeline: --section-view block;
view-timeline-inset: 20% 5%;
}
Extend the Effective Scrollport
.card {
view-timeline: --card-view block;
view-timeline-inset: -30px;
}
Use Scroll Padding Automatically
.scroll-container {
scroll-padding-block: 60px;
}
.card {
view-timeline: --card-view block;
view-timeline-inset: auto;
}
Account for a Fixed Header
.section {
view-timeline: --section-view block;
view-timeline-inset: 80px 0;
}
This example adjusts the start boundary by 80 pixels while leaving the end boundary unchanged.
Use calc() for Flexible Insets
.card {
view-timeline-inset: calc(10% + 20px);
}
Combine With an Animation Range
.card {
view-timeline: --card-view block;
view-timeline-inset: 10%;
animation: fade-in 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
view-timeline-inset Example
This example compares two cards with different view timeline insets. Both cards use the same animation, but their effective visibility boundaries differ.
Scroll inside each demonstration to observe how changing the inset affects the animation's progress. Browsers without the required scroll-driven animation features display the cards without the effect.
HTML Example
<div class="inset-demo">
<h3>Inset: 0</h3>
<div class="inset-scroll">
<div class="inset-spacer">Scroll down</div>
<div class="inset-card inset-zero">Normal Boundaries</div>
<div class="inset-spacer">Continue scrolling</div>
</div>
<h3>Inset: 20%</h3>
<div class="inset-scroll">
<div class="inset-spacer">Scroll down</div>
<div class="inset-card inset-adjusted">Adjusted Boundaries</div>
<div class="inset-spacer">Continue scrolling</div>
</div>
</div>
CSS Example
.inset-demo h3 {
margin: 15px 0 10px;
}
.inset-scroll {
height: 220px;
overflow-y: auto;
padding: 10px;
border: 1px solid #ccc;
}
.inset-spacer {
display: grid;
place-items: center;
height: 180px;
color: #555;
}
.inset-card {
display: grid;
place-items: center;
min-height: 100px;
padding: 20px;
background-color: #e5eef7;
border: 2px solid #0066cc;
border-radius: 6px;
text-align: center;
}
@keyframes inset-reveal {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@supports (view-timeline-inset: 10%) and (animation-timeline: view()) {
.inset-zero {
view-timeline: --zero-view block;
view-timeline-inset: 0;
animation: inset-reveal 1s linear both;
animation-timeline: --zero-view;
animation-range: entry 0% entry 100%;
}
.inset-adjusted {
view-timeline: --adjusted-view block;
view-timeline-inset: 20%;
animation: inset-reveal 1s linear both;
animation-timeline: --adjusted-view;
animation-range: entry 0% entry 100%;
}
}
@media (prefers-reduced-motion: reduce) {
.inset-card {
animation: none;
}
}
Inset: 0
Inset: 20%
Understanding the Results
Both cards define named view progress timelines and use the same opacity and translation animation.
Normal Boundaries
The first card uses view-timeline-inset: 0, so its view progress is calculated using the scrollport's normal boundaries.
Adjusted Boundaries
The second card uses view-timeline-inset: 20%, moving the effective start and end boundaries inward by 20% of the scrollport size.
Animation Progress
Because the effective boundaries differ, the cards reach equivalent animation progress at different scroll positions.
Experiment With the Inset
Increase the percentage to create a smaller effective scrollport.
.inset-adjusted {
view-timeline-inset: 30%;
}
Experiment With Negative Values
.inset-adjusted {
view-timeline-inset: -20px;
}
The effective boundaries extend beyond the normal scrollport, changing the scroll positions associated with the animation range.
Experiment With Asymmetric Insets
.inset-adjusted {
view-timeline-inset: 25% 5%;
}
The start and end boundaries now use different inset amounts.
Accessibility Considerations
The view-timeline-inset property affects scroll-driven animation timing but does not change document semantics or reading order.
Respect Reduced Motion Preferences
Provide an alternative for users who prefer reduced motion.
@media (prefers-reduced-motion: reduce) {
.animated-card {
animation: none;
}
}
Keep Important Content Visible
Do not rely on scroll-driven animations to make essential information available.
Avoid Hidden Interactive Controls
Buttons, links, and form controls should remain discoverable and usable even when an animation has not progressed.
Avoid Excessive Movement
Large translations and repeated motion can be distracting or uncomfortable.
Maintain Readable Contrast
Animations that change opacity should not make important text difficult to read.
Support Keyboard Navigation
Scrollable regions and interactive elements should remain usable through keyboard navigation.
Test Without Animation
Verify that the page remains understandable when scroll-driven animations are unsupported or disabled.
Common Mistakes
Using Three or More Values
.example {
view-timeline-inset: 10px 20px 30px;
}
The property accepts one or two values.
Using an Unsupported Keyword
.example {
view-timeline-inset: center;
}
The center keyword is not valid.
Using a Unitless Nonzero Number
.example {
view-timeline-inset: 20;
}
Use a length such as 20px or a percentage such as 20%.
Confusing Insets With Padding
The property does not add padding or change an element's layout.
Assuming Insets Change Clipping
Negative insets do not make content outside the actual scrollport visible.
Confusing auto With Zero
The auto value can use scroll-padding values, while 0 explicitly uses no inset.
Using Insets Without a View Timeline
The property adjusts view timeline calculations. It does not create a named timeline by itself.
Forgetting animation-timeline
A named timeline must be referenced by an animation to control its progress.
Confusing Insets With animation-range
Insets adjust the effective scrollport boundaries. Animation ranges select portions of the resulting timeline.
Ignoring Browser Support
Provide fallbacks because scroll-driven animation support varies across browsers.
Ignoring Reduced Motion Preferences
Disable or simplify substantial animation when the user requests reduced motion.
Important Considerations
Keep the following points in mind when using view-timeline-inset:
- The property adjusts effective scrollport boundaries for view progress timelines.
- It is part of CSS scroll-driven animations.
- Its initial value is
auto. - The property is not inherited.
- It accepts one or two values.
- Values can be
auto, lengths, or percentages. - A single value applies to both boundaries.
- Two values control the start and end boundaries separately.
- Positive values move effective boundaries inward.
- Negative values move effective boundaries outward.
- Zero uses the normal scrollport boundary without an inset.
- The
autovalue takes relevant scroll-padding into account. - Percentages are relative to the scrollport size along the selected axis.
- Length and percentage values can be combined using
calc(). - The start and end boundaries follow the selected timeline axis.
- Insets do not change the scroll container's actual dimensions.
- Insets do not change the scroll container's clipping area.
- Insets do not add CSS padding or margins.
- The property does not change the element's position.
- The property does not create a named timeline by itself.
- Use
view-timeline-nameorview-timelineto declare a timeline. - Use
view-timeline-axisto select the measurement axis. - Use
animation-timelineto attach an animation to a timeline. - Use
animation-rangeto select a portion of the timeline. - Changing the inset changes the scroll positions associated with timeline ranges.
- The property is not included in the
view-timelineshorthand. - Explicit insets can override the automatic scroll-padding-based behavior.
- Use percentage insets for responsive effects.
- Use length insets for fixed-distance adjustments.
- Provide fallbacks for unsupported browsers.
- Respect reduced-motion preferences.
- Keep essential content accessible without animation.
- Test effects across different scrollport sizes and writing modes.
Browser Support
The CSS view-timeline-inset property has limited availability compared with established CSS layout and animation properties.
Support varies among browsers and versions. The property is implemented in Chromium-based browsers, while compatibility in other browser engines and older versions should be checked before relying on it.
For current compatibility information, visit Can I Use? and search for view-timeline-inset.
Standard Declaration
.card {
view-timeline: --card-view block;
view-timeline-inset: 10%;
}
Feature Detection
@supports (view-timeline-inset: 10%) and (animation-timeline: view()) {
.card {
view-timeline: --card-view block;
view-timeline-inset: 10%;
animation-timeline: --card-view;
}
}
Progressive Enhancement
Start with visible content and add scroll-driven animations only when the necessary features are supported.
.card {
opacity: 1;
transform: none;
}
@supports (view-timeline-inset: 10%) and (animation-timeline: view()) {
.card {
view-timeline: --card-view block;
view-timeline-inset: 10%;
animation: reveal 1s linear both;
animation-timeline: --card-view;
animation-range: entry 0% entry 100%;
}
}
Vendor Prefixes
The standard property uses the unprefixed view-timeline-inset name. Experimental browser implementations may differ, so consult current documentation when supporting older versions.
Testing Recommendations
Test positive, negative, and percentage insets. Verify interactions with scroll-padding and confirm that content remains usable when scroll-driven animations are unsupported.
Specifications
The view-timeline-inset property is defined in the Scroll-driven Animations Module Level 1 specification.
Scroll-driven Animations Module Level 1 - view-timeline-inset
The specification defines how explicit and automatic insets adjust the effective scrollport boundaries used for view progress timelines.
For additional documentation and examples, consult MDN Web Docs.
