Borders help separate parts of a webpage visually. Changing their color and style makes your design clearer and more attractive.
Border color and style in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
border-{side?}-{width?} border-{color} border-{style}border-{side?}-{width?} sets which border and how thick it is (e.g., border for all sides, border-t-2 for top border 2px).
border-{color} sets the border color (e.g., border-red-500).
border-{style} sets the border style like solid, dashed, or dotted (e.g., border-dashed).
<div class="border border-blue-500 border-solid p-4">Content</div><div class="border-t-4 border-red-600 border-dashed p-4">Content</div><div class="border-b-2 border-green-400 border-dotted p-4">Content</div>This page shows three boxes with different border colors and styles using Tailwind CSS. Each box uses padding and rounded corners for better look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Border Color and Style Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <section class="max-w-md mx-auto space-y-6"> <div class="border border-blue-500 border-solid p-4 rounded"> <p>This box has a solid blue border.</p> </div> <div class="border-t-4 border-red-600 border-dashed p-4 rounded"> <p>This box has a thick, dashed red top border only.</p> </div> <div class="border-b-2 border-green-400 border-dotted p-4 rounded"> <p>This box has a thin, dotted green bottom border only.</p> </div> </section> </body> </html>
Use border-solid, border-dashed, or border-dotted to change border style.
Border colors come from Tailwind's color palette, like border-red-500 or border-green-400.
Combine border side, width, color, and style classes for custom borders.
Borders separate content and add style.
Tailwind uses simple classes for border color and style.
Mix border side, width, color, and style classes to get the look you want.
Practice
Solution
Step 1: Understand Tailwind color naming
Tailwind uses color names followed by a number for shade, likered-500.Step 2: Identify correct border color class
The correct format for border color isborder-{color}-{shade}, soborder-red-500is correct.Final Answer:
border-red-500 -> Option AQuick Check:
Border color usesborder-{color}-{shade}format [OK]
border-color-shade format for colors [OK]- Using
border-color-redwhich is invalid - Using just
border-redwithout shade - Using non-Tailwind class names
Solution
Step 1: Recall Tailwind border style classes
Tailwind usesborder-solid,border-dashed,border-dottedfor border styles.Step 2: Match correct class
border-dashedis the correct class to apply dashed border style.Final Answer:
border-dashed -> Option BQuick Check:
Border style classes start withborder-+ style [OK]
border- + style name [OK]- Using
border-dashwhich is not valid - Adding extra words like
border-style-dashed - Using non-Tailwind class names
<div class="border-4 border-blue-700 border-dotted">Content</div>
Solution
Step 1: Analyze border width class
border-4means border width is 4 pixels, which is thick.Step 2: Analyze border color and style
border-blue-700sets a dark blue color, andborder-dottedsets dotted style.Final Answer:
A thick (4px) blue dotted border -> Option CQuick Check:
Width 4 + blue-700 + dotted = thick blue dotted border [OK]
- Ignoring border width and assuming thin border
- Confusing dotted with dashed style
- Mixing up color shades
<div class="border-2 border-green border-solid">Box</div>
Solution
Step 1: Check border color class format
border-greenis incomplete; Tailwind requires a shade likeborder-green-500.Step 2: Verify other classes
border-2andborder-solidare valid classes.Final Answer:
Missing shade number in border color class -> Option DQuick Check:
Border color needs shade number like-500[OK]
- Omitting shade number in color class
- Using invalid style class names
- Confusing border width units
Solution
Step 1: Set default small screen styles
Useborder-red-600andborder-solidfor small screens (default).Step 2: Override on medium screens and up
Usemd:border-blue-600andmd:border-dashedto change color and style on medium+ screens.Final Answer:
border border-red-600 border-solid md:border-blue-600 md:border-dashed-> Option AQuick Check:
Default solid red, medium+ dashed blue withmd:prefix [OK]
md: prefix to change styles on medium screens [OK]- Mixing up default and responsive classes order
- Using wrong style classes for screen sizes
- Forgetting to include base
borderclass
