Border Width

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

Class reference

Class
Properties
.border-0border-width: 0;
.border-2border-width: 2px;
.border-4border-width: 4px;
.border-8border-width: 8px;
.borderborder-width: 1px;
.border-t-0border-top-width: 0;
.border-r-0border-right-width: 0;
.border-b-0border-bottom-width: 0;
.border-l-0border-left-width: 0;
.border-t-2border-top-width: 2px;
.border-r-2border-right-width: 2px;
.border-b-2border-bottom-width: 2px;
.border-l-2border-left-width: 2px;
.border-t-4border-top-width: 4px;
.border-r-4border-right-width: 4px;
.border-b-4border-bottom-width: 4px;
.border-l-4border-left-width: 4px;
.border-t-8border-top-width: 8px;
.border-r-8border-right-width: 8px;
.border-b-8border-bottom-width: 8px;
.border-l-8border-left-width: 8px;
.border-tborder-top-width: 1px;
.border-rborder-right-width: 1px;
.border-bborder-bottom-width: 1px;
.border-lborder-left-width: 1px;

All sides

Use the .border, .border-0, .border-2, .border-4, or .border-8 utilities to set the border width for all sides of an element.

Border Width - 图1

  1. <div class="border-0 border-gray-600 ..."></div>
  2. <div class="border border-gray-600 ..."></div>
  3. <div class="border-2 border-gray-600 ..."></div>
  4. <div class="border-4 border-gray-600 ..."></div>
  5. <div class="border-8 border-gray-600 ..."></div>

Individual sides

Use the .border-{side}, .border-{side}-0, .border-{side}-2, .border-{side}-4, or .border-{side}-8 utilities to set the border width for one side of an element.

Border Width - 图2

  1. <div class="border-t-2 border-gray-600 ..."></div>
  2. <div class="border-r-2 border-gray-600 ..."></div>
  3. <div class="border-b-2 border-gray-600 ..."></div>
  4. <div class="border-l-2 border-gray-600 ..."></div>

Between elementsv1.3.0+

You can also add borders between child elements using the divide-{x/y}-{width} and divide-{color} utilities.

Learn more in the Divide Width and Divide Color documentation.

Border Width - 图3

  1. <div class="divide-y divide-gray-400">
  2. <div class="text-center py-2">1</div>
  3. <div class="text-center py-2">2</div>
  4. <div class="text-center py-2">3</div>
  5. </div>

Responsive

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

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

Border Width - 图4

all

Border Width - 图5

sm

Border Width - 图6

md

Border Width - 图7

lg

Border Width - 图8

xl

  1. <div class="border-2 sm:border-t-8 md:border-r-8 lg:border-b-8 xl:border-8">
  2. </div>

Customizing

Border Widths

By default Tailwind provides five border-width utilities, and the same number of utilities per side (top, right, bottom, and left). You change, add, or remove these by editing the theme.borderWidth section of your Tailwind config. The values in this section will also control which utilities will be generated side.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. borderWidth: {
  5. default: '1px',
  6. '0': '0',
  7. '2': '2px',
  8. + '3': '3px',
  9. '4': '4px',
  10. + '6': '6px',
  11. - '8': '8px',
  12. }
  13. }
  14. }

Responsive and pseudo-class variants

By default, only responsive variants are generated for border width utilities.

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

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

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

Disabling

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

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

← Border Radius   Border Color →