Qu'est-ce que Generateur de dimensionnement CSS stretch ?
The CSS stretch keyword (Chrome 138+) is the standard value for fill-available sizing, replacing the vendor-prefixed -webkit-fill-available and -moz-available keywords. When you set width: stretch, the element sizes to fill the available space using margin-box sizing — meaning the element's margin-box fits inside the containing block. This differs from width: 100% which uses content-box sizing and often overflows when padding, border, or margin are present. stretch works in block, flex, grid, and absolutely positioned layout contexts.
Réponse rapide
Use width: stretch or height: stretch for standard fill-available sizing. Unlike width: 100%, stretch uses margin-box sizing so padding and border do not cause overflow. Replaces -webkit-fill-available and -moz-available with a single standardized keyword. Chrome 138+, Firefox 130+, Safari 18.2+.
Limites
- stretch is not yet supported in all browsers. Chrome 138+, Firefox 130+, and Safari 18.2+ support it. Keep vendor-prefixed fallbacks (-webkit-fill-available, -moz-available) and a width: 100% fallback for older browsers.
- stretch only works on elements with block, flex, grid, or absolutely positioned display. Inline elements, table cells, and replaced elements (img, video, iframe without explicit sizing) do not support stretch sizing.
- In flex and grid contexts, stretch may interact unexpectedly with alignment properties. A flex item with align-self: stretch and width: stretch can produce conflicting sizing instructions — the stretch keyword on the sizing property takes precedence over alignment stretch.
Comment utiliser cet outil
- Select your layout context — the behavior of stretch differs slightly between block, flex, grid, and absolutely positioned elements.
- Choose the axis you want to stretch (width, height, or both via inset: 0 for abspos).
- Review the layout-specific note explaining how stretch interacts with margins, padding, and the containing block in your chosen context.
- Copy the generated CSS and replace any existing width: 100% patterns or vendor-prefixed fill-available declarations.
A quoi il sert
- Replace width: 100% on an input or select element that overflows its parent due to padding and border — stretch uses margin-box sizing so the total box fits inside the container.
- Standardize cross-browser fill-available sizing by replacing -webkit-fill-available and -moz-available with the standard stretch keyword.
- Make an absolutely positioned element stretch to the edges of its positioned ancestor without explicit top/right/bottom/left values.