Sub topic 6
Borders, rounded corners, and shadows
This chapter covers the utilities that give elements edges and depth: borders, outlines and rings, border radius, and shadows. It assumes you know the CSS box model, can read the spacing and color utilities from earlier chapters, and have a working Tailwind setup. Borders matter more than their weight in the outline suggests, because they interact with sizing, color, and state variants.
How borders work in Tailwind
A plain border class sets a width of 1px and a solid style. It also uses the current border color. In Tailwind v4 that color is currentColor, so the border takes the text color unless you override it. In Tailwind v3 the default was a light gray. If you migrate between versions, check any bare border classes.
<div class="border border-slate-300 p-4">A 1px slate border on all sides.</div>Width utilities use a small fixed scale.
| Class | Width |
|---|---|
| `border` | 1px |
| `border-0` | 0px |
| `border-2` | 2px |
| `border-4` | 4px |
| `border-8` | 8px |
Each width has per-side forms. Use border-t, border-r, border-b, and border-l for single sides. Use border-x and border-y for pairs. Add a number to set the width, as in border-b-2.
<h2 class="border-b-2 border-indigo-500 pb-2 text-xl font-semibold">
Section heading with an underline
</h2>Border color and style
Border colors use the same palette as other color utilities, such as border-slate-200 or border-indigo-600. You can add opacity with a slash, as in border-black/10. Per-side colors exist too, for example border-t-red-500.
Style utilities are border-solid, border-dashed, border-dotted, border-double, and border-none. Setting a width alone does not draw anything if the style is none. In Tailwind, border-2 also sets border-style: solid through its base layer, so you rarely need border-solid.
<div class="rounded-lg border-2 border-dashed border-slate-400 p-8 text-center text-slate-500">
Drop files here
</div>Dividers between children
Use divide-y or divide-x on a parent to draw borders between its children, without a border before the first child or after the last. Color them with divide-slate-200.
<ul class="divide-y divide-slate-200">
<li class="py-3">First item</li>
<li class="py-3">Second item</li>
<li class="py-3">Third item</li>
</ul>This is cleaner than adding border-b to each item and then removing it from the last one.
Borders and layout size
Under Tailwind's base styles, every element uses box-sizing: border-box. A border therefore sits inside the element's declared width and height. An element with w-64 border-4 is still 16rem wide. The content area shrinks instead. If a layout shifts when you add a border on hover, the border is growing into the content box. The fix is to reserve the space with a transparent border from the start.
<a href="/docs" class="border-b-2 border-transparent hover:border-indigo-600">Docs</a>Outlines and rings
An outline is drawn outside the border box and does not affect layout. Tailwind offers outline, outline-2, outline-offset-2, and color utilities such as outline-indigo-500. Use outline-none carefully, since it removes the focus indicator that keyboard users depend on. If you remove the default focus style, replace it.
A ring is built from a box shadow with no blur. ring-2 draws a 2px ring around the element, and ring-indigo-500 colors it. Rings are the common choice for focus styles.
<button class="rounded-lg bg-indigo-600 px-4 py-2 text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
Save
</button>The ring-offset-2 class adds a gap between the element and the ring. In Tailwind v4, a bare ring is 1px wide (it was 3px in v3), so write the width explicitly. Many projects use focus-visible: instead of focus:, so the ring shows for keyboard focus but not for mouse clicks.
Rounded corners
The rounded family sets border-radius. Sizes run from sharp to fully round.
| Class | Effect |
|---|---|
| `rounded-none` | No rounding |
| `rounded-sm` | Slight rounding |
| `rounded` | Small rounding (naming differs between v3 and v4, see the note below) |
| `rounded-md` | Medium |
| `rounded-lg` | Large |
| `rounded-xl` | Extra large |
| `rounded-2xl` | Larger still |
| `rounded-full` | Pill or circle |
Corners and sides
Prefix the radius with a side or a corner. rounded-t-lg rounds the top two corners, and rounded-l-lg, rounded-r-lg, and rounded-b-lg work the same way. For one corner, use rounded-tl-lg, rounded-tr-lg, rounded-br-lg, or rounded-bl-lg.
<div class="overflow-hidden rounded-xl border border-slate-200">
<div class="bg-slate-100 p-4 font-semibold">Header</div>
<div class="p-4">Body content</div>
</div>The overflow-hidden class is the common gotcha here. A child with its own background paints over the parent's rounded corners, because the corners only clip the parent's own background and border. Adding overflow-hidden to the parent clips the children to the curve. The cost is that anything meant to stick out, such as a dropdown or a focus ring, is clipped too.
Circles and pills
rounded-full uses a very large radius. On a square element it gives a circle. On a rectangle it gives a pill with fully round ends.
<img src="/avatar.jpg" alt="User avatar" class="size-12 rounded-full object-cover">
<span class="rounded-full bg-green-100 px-3 py-1 text-sm text-green-800">Active</span>The size-12 utility sets width and height together. The object-cover class keeps a non-square photo from stretching inside the circle.
Shadows
Box shadows suggest elevation. The scale runs from shadow-sm through shadow-md, shadow-lg, shadow-xl, and shadow-2xl, with shadow-none to remove one. Larger shadows are softer and spread farther, which reads as an element sitting higher above the page.
<div class="grid grid-cols-3 gap-6 bg-slate-50 p-8">
<div class="rounded-lg bg-white p-4 shadow-sm">Low</div>
<div class="rounded-lg bg-white p-4 shadow-md">Medium</div>
<div class="rounded-lg bg-white p-4 shadow-xl">High</div>
</div>Shadow color
Shadows are black at low opacity by default. Tint them with shadow-indigo-500/30. A tinted shadow under a colored button looks more natural than a gray one.
<button class="rounded-lg bg-indigo-600 px-4 py-2 text-white shadow-lg shadow-indigo-500/30">
Upgrade
</button>The color utility only works when a shadow size is also present. shadow-indigo-500/30 alone sets a color variable, but no shadow is drawn.
Inset shadows and drop shadows
Use inset-shadow-sm in v4, or shadow-inner in v3, for a pressed-in effect such as a text input well. For non-rectangular content such as a transparent PNG or an SVG, a box shadow follows the rectangle, not the shape. Use drop-shadow-md, which applies a CSS filter and follows the visible pixels.
| Utility | Follows | Typical use |
|---|---|---|
| `shadow-*` | The element's box, including its radius | Cards, buttons, menus |
| `drop-shadow-*` | The visible shape, including transparency | Icons, cut-out images |
Combining the pieces
Shadows, borders, and rings can be combined. Tailwind composes box-shadow-based utilities (shadow and ring) through CSS variables, so a ring and a shadow on the same element both show.
<div class="rounded-xl border border-slate-200 bg-white p-6 shadow-md transition hover:shadow-lg hover:border-slate-300">
<h3 class="font-semibold text-slate-900">Hoverable card</h3>
<p class="mt-1 text-slate-600">The shadow and border darken on hover.</p>
</div>The transition class animates the change between the two states. Without it, the shadow jumps.
Common errors
- A border has the wrong color. A bare
borderusescurrentColorin v4. Always add a color class such asborder-slate-200. - Layout jumps on hover. The hover state adds a border width. Reserve the space with
border-transparentin the base state. - Children poke through rounded corners. Add
overflow-hiddento the parent, then check that nothing needs to overflow. - The shadow color class has no effect. Add a size such as
shadow-mdbesideshadow-indigo-500/30. - Focus is invisible. Removing the outline with
outline-nonewithout adding a ring removes the keyboard cue. - A shadow has square edges on a transparent image. Use
drop-shadow-*. - Dynamic radius or shadow names do not work. Names such as `
rounded-${size}` are never detected, as covered in the chapter on dynamic class names. Write complete class names.
Practical guidance
Keep the set of choices small. A project usually needs two or three radius values, two or three shadow levels, and one border color for neutral surfaces. Decide these once, perhaps as theme tokens, and reuse them. Mixed radii on neighboring elements look accidental. When nested elements both have rounded corners, the inner radius should be smaller than the outer radius by roughly the padding between them, so the curves look parallel.
Exercise
A card uses rounded-xl with a header that has bg-slate-100. The header's square corners show past the card's curved top corners. What is the smallest fix, and what is one side effect to watch for?
Show answer
Add overflow-hidden to the card so the header is clipped to the rounded shape. The side effect is that anything meant to extend outside the card, such as a dropdown menu or an outer focus ring on a child, is also clipped.
Exercise
A navigation link gets hover:border-b-2 hover:border-indigo-600, and the links below it shift down by 2px on hover. Write the fix.
Show answer
Reserve the space in the default state with a transparent border: border-b-2 border-transparent hover:border-indigo-600. The border width stays the same, so only the color changes on hover and nothing moves.
Exercise
You add shadow-red-500/40 to a button and see no shadow. Why, and how do you fix it?
Show answer
The color utility only sets the shadow color. No shadow size is applied. Add a size utility such as shadow-lg, giving shadow-lg shadow-red-500/40.