Outline

Utilities for controlling an element’s outline.

Default class reference

Class
Properties
outline-noneoutline: 2px solid transparent; outline-offset: 2px;
outline-whiteoutline: 2px dotted white; outline-offset: 2px;
outline-blackoutline: 2px dotted black; outline-offset: 2px;

Remove outlines

Use outline-none to hide the default browser outline on focused elements.

It is highly recommended to apply your own focus styling for accessibility when using this utility.

Outline - 图1

  1. <input type="text"
  2. placeholder="Default focus style"
  3. class="..." />
  4. <input type="text"
  5. placeholder="Custom focus style"
  6. class="focus:outline-none focus:ring focus:border-blue-300 ..." />

The outline-none utility is implemented using a transparent outline under the hood to ensure elements are still visibly focused to Windows high contrast mode users.

Dotted outlines

Use the outline-white and outline-black utilities to add a 2px dotted border around an element with a 2px offset. These are useful as an accessible general purpose custom focus style if you don’t want to design your own.

Outline - 图2

  1. <button class="focus:outline-black ...">Button A</button>
  2. <button class="focus:outline-white ...">Button B</button>

Customizing

Outlines

By default, Tailwind provides three outline utilities. You can customize these by editing the theme.outline section of your tailwind.config.js file.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. outline: {
  6. blue: '2px solid #0000ff',
  7. }
  8. }
  9. }
  10. }

You can also provide an outline-offset value for any custom outline utilities using a tuple of the form [outline, outlineOffset]:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. outline: {
  6. blue: ['2px solid #0000ff', '1px'],
  7. }
  8. }
  9. }
  10. }

Variants

By default, only responsive, focus-within and focus variants are generated for outline utilities.

You can control which variants are generated for the outline utilities by modifying the outline property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and active variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. extend: {
  5. // ...
  6. + outline: ['hover', 'active'],
  7. }
  8. }
  9. }

Disabling

If you don’t plan to use the outline utilities in your project, you can disable them entirely by setting the outline property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + outline: false,
  6. }
  7. }

←Cursor   Pointer Events→