Sub topic 5
Borders on individual sides
This chapter assumes you know the basics of Tailwind border width, style, and color utilities, and that you have a working Tailwind project or playground. The examples work in Tailwind v3 and v4 unless noted.
Why per-side borders matter
A border class applies to all four sides of an element. Many interface patterns need only one or two sides: a divider under a heading, an accent bar beside an alert, an underline beneath the active tab. Tailwind provides side-specific utilities so you don't need custom CSS for these.
Each side has its own prefix:
| Prefix | Side affected | CSS property |
|---|---|---|
| `border-t` | Top | `border-top-width` |
| `border-r` | Right | `border-right-width` |
| `border-b` | Bottom | `border-bottom-width` |
| `border-l` | Left | `border-left-width` |
| `border-x` | Left and right | both horizontal widths |
| `border-y` | Top and bottom | both vertical widths |
Tailwind v3.3 and later also provide logical-property versions: border-s (start) and border-e (end). These follow the text direction, so they flip sides in right-to-left languages.
Setting width on one side
Side utilities accept the same width scale as border. Without a number, the width is 1px. With a number, it is that many pixels: 0, 2, 4, or 8.
<div class="border-b-2 border-slate-300 p-4">
Heading with a 2px bottom edge
</div>The element has a visible bottom border and no other borders. Notice that this example sets no border-solid class. Tailwind's base styles (called Preflight) set border-style: solid and a default border color on every element. That is why a lone border-b-2 is enough to draw a line.
You can also remove a side. This is useful when a base class sets all sides and a variant or later class needs to turn one off:
<div class="border border-t-0 border-slate-300 p-4">
Border on three sides, none on top
</div>border-t-0 sets the top width to zero while the other sides keep the 1px width from border.
Setting color on one side
Color utilities follow the same pattern. border-t-red-500 colors only the top edge, and border-x-slate-200 colors left and right together.
<div class="rounded-lg border-2 border-dashed border-slate-300 border-b-emerald-500 p-4">
Dashed border with a green bottom edge
</div>Here border-2 sets the width on every side, border-dashed sets the style on every side, and border-slate-300 sets the color on every side. Then border-b-emerald-500 overrides only the bottom color.
The opacity modifier works on side colors too, for example border-b-emerald-500/50.
How overrides are resolved
The order of classes in the class attribute does not decide which utility wins. Tailwind generates its CSS in a fixed order, and the side-specific color utilities are placed after the all-sides color utilities. So border-b-emerald-500 beats border-slate-300 whichever you write first.
If two classes target the same property with equal specificity, the one later in the generated stylesheet wins. When a result surprises you, check the generated order rather than your class order.
Style applies to all sides
There are no per-side style utilities. border-dashed, border-dotted, border-double, border-solid, and border-none all affect every side. Per-side width and color exist, but style does not.
This matters in one case. If you want a dashed bottom edge and no other borders, set the width on the bottom only:
<div class="border-b-2 border-dashed border-slate-400 p-4">
Only the bottom edge is drawn, and it is dashed
</div>The other three sides are dashed too, but they have zero width, so you never see them.
Building common patterns
An accent bar on an alert
A thick left border with a tinted background is a common notice style:
<div class="rounded-r-md border-l-4 border-amber-500 bg-amber-50 p-4 text-amber-900">
Your trial ends in three days.
</div>rounded-r-md rounds only the right corners. Rounding the left corners of an element with a thick left border produces a curved, tapering bar, which usually looks unintended. Corner utilities are covered in the next chapter section on rounding, so here the point is only that border side and corner choice should agree.
Tabs with an active underline
Give every tab a transparent bottom border so the layout does not shift when one becomes active:
<nav class="flex gap-4 border-b border-slate-200">
<a href="#" class="border-b-2 border-transparent px-1 py-2 text-slate-600 hover:border-slate-300">Overview</a>
<a href="#" class="border-b-2 border-indigo-600 px-1 py-2 font-medium text-indigo-600">Activity</a>
<a href="#" class="border-b-2 border-transparent px-1 py-2 text-slate-600 hover:border-slate-300">Settings</a>
</nav>Each tab always has a 2px bottom border. Only its color changes. If you added the border only to the active tab, that tab would grow 2px taller and push its neighbors out of alignment.
Separating a footer
A single border-t is the lightest way to separate a footer from the content above it:
<footer class="mt-8 border-t border-slate-200 pt-4 text-sm text-slate-500">
Last updated today
</footer>Axis utilities
border-x and border-y set two opposite sides at once. They exist for width and color.
<div class="border-y-2 border-x-0 border-y-slate-400 p-4">
Lines above and below, nothing at the sides
</div>Because border-x-0 and border-y-2 write to different sides, they do not conflict. In the generated CSS, the axis utilities come before the single-side ones. So border-x-4 border-l-0 gives you a right border only.
Combining with state variants
Side utilities accept variants like any other class. A common use is an underline that appears on hover:
<a href="#" class="border-b-2 border-transparent hover:border-indigo-500">
Hover me
</a>The width stays constant and only the color changes, which avoids layout shift. If you instead wrote hover:border-b-2 with no base width, the element would gain 2px of height on hover and surrounding content would jump.
Common errors
- No border appears. A color alone does not draw anything. Make sure a width utility such as
border-borborder-b-2is present for that side. - A side shows the wrong color. Look for a default or inherited color. Preflight sets the border color to the theme's default gray, so a side without its own color utility uses that.
- Content shifts on hover or selection. Reserve the width in the base state and change only the color. Use
border-transparentas the resting color. - Expecting per-side style. Tailwind has no
border-b-dashed. Use a width on one side and a style on the element, as shown earlier. - Left and right swapped in right-to-left pages. Use
border-sandborder-ewhen the layout should mirror with text direction.
Diagram: which classes target which sides
Read the diagram top to bottom. A utility higher in the tree covers every side beneath it, and a lower utility is more specific and overrides it.
Exercises
Exercise
You want a card with a 1px gray border on the left, right, and bottom, and no border on top. Which two classes give you a 1px border on all sides and then remove the top?
Show answer
Use border and border-t-0. The first sets 1px on all four sides and the second sets the top width to zero.
Exercise
A navigation link gets border-b-2 border-indigo-600 only when it is active, and the other links jump down by 2px. Describe a fix.
Show answer
Give every link border-b-2 border-transparent as its resting state, then use border-indigo-600 instead of border-transparent for the active link. The width is then constant and only the color changes, so nothing shifts.
Exercise
Will border-b-2 border-b-dashed produce a dashed bottom line? Why or why not?
Show answer
No. Tailwind has no per-side style utilities, so border-b-dashed does not exist and is ignored. Use border-b-2 border-dashed instead. The style applies to all sides, but only the bottom has a width, so only the bottom is visible.