CKTIS / CSS
align-items: a shared alignment for child boxes
Choose the default cross-axis alignment in flexbox or block-axis alignment in a grid.
Version: CSS Modules
Syntax
display: flex; align-items: center;Set align-items on the container. Its value supplies the default alignment used by children whose align-self is auto; it is not inherited as an ordinary inherited property. In a row flex container the cross axis is normally vertical, but flex-direction and writing mode determine the actual axes. In grid, each item aligns within its own grid area along the block axis. This is different from align-content, which distributes lines or tracks.
center, start, end and the baseline values position items in different ways. stretch can enlarge an automatically sized item within its size constraints; it does not overwrite an explicit height in a horizontal row. The initial normal value is layout-dependent and commonly behaves like stretch in flexbox, so do not treat normal as a universal centering rule. Auto margins can take priority; safe center favors the start side when centering would cause unsafe overflow.
The example uses a 100px-high flex row with 20px and 40px children. Centering places their top edges at 40px and 30px. After changing to stretch and making only the second height auto, the heights become 20px and 100px, both starting at zero. Real rectangle and layout-size measurements demonstrate why fixed and automatic sizes behave differently.
Examples
const row = document.createElement('div');
row.style.cssText = 'display:flex;align-items:center;width:200px;height:100px';
const a = document.createElement('div'), b = document.createElement('div');
a.style.cssText = 'width:40px;height:20px';
b.style.cssText = 'width:40px;height:40px';
row.append(a,b); document.body.append(row);
const top = el => Math.round(el.getBoundingClientRect().top - row.getBoundingClientRect().top);
console.log('center top:', top(a), top(b));
row.style.alignItems = 'stretch'; b.style.height = 'auto';
console.log('stretch height:', a.offsetHeight, b.offsetHeight);
console.log('stretch top:', top(a), top(b));
row.remove();Result
center top: 40 30 stretch height: 20 100 stretch top: 0 0
Executed in Chromium 157.0.8103.51. These measurements cover a horizontal single-line flex row without margins or borders, not every writing mode, baseline fallback or grid sizing case.