Border utilities help you quickly add or remove borders around elements without writing custom CSS.
Border utilities in Bootsrap
border border-top border-end border-bottom border-start border-0 border-top-0 border-end-0 border-bottom-0 border-start-0 border-primary border-secondary border-success border-danger border-warning border-info border-light border-dark border-white
Use border to add a border on all sides.
Add -0 suffix to remove border from specific sides.
<div class="border p-3">Box with border on all sides</div>
<div class="border-top p-3">Box with border only on top</div>
<div class="border border-primary p-3">Box with blue border</div>
<div class="border border-danger border-top-0 p-3">Box with red border except no top border</div>
This example shows four boxes with different border utilities from Bootstrap. Each box uses padding for spacing and different border classes to demonstrate how borders appear on all sides, only on top, with color, and with one side removed.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Border Utilities Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container my-5"> <h1>Bootstrap Border Utilities</h1> <section class="mb-4"> <div class="border p-3 mb-3">Border on all sides</div> <div class="border-top p-3 mb-3">Border only on top</div> <div class="border border-primary p-3 mb-3">Primary color border</div> <div class="border border-danger border-top-0 p-3">Danger color border except no top border</div> </section> </main> </body> </html>
Border utilities use 1px solid borders by default.
Use padding classes like p-3 to add space inside bordered elements.
Border colors follow Bootstrap's theme colors for consistency.
Border utilities let you add or remove borders quickly with simple classes.
You can control which sides have borders and their colors easily.
They help keep your design consistent and save time writing CSS.
Practice
Solution
Step 1: Understand the border utility classes
Bootstrap'sborderclass adds a border on all four sides of an element.Step 2: Compare with side-specific classes
Classes likeborder-toporborder-leftadd borders only on one side, not all sides.Final Answer:
border-> Option AQuick Check:
All sides border =border[OK]
border for all sides border fast [OK]- Confusing
border-topas all sides border - Using
border-noneto add border - Thinking
border-leftadds all borders
Solution
Step 1: Identify the Bootstrap class for removing borders
Bootstrap usesborder-0to remove all borders from an element.Step 2: Check other options for validity
Classes likeborder-remove,no-border, andborder-noneare not valid Bootstrap classes.Final Answer:
border-0-> Option CQuick Check:
Remove border =border-0[OK]
border-0 to remove borders quickly [OK]- Using non-existent classes like
border-none - Assuming
border-removeworks - Confusing
border-0with adding borders
<div class="border-top border-danger p-3">Hello</div>
Solution
Step 1: Analyze the classes used
The classborder-topadds a border only on the top side. The classborder-dangercolors the border red.Step 2: Understand the combined effect
Only the top border will be visible and it will be red. Other sides have no border.Final Answer:
A red border on the top side only -> Option DQuick Check:
border-top + border-danger= red top border [OK]
- Thinking
border-dangeradds border on all sides - Assuming
border-topadds border on all sides - Ignoring the color class effect
border-left-3. Why does the border not appear?Solution
Step 1: Check Bootstrap border width classes
Bootstrap usesborderfor border presence andborder-1,border-2, etc. for width, but not combined with side likeborder-left-3.Step 2: Understand correct usage
To add a left border with width, useborder-startplusborder-3or justborder-startwith color.border-left-3is invalid.Final Answer:
border-left-3is not a valid Bootstrap class -> Option AQuick Check:
Invalid class name = no border shown [OK]
- Using invalid combined classes like
border-left-3 - Assuming buttons can't have borders
- Forgetting to add color class for visibility
Solution
Step 1: Identify classes for border side and width
border-bottomadds border only on the bottom side.border-4sets border thickness to 4 (thick).Step 2: Add color class
border-primarycolors the border blue (Bootstrap primary color).Step 3: Check class order and validity
Order does not affect Bootstrap border utilities, soborder-bottom border-4 border-primaryis correct.border-bottom-4is invalid.Final Answer:
border-bottom border-4 border-primary-> Option BQuick Check:
Bottom thick blue border =border-bottom border-4 border-primary[OK]
- Using invalid class
border-bottom-4 - Adding border on all sides instead of bottom only
- Forgetting to add border width class
Ready to prove it?
Pass the test and this pattern moves unknown
