modern-web-guidance
Search tool for modern web development best practices. MANDATORY: Execute FIRST for all HTML/CSS and clientside JS tasks. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns. Trigger immediately for: modals/dialogs/popovers, tables, dark mode, anchor positioning, container queries, view transitions, scroll-driven animations, parallax/reveals, forms, validation, autofill, accessibility, custom selects, scrollbars, CWV (LCP, INP, CLS), content-visibility, fetch pri
Install
npx skills add https://github.com/GoogleChrome/modern-web-guidance --skill modern-web-guidanceAnimate to Intrinsic Sizes
Animating elements to dynamic sizes like block-size: auto or inline-size: max-content has historically required JavaScript or fragile "max-height" hacks. The interpolate-size property and calc-size() function allow the browser to natively interpolate between fixed lengths and intrinsic sizing keywords.
Implementation steps
- Opt-in to keyword interpolation: Apply
interpolate-size: allow-keywordsto a parent element (typically:root) to enable transitions for properties using intrinsic keywords. - Define the transition: Set a
transitionfor the sizing property (e.g.,block-size,inline-size) on the target element. - Use intrinsic keywords: Change the sizing property to a supported intrinsic keyword—
auto,min-content,max-content,fit-content, or (for flex-basis)content—during an interaction (e.g.,:hoveror a state class). - Perform calculations (Optional): Use
calc-size()if you need to perform math on an intrinsic size (e.g.,auto + 2rem).calc-size()also supports theanykeyword for basis-agnostic calculations.
Example: Generic Expansion Pattern
You can apply this pattern to any container (like a "Show More" section or a navigation menu) to transition between a restricted height and the element's natural size.
Example: Calculated Intrinsic Inline-Size
Example: Transition from Intrinsic to Fixed
You can also animate in the opposite direction—starting from a natural size and collapsing to a specific length. This is useful for "dismissible" components.
Key constraints
- Keyword-to-Keyword Restriction: You cannot animate between two different keywords directly (e.g., from
min-contenttomax-content). One end of the transition must be a fixed length or percentage (e.g.,0toauto). - Calc-size Syntax: Inside
calc-size(), you cannot mix different intrinsic keywords in the same expression. The first argument (the basis) defines whatsizerepresents. - Opt-in Requirement: Transitions to intrinsic keywords are disabled by default (
numeric-only) to maintain backward compatibility. You must applyinterpolate-size: allow-keywordsto the element or an ancestor.calc-size()acts as a per-property override, automatically enabling interpolation whenever it is used.
Fallback strategies
Browser support for interpolate-size: Limited availability. Supported by: Chrome 129 (Sep 2024) and Edge 129 (Sep 2024). Unsupported in: Firefox and Safari.
Browser support for calc-size(): Limited availability. Supported by: Chrome 129 (Sep 2024) and Edge 129 (Sep 2024). Unsupported in: Firefox and Safari.
interpolate-size and calc-size() are progressive enhancements. Browsers that do not support them will perform an instant jump to the target size.
- Graceful Degradation: For simple
block-size: autotransitions, standard browsers will simply toggle the size instantly, which is functional but less polished. - Manual keyword fallbacks: When using
calc-size(), always provide a standard keyword fallback for older browsers, as they will discard the entirecalc-size()declaration.