Skip to main content

Tailwind CSS Outline Cheatsheet

Complete reference for outline utilities in Tailwind v4.
Click any utility to copy the class name.

Outline vs Border vs Ring

Understanding when to use each is crucial for proper styling and accessibility.

Border

border-4
  • -Affects layout (takes space)
  • +Part of box model
  • +Can have different styles per side
CSS: border-width

Outline

outline-4
  • +Does NOT affect layout
  • +Native CSS property
  • -Can't style individual sides
CSS: outline-width

Ring (Tailwind)

ring-4
  • +Does NOT affect layout
  • +Has ring-offset utilities
  • !Tailwind-specific (box-shadow)
CSS: box-shadow

Key Takeaway: Use outline or ring for focus states since they don't shift the layout. Use border when the visual element should be part of the element's dimensions.

Outline Width

Control the width of an element's outline.

Outline Color

Set the color of an element's outline. All Tailwind color palettes are available.

Special Values

Color Palette (500 shade examples)

Shade variants: Each color has shades from 50 to 950.
Example: outline-blue-50, outline-blue-100, ..., outline-blue-950

Outline Style

Control the style of an element's outline.

Outline Offset

Control the space between an element and its outline.

Accessibility Warning: outline-none

Never remove focus outlines without providing an alternative!

Focus outlines are essential for keyboard navigation. Removing them makes your site inaccessible to users who rely on keyboard navigation (Tab key).

Bad Practice

<button class="outline-none">
  Click me
</button>

No focus indicator = inaccessible

Good Practice

<button class="outline-none
               focus:ring-2
               focus:ring-blue-500">
  Click me
</button>

Ring provides visible focus

Common Usage Patterns

Custom Focus Style

<input class="outline-none
              focus:outline-2
              focus:outline-blue-500
              focus:outline-offset-2" />

Dashed Selection Indicator

<div class="outline-2
            outline-dashed
            outline-gray-400">
  Selected item
</div>

Button Focus with Ring

<button class="outline-none
               focus-visible:ring-2
               focus-visible:ring-primary">
  Better UX with focus-visible
</button>

Thick Outline on Hover

<div class="outline-2
            outline-transparent
            hover:outline-purple-500
            outline-offset-4
            transition-all">
  Hover me
</div>

Frequently Asked Questions

What is the difference between outline, border, and ring in Tailwind CSS?

Border affects layout (takes up space), outline doesn't affect layout (sits outside the element), and ring uses box-shadow (also doesn't affect layout). Ring is Tailwind-specific and provides more flexibility with ring-offset utilities.

Should I use outline-none on focus states?

Never remove focus outlines without providing an alternative focus indicator. This is crucial for keyboard navigation accessibility. If you use outline-none, always pair it with a visible focus style like ring-2 or a custom focus indicator.

What does outline-offset do in Tailwind CSS?

Outline-offset creates space between the element and its outline. Values like outline-offset-2 or outline-offset-4 push the outline away from the element, creating a visual gap that can improve visibility and aesthetics.

When should I use outline vs ring?

Use outline when you need native CSS outline behavior (like for focus states that work with browser defaults). Use ring when you want more control, like using ring-offset to create space between the element and the ring, or when you want to combine it with other box-shadow effects.

Can I use arbitrary values for outline?

Yes! Use bracket notation for custom values: outline-[3px], outline-offset-[6px], or outline-[#custom-color].