Sub topic 6
Borders, rounded corners, and shadows
This chapter assumes you know the CSS box model, can read the spacing and color utilities from earlier chapters, and have a working Tailwind setup. Here you will give elements edges, rounded corners, and depth using utility classes.
Borders
Tailwind splits a border into width, color, and style. The border class sets a 1px width, and the border-color utilities set the color.
<div class="border border-slate-300 p-4">Default border</div>
<div class="border-2 border-indigo-500 p-4">2px border</div>
<div class="border-b border-slate-200 p-4">Bottom edge only</div>Width utilities follow the same pattern as spacing utilities. Add a side letter to limit the border to one edge: border-t, border-r, border-b, border-l. Use border-x and border-y for pairs. Numbers set the width in pixels: border-2, border-4, border-8.
Without a color utility, the border uses the default border color. This default changed between Tailwind versions. In v4 it is currentcolor, so you should name a color explicitly.
Dividers
To draw lines between siblings, use divide-y on the parent instead of putting a border on each child.
<ul class="divide-y divide-slate-200">
<li class="py-2">First</li>
<li class="py-2">Second</li>
<li class="py-2">Third</li>
</ul>Focus rings
A ring is an outline drawn with a box shadow, so it does not change the element's layout size. You used focus:ring-2 in the card example. Rings are the usual way to show keyboard focus.
Rounded corners
The rounded family sets border-radius. The size names run from small to fully round.
| Class | Effect |
|---|---|
| `rounded-sm` | Slight rounding |
| `rounded` | Small default rounding |
| `rounded-lg` | Larger rounding, common for buttons |
| `rounded-xl` | Card-style rounding |
| `rounded-full` | Circles and pill shapes |
You can round single corners or sides with rounded-t-lg (top two corners) or rounded-tl-lg (top-left only).
<img class="size-16 rounded-full" src="/avatar.png" alt="User avatar">
<span class="rounded-full bg-green-100 px-3 py-1 text-green-800">Active</span>On a square element, rounded-full makes a circle. On a wider element it makes a pill.
Shadows
The shadow utilities add a box shadow. They scale from subtle to dramatic.
<div class="rounded-xl bg-white p-6 shadow-sm">Subtle</div>
<div class="rounded-xl bg-white p-6 shadow-md">Medium</div>
<div class="rounded-xl bg-white p-6 shadow-xl">Pronounced</div>Larger shadows suggest the element is higher above the page. Use this to separate layers: cards get shadow-md, dropdowns and modals get shadow-lg or shadow-xl. Use shadow-none to remove a shadow, for example at a larger breakpoint.
How the pieces combine
A typical card uses all three utilities together. Each one controls a different part of the look, and none of them depends on the others.
<div class="rounded-xl border border-slate-200 bg-white p-6 shadow-md hover:shadow-lg">
<h2 class="text-lg font-semibold">Plan</h2>
<p class="mt-2 text-slate-600">Hover to lift the card.</p>
</div>The hover:shadow-lg prefix is a state variant. The next chapters cover variants in detail.
Common errors
- Border color missing. A border with no color class may look black or match the text color, depending on your Tailwind version. Always pair
borderwith a color. - Rounding hidden by children. A child with a background can cover the parent's rounded corners. Add
overflow-hiddento the parent. - Shadows invisible on dark backgrounds. Dark shadows disappear against dark surfaces. In dark mode, rely on a border or a lighter surface color instead.
- Border shifts layout. Adding a border on hover changes the element's size. Use a ring, or keep a transparent border, such as
border border-transparent hover:border-indigo-500.
Exercise
A card has rounded-xl and contains an image at the top with no rounding. The image's square corners stick out past the card's corners. Which single class fixes this, and on which element?
Show answer
Add overflow-hidden to the card (the parent). It clips the child image to the parent's rounded corners. Alternatively, put rounded-t-xl on the image itself.
Exercise
Write the classes for a pill-shaped badge with a 1px indigo border, horizontal padding of 12px, and vertical padding of 4px.
Show answer
rounded-full border border-indigo-500 px-3 py-1