Component
stretch
Demo
tokens.css,
base.css and stretch.css. No scripts.
Source
Copy both files, or run npx nojsui add stretch.
Browser support
Works across current and earlier versions of every major engine.
| Feature | Baseline | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|
| Feature | Baseline | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|---|
| stretch | limited | 138 | 138 | — | 27 | 138 | — | 27 |
Usage
Add the class to an element that would otherwise shrink-wrap — a button, an input, a select, an inline-block — to make it fill its container:
<button type="submit" class="sk-stretch">Create account</button>
It is a utility, not a component with parts. One class, one declaration, and
it combines with anything: <button class="sk-button sk-stretch">.
How it works
Why not inline-size: 100%
100% is the size of the containing block. Margins are added outside that,
so an element with any inline margin overflows its container by exactly that
margin. box-sizing: border-box (which base.css sets) absorbs padding and
border. It never absorbs margin.
inline-size: stretch is the containing block minus the margins: the size
an ordinary block already gets from auto. The keyword makes that size
available to the elements that auto shrink-wraps instead:
| Element | auto gives | 100% gives | stretch gives |
|---|---|---|---|
A <div> in normal flow | Fills, minus margins | Fills, plus margins (overflows) | Fills, minus margins |
A <button>, <input>, <select> | Its content’s width | Fills, plus margins | Fills, minus margins |
| An absolutely positioned box with one inline inset | Its content’s width | The containing block, plus margins | The containing block, minus margins |
So the first row does not need this utility: a plain block already fills. The other rows do.
What it does not do
stretch fills the containing block, not the space left over in a row. In a
flex row it makes the item as wide as the whole container, so the item wraps or
squeezes its siblings. For “take the remaining space”, use flex: 1 on the item,
not this.
Keyboard contract
None. This is a sizing utility. Whatever element you put it on keeps its own keyboard behaviour.
| Key | Behaviour |
|---|---|
Tab | Unchanged — focus order is the element’s own |
| Any other key | Unchanged |
Verified manually in VoiceOver and NVDA: not applicable — the utility changes size only, and adds no element, role or state.
Accessibility notes
A wider control is an easier target, which is most of why forms on narrow screens stretch their buttons. Nothing about the element’s role, name or focus behaviour changes.
The 100% overflow this utility avoids has an accessibility side: content that
runs past its container can cause sideways scrolling at high zoom (WCAG 1.4.10,
Reflow). stretch cannot overflow by its margins.
Degradation
| Feature used | Baseline status | Behavior without it |
|---|---|---|
stretch | limited | inline-size: 100% instead. Identical when the element has no inline margins; with margins, it overflows the container by them. Firefox today. Avoid inline margins on a stretched element if Firefox matters to you, or put the space on the parent as padding. |