Sub topic 11
Corner radius with logical corners
This chapter assumes you know the block and inline axes, the start and end sides, and the two-value shorthands from the earlier chapters. You should also be comfortable with border-radius in its physical form.
The problem: asymmetric corners
Most rounded boxes use one radius on all four corners, such as border-radius: 8px. That rule is already direction-neutral, so you don't need to change it.
The trouble starts when only some corners are rounded. Common cases are a tab with rounded top corners, a speech bubble with one square corner, and a button attached to the end of a text input. Here is a chat bubble written with physical values:
.bubble {
border-radius: 1rem 1rem 1rem 0;
}The four values run top-left, top-right, bottom-right, bottom-left. The square corner is the bottom left. In an English interface that corner points at a speaker on the left. In an Arabic interface the speaker is on the right, and the square corner now points the wrong way. The same problem appears in vertical writing modes, where "bottom left" has no fixed relationship to the text.
The four logical corner properties
CSS has no logical version of the border-radius shorthand. Instead, there are four longhand properties, one per corner:
border-start-start-radiusborder-start-end-radiusborder-end-start-radiusborder-end-end-radius
Each name is border- plus two flow-relative words plus -radius. The first word names the block side and the second names the inline side. So border-start-end-radius is the corner at the block start and the inline end.
Block start is the edge where lines of text begin, such as the top in English. Inline end is the edge where a line of text ends, such as the right in English.
This order is the reverse of what many people expect. In the physical shorthand you think "top, then left". In the logical names the block side comes first. Learn this order once. It is the usual source of mistakes with these properties.
How the corners map
The physical corner that each property selects depends on writing-mode and direction:
| Property | `horizontal-tb`, LTR | `horizontal-tb`, RTL | `vertical-rl`, LTR |
|---|---|---|---|
| `border-start-start-radius` | top left | top right | top right |
| `border-start-end-radius` | top right | top left | bottom right |
| `border-end-start-radius` | bottom left | bottom right | top left |
| `border-end-end-radius` | bottom right | bottom left | bottom left |
The last column follows from the axes. In vertical-rl, blocks stack from right to left, so block start is the right edge. The inline direction runs top to bottom when direction is LTR, so inline start is the top edge. The corner at block start and inline start is therefore the top right.
Rewriting the chat bubble
The bubble should have a square corner at the block end and the inline start. That corner touches the speaker's side of the box, whichever side that is.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Logical corners</title>
<style>
.bubble {
max-inline-size: 30ch;
padding: 0.75rem 1rem;
background: #dbeafe;
border-radius: 1rem;
border-end-start-radius: 0;
}
</style>
</head>
<body>
<p class="bubble" dir="ltr" lang="en">Hello, are you there?</p>
<p class="bubble" dir="rtl" lang="ar">مرحبا، هل أنت هنا؟</p>
</body>
</html>The first line sets all four corners to 1rem. The second line overrides one corner. In the LTR paragraph the square corner is at the bottom left. In the RTL paragraph it is at the bottom right. No second rule or [dir=rtl] selector is needed.
Order matters here. Both declarations set the same corner, so the later one wins by the normal cascade. Put the shorthand first and the logical longhand after it. If you reverse them, the shorthand resets the corner and your override is lost.
Rounding one side
There are no border-inline-start-radius or border-block-end-radius properties. To round a whole side, write the two corner longhands that make up that side.
This tab has rounded corners on its block-start side and square corners on its block-end side:
.tab {
border-start-start-radius: 0.5rem;
border-start-end-radius: 0.5rem;
border-end-start-radius: 0;
border-end-end-radius: 0;
}Both rounded corners share the word start in first position. A side is always the two properties that share one word in the same position. The block-start side is start-start and start-end. The inline-end side is start-end and end-end.
An input group is a second case. The text input should be square at its inline end and the button square at its inline start, so they join cleanly:
.input {
border-start-end-radius: 0;
border-end-end-radius: 0;
}
.button {
border-start-start-radius: 0;
border-end-start-radius: 0;
}In LTR the button sits to the right of the input. In RTL it sits to the left. The joined edges flip with it, provided the layout also flows with the direction. A flex row does this automatically.
Radius values
Each logical radius property takes the same values as the matching physical longhand. You can use a length, a percentage, or two values for an elliptical corner:
.pill-end {
border-start-end-radius: 50%;
border-end-end-radius: 50%;
}
.leaf {
border-start-start-radius: 2rem 1rem;
}Percentages resolve against the dimensions of the border box, as they do with border-radius. If you use elliptical two-value radii in a vertical writing mode, check the result in a browser. Confirm how the two values map to the axes in your target browsers instead of assuming they follow the flow.
For a full pill shape on a button, a large fixed length such as 999px is still the common approach. It works because the browser scales oversized radii down to fit.
Where the logical properties do not help
- Symmetric rounding.
border-radius: 8pxhas the same result in every mode. Replacing it with four longhands only adds code. - Physical shapes. If a corner must stay at the top left because it matches an image or a drawn shape, use the physical property. The chapter on when to keep physical values covers this.
- Shorthand habits. Do not expect
border-radius: start endor similar to work. Theborder-radiusshorthand is always physical, and its values go top left, top right, bottom right, bottom left.
Fallbacks and support
The four logical corner properties are supported in current versions of the major browsers. In an older browser that does not recognize them, the declaration is ignored. If your audience includes those browsers, give a physical fallback first and reset it inside @supports, the same pattern used for margins:
.bubble {
border-radius: 1rem;
border-bottom-left-radius: 0;
}
@supports (border-end-start-radius: 0) {
.bubble {
border-bottom-left-radius: 1rem;
border-end-start-radius: 0;
}
}The reset line is needed. Without it, the physical border-bottom-left-radius: 0 would still apply in a supporting browser, and in RTL both the bottom-left and bottom-right corners would be square. Setting the bottom left back to 1rem inside @supports leaves only the logical property in control.
Testing
To check corner rules, render each element in several modes and look at which corner is square:
- Add
dir="rtl"to the element or to<html>. The square corner should move to the opposite side. - Add
style="writing-mode: vertical-rl"and compare against the table above. - Toggle the
directionproperty in browser developer tools, which is faster than editing the markup.
Exercise
A tab bar is used in English and in Hebrew (right-to-left). Each tab should have rounded corners on its block-start side only, with a radius of 6px. Which two logical properties do you set to 6px, and which physical corners do they select in each language?
Show answer
Set border-start-start-radius and border-start-end-radius to 6px. In horizontal-tb text, block start is the top in both languages. In English (LTR), start-start is the top left and start-end is the top right. In Hebrew (RTL), start-start is the top right and start-end is the top left. Because both top corners are rounded, the visible result is identical, so this pair works in either direction.
Exercise
A search field is followed by a button in a flex row. You want the button's inline-start corners to be square so it joins the field. Which two properties do you set to 0 on the button? In vertical-rl text with LTR direction, which physical edge does that side map to?
Show answer
Set border-start-start-radius and border-end-start-radius to 0. Both have "start" as their second word, which selects the inline-start side. In vertical-rl with LTR direction, the inline axis runs top to bottom, so inline start is the top edge.