Tailwind CSS

Borders


Tailwind CSS offers a comprehensive set of utility classes to manage borders.

 

1. Border Width:

Controlled using classes with the prefix border-. These classes represent different widths based on Tailwind's spacing scale (often in rems).

 

  • border: Thin border (usually 1px)
  • border-2: Medium border (typically 2px)
  • border-4: Thick border (often 4px)

 

2. Border Style


Defined using classes like:

  • border-solid: Solid line (default)
  • border-dashed: Dashed line
  • border-dotted: Dotted line
  • border-double: Double line

 

3. Border Color:

Set with classes prefixed by border- followed by a color name or hex code:

  • border-gray-500: Gray border 
  • border-blue: Blue border
  • border-transparent: No border (useful for creating space without a visible line)

 

Example:

<div class="box border border-dashed border-blue-400"> This box has a dashed blue border. </div>

 

Customization

Tailwind allows for granular control over borders:

 

Individual Sides: Use classes like border-top, border-right, border-bottom, and border-left to target specific sides of the element. For instance, border-left-2 border-gray-300 applies a thicker left border with a light gray color.

Responsive Borders: Apply responsive prefixes like md: or lg: to adjust borders based on screen sizes. For example, lg:border-4 sets a thick border only on large screens and above.

 

Additional Utilities:

 

Border Radius: Use the rounded class or its variations (e.g., rounded-lg) to add rounded corners to elements along with borders.

Border Opacity: Control the transparency of borders using the border-opacity class with values from 0 (fully transparent) to 100 (fully opaque).

 

Note:

Tailwind provides a wide range of utility classes for borders, allowing for various styles and customizations.
You can combine classes for complex border configurations (e.g., border-2 border-dashed border-red-500).