Open any app on your phone. Its buttons and cards almost always have rounded corners, and many have a thin border. Those two things are what you set in this lesson.
A border is the line around an element, and rounded means its corners are rounded off. In Tailwind they are separate classes: border adds the line, border-gray-300 colours it, rounded-xl rounds the corners. Setting them is like choosing a photo frame: you choose how thick the frame is, its colour, and its corners (sharp or soft). In Tailwind, each of those choices is one class.
A card with a border
Here is the card from the exercise:
<div id="card" class="border border-gray-300 rounded-xl p-4">
Card with a border
</div>
| Class | The CSS Tailwind writes | The result |
|---|---|---|
border |
border-width: 1px and border-style: solid |
a 1px line |
border-gray-300 |
border-color: var(--color-gray-300) |
light grey |
rounded-xl |
border-radius: var(--radius-xl) |
0.75rem = 12px |
p-4 |
padding: calc(var(--spacing) * 4) |
16px |
borderadds the line. Without this class there is no line, because Tailwind's preflight sets the line width of every element to 0.border-gray-300only gives the line a colour. In Tailwind v4,borderwithout a colour class uses the element's text colour (currentColor), usually black. So set the colour yourself.rounded-xlrounds all four corners by 12px.p-4adds 16px of room inside, so the text doesn't touch the line.
Line width and sides
| Class | CSS |
|---|---|
border |
border-width: 1px |
border-2 |
border-width: 2px |
border-4 |
border-width: 4px |
border-8 |
border-width: 8px |
border-t, border-r, border-b, border-l |
a 1px line on the top, right, bottom, or left only |
border-b-2 |
a 2px bottom line |
border-x, border-y |
left and right, top and bottom |
The number in border-2 is pixels, not 4px steps as in the spacing classes. border-b makes border-bottom-width: 1px, useful for a line under a heading.
The rounded scale
| Class | border-radius |
|---|---|
rounded-none |
0 |
rounded-xs |
2px |
rounded-sm |
4px |
rounded-md |
6px |
rounded-lg |
8px |
rounded-xl |
12px |
rounded-2xl |
16px |
rounded-3xl |
24px |
rounded-full |
as large as possible |
For some corners only: rounded-t-lg (the two top corners), rounded-b-lg (the two bottom corners), rounded-tl-lg (top left), rounded-br-md (bottom right). Be careful with v3 tutorials. In v3, rounded-sm is 2px. In v4, 2px has the new name rounded-xs, and rounded-sm became 4px. From rounded-md up, the sizes are the same in both versions.
rounded-full: pills and circles
Before you continue, guess: a 192 × 48px button gets rounded-full. Does it become an ellipse, or a pill shape?
rounded-full makes border-radius: calc(infinity * 1px), which is a very large number. When a corner radius is bigger than the box, the browser shrinks it until it fits, which is half the shortest side. The result:
- A 96 × 96px square (
size-24 rounded-full) becomes a circle: each radius shrinks to 48px. - A 192 × 48px button (
w-48 h-12 rounded-full) becomes a pill: each radius shrinks to 24px, half its height. The left and right ends are half circles, the top and bottom sides stay straight. Not an ellipse.
This differs from border-radius: 50% in plain CSS, which gives an ellipse on a long box. rounded-full makes a full circle only when the width and height are equal.
💡 Ring and divide
Two other classes also draw lines:
<input class="rounded-md border border-gray-300 ring-2 ring-blue-500">
<ul class="divide-y divide-gray-200">
<li>Item 1</li>
<li>Item 2</li>
</ul>
ring-2 ring-blue-500draws a 2px blue outer line withbox-shadow. Unlike a border, a ring takes no space, so the elements around it don't shift. A ring is often used to mark focus, which shows that an element is selected, for example an input you are typing in.divide-y divide-gray-200puts a 1px grey line between its children (the<li>items), with no line under the last item.
⚠️ Borders that vanish and corners that miss
- A colour without
border.border-gray-300on its own draws nothing, because the line width is still 0. Addbordertoo. borderwithout a colour. In v4, the line follows the text colour (currentColor), usually black. v3 tutorials say the default colour is light grey, but that has changed. Write the colour:border-gray-300.- One step off on rounded. The exercise asks for a 12px radius, which is
rounded-xl.rounded-lgis only 8px,rounded-2xl16px. border-bottomas a class. That's a CSS property name. The Tailwind class isborder-b.
TL;DR: border adds a 1px border line. border-2, border-4, border-8 are thicker, and the number is pixels. border-t, border-r, border-b, border-l do one side, and border-gray-300 colours the line. In v4 a border without a colour follows the text colour, and a colour without border draws nothing, so add both. Corners use rounded-*: rounded-lg 8px, rounded-xl 12px, rounded-2xl 16px, and rounded-t-lg for the top corners only. rounded-full turns a square into a circle and a long box into a pill. The exercise card: border border-gray-300 rounded-xl p-4 = a 1px grey line, a 12px radius, 16px of padding. ring-* draws an outer line that takes no space, and divide-y puts lines between an element's children.
⚡ Line, colour, corners
Write:
<div id="card" class="border border-gray-300 rounded-xl p-4">
Card with a border
</div>
Meaning: border adds a 1px border line, border-gray-300 colours it light grey, rounded-xl rounds the corners by 12px, and p-4 adds 16px of room inside.
The exercise asks for a 12px radius, which is rounded-xl. rounded-lg is only 8px.
⚡ Add both
Guess first: only border-gray-300, with no border. Does a line show?
No. Without border, the line width is 0, because Tailwind sets the line width of every element to 0 at the start. So the colour draws nothing.
Meaning: In the opposite case, a border with no colour class follows the text colour in v4, usually black. So add both.
⚡ Circle or pill
Guess first: rounded-full rounds the corners as much as possible. A 192 × 48px button gets rounded-full. Does it become an ellipse?
No, a pill shape. Each corner radius shrinks to 24px (half the button's height) to fit. The left and right ends become half circles, and the top and bottom sides stay straight.
Meaning: rounded-full only makes a full circle when the width and height are equal, for example size-24 rounded-full (96 × 96px).