Conditional Border Radius In CSS
Frontend developers have a compact CSS trick to digest: adjusting border-radius based on whether an element fills the viewport. Ahmad Shadeed documents the approach, which comes from the Facebook CSS codebase. The behavior it produces: an element spanning the viewport's full width gets no rounding at all, while every other element gets 8px.
.card {
border-radius: max(0px, min(8px, calc((100vw - 4px - 100%) * 9999)));
}
The whole mechanism fits in one line. It hinges on comparing 100vw against 100%. In most cases the computed radius lands at 8px; once the component matches the viewport width (within 4px, though that tolerance can be dropped), the formula produces a negative number, which is invalid, and the radius falls back to 0px.
The 9999 multiplier acts as a switch: it eliminates low-positive intermediate values, so the result is either 8px or 0px, never something in between. Strip that multiplier out, resize the window, and the radius will visibly morph as the viewport approaches the component's width.
So why not use a @media query instead? Frank Yan, the developer behind Facebook's choice, explains that the technique isn't a media query comparing the viewport to a fixed width — it works more like a container query, comparing the viewport to the element's own variable width.
Naman Goel adds that this makes it a more general-purpose solution, since it needs no knowledge of the card's size, whereas a media query would depend on the card's width.
The approach is known as the "Fab Four" Technique, which also has applications in email.



