Border Color

Utilities for controlling the color of an element’s borders.

Class reference

Border Color - 图1 Border Color - 图2 Border Color - 图3 Border Color - 图4

Usage

Control the border color of an element using the .border-{color} utilities.

Border Color - 图5

  1. <input class="border border-red-500 ...">

Responsive

To control the border color of an element at a specific breakpoint, add a {screen}: prefix to any existing border color utility. For example, use md:border-green-500 to apply the border-green-500 utility at only medium screen sizes and above.

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

  1. <button class="border-blue-500 sm:border-green-500 md:border-indigo-500 lg:border-red-500 xl:border-black ...">
  2. Button
  3. </button>

Border Color - 图6

Hover

To control the border color of an element on hover, add the hover: prefix to any existing border color utility. For example, use hover:border-blue-500 to apply the border-blue-500 utility on hover.

Border Color - 图7

  1. <button class="border-2 border-blue-500 hover:border-red-500 ...">
  2. Button
  3. </button>

Hover utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

  1. <button class="... md:border-blue-500 md:hover:border-blue-700 ...">Button</button>

Focus

To control the border color of an element on focus, add the focus: prefix to any existing border color utility. For example, use focus:border-blue-500 to apply the border-blue-500 utility on focus.

Border Color - 图8

  1. <input class="border-gray-400 focus:border-blue-500 ...">

Focus utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

  1. <input class="... md:border-gray-200 md:focus:border-white ...">

Customizing

Border Colors

By default Tailwind makes the entire default color palette available as border colors.

You can customize your color palette by editing the theme.colors variable in your tailwind.config.js file, or customize just your border colors using the theme.borderColor section of your Tailwind config.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. borderColor: theme =&gt; ({
  5. - ...theme('colors'),
  6. default: theme('colors.gray.300', 'currentColor'),
  7. + 'primary': '#3490dc',
  8. + 'secondary': '#ffed4a',
  9. + 'danger': '#e3342f',
  10. })
  11. }
  12. }

Responsive and pseudo-class variants

By default, only responsive, hover and focus variants are generated for border color utilities.

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

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

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - borderColor: ['responsive', 'hover', 'focus'],
  6. + borderColor: ['responsive', 'hover', 'focus', 'active', 'group-hover'],
  7. }
  8. }

Disabling

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

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