Sub topic 6
Rounding corners
This chapter assumes you can apply Tailwind color and border utilities (border, border-slate-200) and know how the CSS box model works. It covers the rounded utilities, which set the CSS border-radius property.
The radius scale
Each rounded-* class maps to a fixed radius on all four corners. The scale below uses Tailwind v4 names.
| Class | Radius |
|---|---|
| `rounded-none` | 0 |
| `rounded-xs` | 0.125rem |
| `rounded-sm` | 0.25rem |
| `rounded-md` | 0.375rem |
| `rounded-lg` | 0.5rem |
| `rounded-xl` | 0.75rem |
| `rounded-2xl` | 1rem |
| `rounded-3xl` | 1.5rem |
| `rounded-full` | 9999px |
Rounding all corners
Radius applies to the background, the border, and any ring or shadow on the element. A single class is usually enough.
<button class="rounded-md border border-slate-300 bg-white px-4 py-2">
Cancel
</button>
<span class="rounded-full bg-emerald-100 px-3 py-1 text-emerald-800">
Active
</span>rounded-full gives a circle on a square element and a pill shape on a wide one. This works because the radius is so large that the browser clamps it to half the shorter side.
Rounding sides and single corners
Add a side or corner abbreviation between rounded and the size.
- Sides:
rounded-t-*,rounded-r-*,rounded-b-*,rounded-l-* - Corners:
rounded-tl-*,rounded-tr-*,rounded-br-*,rounded-bl-*
Sides round the two corners on that side. Use them when elements sit flush against each other, such as a button group.
<div class="inline-flex">
<button class="rounded-l-lg border border-slate-300 px-4 py-2">Day</button>
<button class="border-y border-slate-300 px-4 py-2">Week</button>
<button class="rounded-r-lg border border-slate-300 px-4 py-2">Month</button>
</div>For layouts that must flip in right-to-left languages, use the logical forms rounded-s-* (start) and rounded-e-* (end). Corner variants such as rounded-ss-* and rounded-ee-* also exist.
Clipping children to the radius
A rounded parent does not round its children. A square image inside a rounded card pokes out past the corners. Add overflow-hidden to the parent so the content is clipped to the curve.
<div class="overflow-hidden rounded-xl border border-slate-200 bg-white">
<img src="cover.jpg" alt="Mountain lake" class="h-40 w-full object-cover" />
<p class="p-4">Lake trip</p>
</div>Without overflow-hidden, you would have to put rounded-t-xl on the image instead. Clipping is simpler, but it also hides anything meant to overflow the card, such as dropdowns and focus rings on inner elements.
Common errors
- Mixing sizes without a plan. Pick one radius for related components, for example
rounded-lgfor cards and inputs, androunded-fullonly for avatars and badges. - Rounding an inner element to the same radius as its parent. With padding, the inner radius should be smaller. Nested elements with equal radii look uneven.
- Expecting radius on
dividelines. Dividers are borders on children, so round the parent and addoverflow-hidden. - Using
rounded-fullon a tall box. You get a pill, not a circle. Give the element equal width and height, such assize-10, for a circle.
Exercise
A card has rounded-xl and contains a full-width image at the top. The image's square corners show outside the card's curved corners. Name two ways to fix it.
Show answer
Add overflow-hidden to the card so the image is clipped to the radius. Alternatively, add rounded-t-xl to the image so its top corners match the card.