Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Tailwind CSS Borders

Tailwind CSS Borders

In Tailwind CSS,Border(Borders) is a common style in layout and design, used to add boundaries or dividing lines to elements.

Tailwind provides a variety of border utility classes to help you control border width, color, style, radius, and borders in each direction.

Border Width (Border Width)

Border width determines the thickness of an element's border lines. Tailwind CSS provides different border width values, allowing you to quickly control element border styles.

Class Names Description Example
border-{n} Set all border widths,n to the width value border-2(width of 2px)
border-t-{n} Set top border width border-t-4(top border width 4px)
border-r-{n} Set right border width border-r-8(right border width 8px)
border-b-{n} Set bottom border width border-b-1(bottom border width 1px)
border-l-{n} Set left border width border-l-3(left border width 3px)

Border Color (Border Color)

By using border-{color} utility classes, you can set an element's border color. Tailwind CSS provides a large number of preset colors that can be used directly, and also supports custom colors.

Class Names Description Example
border-{color} Set border color border-red-500(red border)
border-t-{color} Set top border color border-t-blue-300(blue top border)
border-r-{color} Set right border color border-r-gray-400(gray right border)
border-b-{color} Set bottom border color border-b-green-600(green bottom border)
border-l-{color} Set left border color border-l-yellow-500(yellow left border)
红色边框,宽度为 2px

Border Style (Border Style)

Tailwind CSS also supports setting border styles, such as solid, dashed, dotted, etc. Through border-{style} utility classes, you can control the display style of borders.

Class Names Description Example
border-solid Set a solid border (default) border-solid
border-dashed Set a dashed border border-dashed
border-dotted Set a dotted border border-dotted
border-double Set a double border border-double
蓝色虚线边框,宽度为 4px

Border Radius (Border Radius)

By setting border-radius, you can control an element's rounded corner effect. Tailwind CSS provides a variety of border radius values and allows you to set different rounded corners in different directions.

Class Names Description Example
rounded-{size} Set a uniform rounded corner size rounded-lg(large rounded corners)
rounded-tl-{size} Set top-left rounded corners rounded-tl-sm(small rounded corners)
rounded-tr-{size} Set top-right rounded corners rounded-tr-md(medium rounded corners)
rounded-br-{size} Set bottom-right rounded corners rounded-br-lg(large rounded corners)
rounded-bl-{size} Set bottom-left rounded corners rounded-bl-xl(extra-large rounded corners)
大圆角边框

Border Control in Four Directions

You can control each direction's border individually (top, right, bottom, left), such as:border-t-2 Controls the top border width,border-r-4 controls the right border width, and so on.

Class Names Description Example
border-t-{size} Set top border width border-t-2(top border width 2px)
border-r-{size} Set right border width border-r-4(right border width 4px)
border-b-{size} Set bottom border width border-b-1(bottom border width 1px)
border-l-{size} Set left border width border-l-3(left border width 3px)
自定义各个方向的边框

Unified Border Control (Border)

If you want to set the same style for all borders, use the border utility class. You can combine other utility classes to control color, style, and width.

Class Names Description Example
border Set all border widths to 1px, solid border(default width of 1px)
border-2 Set all border widths to 2px border-2(solid line with 2px width)
border-4 Set all border widths to 4px border-4(solid line with 4px width)
绿色实线边框,宽度为 4px

Inner and Outer Borders (Box Model)

Tailwind CSS also provides utility classes to control Box Model , especially inner and outer borders, margins, and padding.

Class Names Description Example
box-border Set the box model to border-box(including the border) box-border
box-content Set the box model to content-box(excluding the border) box-content
边框包含在内的盒子模型

Comprehensive Example Combining All Border Utilities

Example

    4px wide red border

    Blue dashed border with a width of 2px

    Rounded green border

    Custom Direction Borders

Try it »