Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 37 ยท Utility Basics

Borders, Rings and Outlines

Style element edges in Tailwind v4: border width, color and style, rounded corners, divide lines, ring utilities and accessible focus outlines, with v3 differences.

The edge of an element can be drawn four different ways in Tailwind: a border (takes up space in the layout), a ring (a shadow that looks like a border and takes no space), an outline (drawn outside the box, used for focus) and divide lines between children. Add rounded corners and you cover almost every card, input and button you will ever style.

Border width, color and style

Border utilities follow the pattern border, border-{side} and border-{width}:

Class Effect
border 1px border on all sides
border-2, border-4, border-8 thicker borders
border-t, border-r, border-b, border-l one side
border-x, border-y two sides
border-s, border-e logical start and end
border-0 remove a border

Color uses the same palette as everything else (border-slate-200), and the style is border-solid (default), border-dashed, border-dotted, border-double or border-none.

v4 change: the default border color is now currentColor, the same as the text color. In v3 it was light gray. So a bare border looks black or dark gray in v4. Always add a color: border border-slate-200.

Border width, color and style

The last box is a common pattern: a thick start border and a pale background make a callout.

Rounded corners

rounded-* sets border radius. In v4 the scale was shifted by one step, so mind the old names:

v4 class Radius Was in v3
rounded-xs 0.125rem rounded-sm
rounded-sm 0.25rem rounded
rounded-md 0.375rem same
rounded-lg 0.5rem same
rounded-xl 0.75rem same
rounded-2xl 1rem same
rounded-3xl, rounded-4xl 1.5rem, 2rem rounded-4xl is new
rounded-full 9999px, pill or circle same
rounded-none 0 same

Round only some corners with rounded-t-lg, rounded-b-lg, rounded-l-lg, rounded-r-lg, or a single one: rounded-tl-xl, rounded-br-none. A square element with rounded-full is a circle; a wide one becomes a pill.

Rounded corners

Divide lines

Instead of putting a border on every item, divide-y draws a border between children, and none on the outside. Style it with divide-{color} and width with divide-y-2.

HTML
<ul class="divide-y divide-slate-200 rounded-lg border border-slate-200">
  <li class="p-3">Inbox</li>
  <li class="p-3">Drafts</li>
  <li class="p-3">Sent</li>
</ul>

Rings

A ring looks like a border but is painted with a box-shadow, so it never changes the layout size. That makes it ideal for focus indicators and for cards where you do not want the content to jump by 1px on hover.

  • ring is a 1px ring (in v4, ring used to be 3px in v3; use ring-3 for that old look).
  • ring-2, ring-4 set the width.
  • ring-sky-500 sets the color, ring-sky-500/50 adds transparency.
  • ring-inset draws it inside the element.
  • inset-ring is the newer inset-shadow-based ring that works together with a normal ring.
  • ring-offset-2 adds a gap of the page background between element and ring.
HTML
<button class="rounded-md bg-white px-4 py-2 ring-1 ring-slate-300 hover:ring-slate-400">
  Cancel
</button>

Outlines and focus

An outline is drawn outside the border, does not affect layout and follows the element's rounded corners in modern browsers. Browsers show a default focus outline on keyboard focus, and you should keep one: removing it makes your site unusable for keyboard users.

Classes: outline (1px), outline-2, outline-offset-2, outline-{color}, outline-dashed. In v4, outline-none was renamed to outline-hidden (it hides the outline but keeps one in forced-colors mode for accessibility). The old behavior of truly removing it is outline-none again, which you should rarely use.

The recommended focus recipe:

HTML
<button class="rounded-md bg-indigo-600 px-4 py-2 text-white
               focus-visible:outline-2 focus-visible:outline-offset-2
               focus-visible:outline-indigo-600">
  Save
</button>

focus-visible: applies only when the browser decides a focus indicator is helpful, which is for keyboard users, not mouse clicks. Press Tab in this TryIt to see it:

Rings and focus outlines

The input uses outline-hidden and replaces the default outline with a border color change and a ring, so it is still obvious when focused. That swap is acceptable; removing the outline with nothing in its place is not.

Which edge tool when?

Need Use
A permanent visible border border + color
Lines between list items divide-y
Highlight that must not shift layout (hover, selected) ring
Keyboard focus indicator outline with focus-visible:
Soft depth shadows, see Shadows, Filters and Backdrop

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In Tailwind v4, what color does a bare border use by default?

    v4 changed the default border color to currentColor. Add a color class such as border-slate-200.
  2. 2. Which utility draws a border-like edge without changing the element's layout size?

    Rings are painted with box-shadow, so they take no space.
  3. 3. What does outline-hidden do in v4?

    outline-hidden is the accessible replacement for the old outline-none behavior.
  4. 4. Which class gives the pill shape to a wide button?

    rounded-full sets a very large radius, creating a pill on wide elements and a circle on square ones.

Summary

  • border, border-{side} and border-{width} draw edges; always add a color in v4.
  • rounded-* has shifted names in v4 (rounded-sm is the old rounded); rounded-full makes pills and circles.
  • divide-* separates children; ring-* draws a layout-free border; outline-* with focus-visible: gives focus states.
  • Never remove focus indicators without a replacement.

Next: Backgrounds and Gradients