Sub topic 4
Border width and style
This chapter covers the two properties that decide whether a border appears and what it looks like: width and style. It assumes you know the CSS box model, have used Tailwind utility classes, and have a project or playground to try the examples in. Color comes from the previous chapters, so border colors are only mentioned where they affect the result.
What the `border` class sets
In plain CSS, a border shows only when width, style, and color are all usable. Tailwind splits these across classes and fills in defaults through Preflight, its base stylesheet. Preflight applies these rules to every element:
border-width: 0, so no element has a visible border by default.border-style: solid, so any border you turn on is solid.- A default border color. In Tailwind v3 this is
gray-200. In v4 it iscurrentColor, the element's own text color.
The class border therefore changes only the width, to 1px. Because Preflight already supplies the solid style, one class gives you a visible line:
<div class="border p-4">A 1px solid border</div>In v3 the line is light gray. In v4 it matches the text color. If your border looks different after an upgrade, this default change is the usual cause. Setting the color explicitly, for example border-slate-300, makes the result the same in both versions.
Width utilities
Width utilities use a short fixed scale:
| Class | Width |
|---|---|
| `border-0` | 0px |
| `border` | 1px |
| `border-2` | 2px |
| `border-4` | 4px |
| `border-8` | 8px |
The names are not a uniform scale. The 1px default has no suffix, and border-1 does not exist in v3. Tailwind v4 accepts any integer, so border-3 produces 3px. In v3 you need an arbitrary value, covered below.
<div class="flex gap-4">
<div class="border-0 border-slate-400 p-4">0</div>
<div class="border border-slate-400 p-4">1</div>
<div class="border-2 border-slate-400 p-4">2</div>
<div class="border-4 border-slate-400 p-4">4</div>
<div class="border-8 border-slate-400 p-4">8</div>
</div>Preflight sets box-sizing: border-box on all elements. When you give an element a fixed width such as w-48, the border is drawn inside that width. Making the border thicker shrinks the content area and does not grow the element.
Arbitrary widths
For a width outside the scale, put a length in square brackets:
<div class="border-[3px] border-slate-400 p-4">3px border</div>
<div class="border-[0.5px] border-slate-400 p-4">Hairline border</div>Arbitrary values are covered in their own chapter. The point here is that any CSS length works.
Style utilities
Style utilities map directly to the CSS border-style values:
| Class | CSS value | Effect |
|---|---|---|
| `border-solid` | `solid` | A continuous line |
| `border-dashed` | `dashed` | A series of dashes |
| `border-dotted` | `dotted` | A series of dots |
| `border-double` | `double` | Two parallel lines |
| `border-hidden` | `hidden` | No border, and wins in collapsed tables |
| `border-none` | `none` | No border |
<div class="grid gap-3">
<div class="border-2 border-solid border-slate-400 p-3">solid</div>
<div class="border-2 border-dashed border-slate-400 p-3">dashed</div>
<div class="border-2 border-dotted border-slate-400 p-3">dotted</div>
<div class="border-4 border-double border-slate-400 p-3">double</div>
</div>You rarely need border-solid because Preflight already sets it. It is useful when you must override another style at a breakpoint or state, such as md:border-solid on an element that is dashed on small screens.
Why `border-double` needs a thick border
A double border is two lines with a gap between them, drawn inside the border width. A 1px or 2px border has no room for that, so the browser draws it as a single line. Use at least border-4, as in the example above, to see two lines.
`border-0` versus `border-none`
These two classes both remove a visible border, but they change different properties.
border-0sets the width to 0. The style and color stay as they were.border-nonesets the style tonone. The width is set to 0 as the style computes to none, so nothing is drawn.border-hiddenbehaves likenonefor most elements. In a table with collapsed borders,hiddentakes priority over every conflicting border, whilenoneloses to any other style.
Use border-0 to undo a width in a responsive or stateful override, for example border md:border-0. Use border-none or border-hidden when you need the style itself to be none or hidden, such as when resetting a border on a table cell.
<table class="border-collapse border border-slate-300">
<tr>
<td class="border border-slate-300 p-2">A</td>
<td class="border-hidden p-2">B (shared edge suppressed)</td>
</tr>
</table>Choosing the right class
The diagram summarizes how the three properties combine.
Widths with other utilities
Width and style work with the variants you will meet later. A common pattern is to change a border on hover:
<button class="border border-slate-300 px-4 py-2 hover:border-2 hover:border-indigo-500">
Hover me
</button>This button has a layout problem. Going from 1px to 2px makes the button 2px larger in each dimension, so neighboring content shifts when the pointer enters. There are two common fixes.
- Start with the larger width and a transparent border, then change only the color:
border-2 border-transparent hover:border-indigo-500. - Keep the width fixed and add a ring on hover. A ring is drawn with a shadow, so it does not affect layout. Rings are covered in a later chapter.
<button class="border-2 border-transparent bg-slate-100 px-4 py-2 hover:border-indigo-500">
Stable layout
</button>Common errors
- No border appears. You set a color or style but no width. Preflight sets the width to 0, so
border-dashed border-slate-300alone draws nothing. Addborderorborder-2. - The border color changed after upgrading to v4. The default changed from
gray-200tocurrentColor. Add an explicit color class. border-doublelooks like a single line. The width is under 3px. Useborder-4or larger.border-1does nothing in v3. The class is not in the v3 scale. Useborder, orborder-[1px]if you want to be explicit.- Layout jumps when a border changes width. Keep the width constant and change the color, or use a ring.
- Dashed or dotted lines look uneven at corners. The browser decides where dashes start and end. This is normal CSS behavior and cannot be tuned with Tailwind classes. Combined with rounded corners, dashes may look uneven.
Putting width and style together
A dashed upload area is a typical use of these classes. It combines a width, a style, a color, and a rounded corner:
<div class="rounded-lg border-2 border-dashed border-slate-300 p-8 text-center text-slate-600">
Drop files here
</div>A thicker, solid accent works differently. It marks the content with a heavy edge and a light frame:
<div class="border border-slate-200 border-l-4 border-l-indigo-500 bg-white p-4">
Note with an accent edge
</div>The second example uses a per-side width, so treat it as a preview of the next chapter.
Exercise
A teammate writes <div class="border-dashed border-slate-400 p-4"> and sees no border. What is missing, and what is the smallest change that fixes it? Also, which change would you make if they then want the dashes to stay visually the same when the pointer hovers, but the border to grow thicker without moving neighboring elements?
Show answer
The width is missing. Preflight sets border-width: 0, so a style and color alone draw nothing. Adding border (1px) or border-2 fixes it. For the hover thickness, a changing border width alters the element's size and shifts neighbors. Instead, start with the thicker width and a transparent color, such as border-2 border-dashed border-transparent hover:border-slate-400, or keep the width fixed and add a ring on hover.
Exercise
You apply border-double border-slate-500 plus border-2 and the border looks like one solid line. Why, and what change shows two lines?
Show answer
A double border needs room for two lines and a gap, and 2px is not enough, so the browser draws one line. Use border-4 or wider, for example border-4 border-double border-slate-500.