border-width

Các utility để kiểm soát độ rộng của border của một phần tử.

ClassStyles
border
border-width: 1px;
border-<number>
border-width: <number>px;
border-(length:<custom-property>)
border-width: var(<custom-property>);
border-[<value>]
border-width: <value>;
border-x
border-inline-width: 1px;
border-x-<number>
border-inline-width: <number>px;
border-x-(length:<custom-property>)
border-inline-width: var(<custom-property>);
border-x-[<value>]
border-inline-width: <value>;
border-y
border-block-width: 1px;
border-y-<number>
border-block-width: <number>px;

Ví dụ

Ví dụ cơ bản

Sử dụng các utility border hoặc border-<number> như border-2border-4 để thiết lập độ rộng border cho tất cả các cạnh của một phần tử:

border

border-2

border-4

border-8

<div class="border border-indigo-600 ..."></div><div class="border-2 border-indigo-600 ..."></div><div class="border-4 border-indigo-600 ..."></div><div class="border-8 border-indigo-600 ..."></div>

Các cạnh riêng lẻ

Sử dụng các utility như border-rborder-t-4 để thiết lập độ rộng border cho một cạnh của một phần tử:

border-t-4

border-r-4

border-b-4

border-l-4

<div class="border-t-4 border-indigo-500 ..."></div><div class="border-r-4 border-indigo-500 ..."></div><div class="border-b-4 border-indigo-500 ..."></div><div class="border-l-4 border-indigo-500 ..."></div>

Các cạnh ngang và dọc

Sử dụng các utility như border-xborder-y-4 để thiết lập độ rộng border trên hai cạnh của một phần tử cùng một lúc:

border-x-4

border-y-4

<div class="border-x-4 border-indigo-500 ..."></div><div class="border-y-4 border-indigo-500 ..."></div>

Sử dụng các thuộc tính logic

Sử dụng các utility như border-sborder-e-4 để thiết lập các thuộc tính logic border-inline-start-widthborder-inline-end-width, ánh xạ tới border trái hoặc phải dựa trên hướng văn bản:

Left-to-right

Right-to-left

<div dir="ltr">  <div class="border-s-4 ..."></div></div><div dir="rtl">  <div class="border-s-4 ..."></div></div>

Giữa các phần tử con

Sử dụng các utility như divide-xdivide-y-4 để thêm border giữa các phần tử con:

01
02
03
<div class="grid grid-cols-3 divide-x-4">  <div>01</div>  <div>02</div>  <div>03</div></div>

Đảo ngược thứ tự phần tử con

Nếu các phần tử của bạn theo thứ tự ngược lại (ví dụ sử dụng flex-row-reverse hoặc flex-col-reverse), hãy sử dụng các utility divide-x-reverse hoặc divide-y-reverse để đảm bảo border được thêm vào đúng cạnh của mỗi phần tử:

01
02
03
<div class="flex flex-col-reverse divide-y-4 divide-y-reverse divide-gray-200">  <div>01</div>  <div>02</div>  <div>03</div></div>

Sử dụng giá trị tùy chỉnh

Use the border-[<value>] syntax to set the border width based on a completely custom value:

<div class="border-[2vw] ...">  <!-- ... --></div>

For CSS variables, you can also use the border-(length:<custom-property>) syntax:

<div class="border-(length:--my-border-width) ...">  <!-- ... --></div>

This is just a shorthand for border-[length:var(<custom-property>)] that adds the var() function for you automatically.

Thiết kế phản hồi

Prefix a border-width utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="border-2 md:border-t-4 ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Chính sách thương hiệu