Every layout engineer and frontend developer knows this quiet visual disaster: a designer draws a stylish card with a repeating background pattern — whether a pixel grid, diagonal hatches, or a decorative retro-UI tile — yet the text inside the block is dynamic. The moment a user switches the interface language or opens the page on a smartphone, the block height shifts and the bottom row of the background artwork gets awkwardly sliced right down the middle.
Previously, solving this meant bringing in heavy JavaScript artillery. Developers attached a ResizeObserver, measured the element's offsetHeight, calculated the remainder after dividing by tile height, and forced an inline min-height. That didn't just load the rendering thread — it also triggered unpleasant layout shifts (Cumulative Layout Shift).
Well-known UI researcher Ahmad Shadeed showed that the modern W3C specification finally lets you solve this in pure CSS using a pairing of the math functions calc-size() and round().
The magic of pairing calc-size() and round()
The round() function, introduced in CSS Values 4, can round numeric values to a given step (interval). But it had a fundamental limitation: it couldn't operate on sizing keywords like auto or max-content, because the browser only computes those during layout.
That's where calc-size(), standardized in CSS Values and Units Module Level 5, enters the scene. It takes a sizing keyword as its basis, and in the second argument lets you run a math operation on the computed value via the size keyword:
.tile-card {
--tile-width: 52px;
--tile-height: 44px;
background-image: url("pattern-tile.png");
background-repeat: repeat;
background-size: var(--tile-width) var(--tile-height);
padding: 24px;
/* Content height is rounded up to a multiple of the tile */
height: calc-size(auto, round(up, size, var(--tile-height)));
}
Let's break this formula down plainly. The auto basis tells the browser: "First compute the natural height of the block from the volume of text inside." Then the size variable feeds that pixel count into round(up, size, var(--tile-height)). The up mode rounds the result strictly upward to the nearest multiple of our 44-pixel tile height. If the text needs 150 pixels, the block automatically grows to 176 pixels (44 × 4), and the bottom row of the pattern stays completely intact.
Progressive enhancement via @supports
Why is it important to use the up rounding strategy specifically? The round() function supports three modes: nearest, down, and up. If you use down or nearest, the final container height can end up smaller than the text height, causing the block to overflow and content to spill out.
Right now, calc-size() is fully supported in Chromium-based browser engines (starting from Chrome 129). In Firefox and Safari, implementation of the spec is actively underway. So in production code, you should roll out this technique as progressive enhancement using @supports:
/* Safe baseline style for all browsers */
.tile-card {
--tile-width: 52px;
--tile-height: 44px;
background-image: url("pattern-tile.png");
background-repeat: repeat;
background-size: var(--tile-width) var(--tile-height);
padding: 24px;
height: auto;
}
/* Progressive height alignment in modern browsers */
@supports (height: calc-size(auto, size)) {
.tile-card {
height: calc-size(auto, round(up, size, var(--tile-height)));
}
}
Combined with other modern layout features we mentioned in our roundup of 12 features of modern CSS, this approach rids your project of extra kilobytes of scripts and gives the browser back its native role as geometry calculator.


