Skip to content

Tailwind CSS - Outline Color

Outline color utilities in Tailwind CSS allow you to control the color of an element’s outline. This is particularly crucial for creating visible and accessible focus indicators for interactive elements like buttons, links, and form inputs.

Tailwind generates outline color utilities based on your configured color palette. The classes follow a predictable pattern: outline-{color}-{shade}. Instead of memorizing every class, learn the pattern.

Class PatternCSS Properties
outline-inheritoutline-color: inherit;
outline-currentoutline-color: currentColor;
outline-transparentoutline-color: transparent;
outline-{color}outline-color: {your-color-value}; (e.g., outline-blue-500)
outline-{color}/{opacity}outline-color: rgb({color-channels} / {opacity-value}); (e.g., outline-blue-500/50)

The {color} can be any color defined in your tailwind.config.js file (like slate, red, emerald), and {shade} is typically a value from 50 (lightest) to 950 (darkest).

Practical Application: Accessible Focus States

Section titled “Practical Application: Accessible Focus States”

A primary use for outline color is to style the focus state of elements, enhancing accessibility. Best practice is to use the focus-visible variant, which applies focus styles only when the user is navigating with a keyboard, providing a cleaner experience for mouse users.

This example demonstrates styling a button with a custom outline color on focus. Note that outline-2 (width) and outline-offset-2 are used alongside outline-violet-500 to make the outline clearly visible.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Outline Color</title>
<!-- For a real project, install Tailwind CSS via npm -->
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-100 flex items-center justify-center h-screen">
<button class="px-6 py-3 bg-violet-600 text-white font-bold rounded-lg shadow-md
transition-transform transform hover:scale-105
focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-400">
Click or Tab to Me
</button>
</body>
</html>

If the default color palette isn’t sufficient, you can easily add your own outline colors in your tailwind.config.js file by extending the outlineColor theme object.

tailwind.config.js
module.exports = {
theme: {
extend: {
outlineColor: {
'brand': '#FF5A5F', // Example brand color
'success': '#22C55E',
}
}
}
}

After this configuration, you can use classes like outline-brand or focus:outline-success in your HTML.

  • Mistake: Outline not appearing. An outline needs a style (outline-solid, outline-dashed) and a width (outline-1, outline-2, etc.) to be visible. The outline utility class is a shorthand that sets a default solid style and width. If you only set outline-blue-500, it won’t be visible without a width and style.
  • Best Practice: focus-visible over focus. Using focus: will show the outline even on mouse clicks, which can be visually distracting. focus-visible: targets keyboard navigation specifically, which is the modern standard for accessibility.
  • Accessibility Tip: Contrast is Key. Ensure your chosen outline color has sufficient contrast against the surrounding background to be clearly visible to all users. Tools like WebAIM’s Contrast Checker can help.