CKTIS / CSS
flex-line-count — minimum flex line count
A Flexbox Level 2 draft property that sets a minimum line count for balancing and also affects available cross-axis space.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
flex-line-count: <integer [1,∞]>;flex-line-count accepts an integer of at least 1; its initial value is 1, and it is not inherited. With flex-wrap: balance, it specifies a minimum, not a maximum, line count. The item count caps that minimum. With flex-wrap: nowrap, it has no effect.
If the flex container’s available cross-axis space is definite, (S - (N - 1) * G) / N calculates the available cross-axis space used to size flex items. S is the container’s definite available cross-axis space, N is the specified value of flex-line-count, and G is the gap between lines. The result does not prescribe the final used size of each line. Without balance, this is its only effect; percentage resolution is unchanged.
This is an editor’s draft feature. The example was run in Chromium 157, but that run does not establish support in Chromium 152. Check parsing and layout in the target browser. The code retains ordinary wrapping as a fallback.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>flex-line-count with balanced wrapping</title>
<style>
.demo {
display: flex;
flex-wrap: wrap;
width: 300px;
gap: 10px;
align-items: flex-start;
}
.demo > span {
flex: 0 0 80px;
height: 30px;
background: lightblue;
}
@supports (flex-wrap: balance) and (flex-line-count: 2) {
.demo {
flex-wrap: balance;
flex-line-count: 2;
}
}
</style>
</head>
<body>
<div class="demo" role="group" aria-label="Three equal-width flex items"><span>A</span><span>B</span><span>C</span></div>
<script>
const demo = document.querySelector('.demo');
const supportsCount = CSS.supports('flex-line-count', '2');
const supportsBalance = CSS.supports('flex-wrap', 'balance');
console.log(`flex-line-count: ${supportsCount ? 'supported' : 'unsupported'}`);
if (supportsCount && supportsBalance) {
console.log(`Computed minimum line count: ${getComputedStyle(demo).getPropertyValue('flex-line-count')}`);
} else {
const lineTops = new Set(Array.from(demo.children, item => item.getBoundingClientRect().top));
console.log(`Fallback flex line count: ${lineTops.size}`);
}
</script>
</body>
</html>Result
flex-line-count: supported Computed minimum line count: 2
The example ran in an isolated Chromium 157.0.8103.51 environment with external requests blocked. The console output matched the stated result exactly.