Design Converter
Education
Last updated on Mar 13, 2025
•4 mins read
Last updated on Mar 13, 2025
•4 mins read
Looking to create clean layouts in React?
Adding a vertical separator with Bootstrap can make a big difference in how your content looks and feels. Vertical dividers help organize content, making it easier for users to follow along. Bootstrap makes adding these dividers simple and flexible, especially when working with flex layouts.
This blog covers how to create a vertical separator in Bootstrap, how to customize it, and how it fits into different UI patterns.
A vertical divider is used to separate elements within a layout. With its grid and flex utilities, Bootstrap allows developers to incorporate vertical dividers efficiently. These rules provide a structured way to separate sections, enhancing readability and user experience.
Bootstrap’s grid system is based on a row and column structure, utilizing flexbox for alignment and spacing. To create a vertical divider, use CSS utilities such as border-start, border-end, and opacity settings to achieve the desired effect.
1.vertical-divider { 2 border-left: 1px solid rgba(0, 0, 0, 0.2); 3 height: 100%; 4 margin: 0 10px; 5}
In the above CSS snippet:
• The rgba(0, 0, 0, 0.2)
value in border-left
ensures a subtle appearance by applying a semi-transparent black border.
• The margin
provides spacing to separate elements.
A simple implementation of a vertical divider within a Bootstrap flex layout:
1import "bootstrap/dist/css/bootstrap.min.css"; 2 3function VerticalDividerExample() { 4 return ( 5 <div className="d-flex align-items-center"> 6 <div className="p-3">Left Content</div> 7 <div className="vertical-divider"></div> 8 <div className="p-3">Right Content</div> 9 </div> 10 ); 11} 12 13export default VerticalDividerExample;
Here:
• The d-flex
class applies a flex layout.
• The align-items-center
class ensures vertical alignment.
• The .vertical-divider
applies the vertical rule.
Bootstrap’s grid system enables structured common layouts using row and col. To create vertical dividers, a simple approach is using borders:
1<div className="container"> 2 <div className="row"> 3 <div className="col-5 p-3">Content 1</div> 4 <div className="col-1 d-flex align-items-center"> 5 <div className="vertical-divider w-100"></div> 6 </div> 7 <div className="col-5 p-3">Content 2</div> 8 </div> 9</div>
The Bootstrap flex layout simplifies adding vertical dividers in common UI structures.
1<div className="d-flex"> 2 <div className="p-3">Section A</div> 3 <div className="vertical-divider"></div> 4 <div className="p-3">Section B</div> 5</div>
The custom vertical rule helper ensures uniform styling across various sections.
Opacity affects how visible the vertical rules appear. Adjust the opacity in CSS:
1.vertical-divider { 2 border-left: 2px solid rgba(0, 0, 0, 0.5); 3 opacity: 0.5; 4}
By modifying the opacity
property, you can adjust the visibility of the divider.
The position of the vertical rule can be adjusted within the layout:
1.vertical-divider { 2 border-left: 1px solid #ccc; 3 height: 100%; 4 position: absolute; 5 left: 50%; 6 transform: translateX(-50%); 7}
This ensures the divider remains centered regardless of content changes.
Instead of using an explicit div, a vertical line can be added using ::after
:
1.divider-container::after { 2 content: ""; 3 position: absolute; 4 left: 50%; 5 width: 1px; 6 height: 100%; 7 background-color: black; 8}
This approach avoids unnecessary elements while keeping the layout clean.
To ensure vertical dividers in common structures are responsive, use Bootstrap’s utility classes.
1<div className="d-flex flex-column flex-md-row"> 2 <div className="p-3">Section A</div> 3 <div className="d-none d-md-block vertical-divider"></div> 4 <div className="p-3">Section B</div> 5</div>
• d-none d-md-block: Hides the vertical divider on small screens.
• flex-column flex-md-row: Stacks content on smaller screens but aligns horizontally on medium screens.
Incorrect Positioning
• Avoid using position: absolute
without a defined left value.
Lack of Flex Support
• Always wrap elements in d-flex
to ensure proper alignment.
Opacity Issues
• Adjust opacity
values for better visibility.
Overusing Extra Elements
• Prefer pseudo-elements over unnecessary div structures.
Using vertical separator Bootstrap helps keep layouts clean and easy to follow. By tweaking opacity, adjusting styles, and using flex layouts, developers can create sharp and organized designs. Bootstrap’s built-in utilities make it simple to add vertical dividers while keeping things consistent. Adding custom styles gives even more control over the look and feel, making it easier to match any design.
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.