Cracker · 2026-11-22
HTML vertical divider: six ways to draw one
An HTML vertical divider is a line between two things that sit side by side. HTML has no tag for it, so you draw one with CSS, and there are at least six good ways. Each demo below is live, and each snippet is whole (markup and styles), so it works when you paste it into a blank page.
A simple line should never cost anything. Here are six for free.
Which one should you use?
Use the border (1) when a line is all you need. Use a flex or grid line (2, 3) when the divider is part of the layout. Use the hr (5) when you want it to count as a real separator for people using screen readers.
1. A border on one side
The simplest way. Put a border on the right of the left box. Good when the divider is just a line.
Left side
Right side
1. A border on one side (HTML and CSS) <style> .row { display: flex; } .left { flex: 1; border-inline-end: 3px solid #86e3be; padding-inline-end: 1rem; } .right { flex: 1; padding-inline-start: 1rem; } </style> <div class="row"> <div class="left"><p>Left side</p></div> <div class="right"><p>Right side</p></div> </div>2. A flex child line
Make the divider its own element and let flex stretch it to the full height. Good when you want to style it as a thing.
Left side
Right side
2. A flex child line (HTML and CSS) <style> .row { display: flex; gap: 1rem; } .pane { flex: 1; } .line { width: 3px; background: #86e3be; align-self: stretch; } </style> <div class="row"> <div class="pane"><p>Left side</p></div> <div class="line" aria-hidden="true"></div> <div class="pane"><p>Right side</p></div> </div>3. A grid column line
A thin middle column holds the line. Good when your layout is already a grid.
Left side
Right side
3. A grid column line (HTML and CSS) <style> .row { display: grid; grid-template-columns: 1fr 3px 1fr; gap: 1rem; } .line { background: #86e3be; } </style> <div class="row"> <div class="pane"><p>Left side</p></div> <div class="line" aria-hidden="true"></div> <div class="pane"><p>Right side</p></div> </div>4. A pseudo-element line
Draw the line with ::after so the markup stays clean, with no extra element. Good when you cannot or will not add one.
Left side
Right side
4. A pseudo-element line (HTML and CSS) <style> .row { display: flex; } .left { flex: 1; position: relative; padding-inline-end: 1rem; } .left::after { content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 3px; background: #86e3be; } .right { flex: 1; padding-inline-start: 1rem; } </style> <div class="row"> <div class="left"><p>Left side</p></div> <div class="right"><p>Right side</p></div> </div>5. An hr turned sideways
An hr is a real separator that screen readers know. Stretch it in a flex row and tell assistive tech it is vertical.
Left side
Right side
5. An hr turned sideways (HTML and CSS) <style> .row { display: flex; gap: 1rem; } .pane { flex: 1; } .row hr { align-self: stretch; width: 0; margin: 0; border: 0; border-inline-start: 3px solid #86e3be; } </style> <div class="row"> <div class="pane"><p>Left side</p></div> <hr aria-orientation="vertical" /> <div class="pane"><p>Right side</p></div> </div>6. A fading gradient
A line that fades at the ends looks softer. A background gradient on a thin element does it.
Left side
Right side
6. A fading gradient (HTML and CSS) <style> .row { display: flex; gap: 1rem; } .pane { flex: 1; } .line { width: 3px; align-self: stretch; background: linear-gradient(to bottom, transparent, #86e3be 20%, #86e3be 80%, transparent); } </style> <div class="row"> <div class="pane"><p>Left side</p></div> <div class="line" aria-hidden="true"></div> <div class="pane"><p>Right side</p></div> </div>
On a phone, it can turn sideways
On a narrow screen, two things side by side are cramped. A common fix is to stack them and turn the vertical line into a horizontal one. In the flex version, add flex-direction: column in a media query, and swap the line's width for a height.
The same idea works for the grid version: change the three columns to one column, and give the middle line a height instead of a width.
The snack take
A divider is just a gap with opinions. Pick the simplest way that works, then move on to the cheese puffs.
Tested in Chromium only. All six use long-supported CSS, so they should work in other current browsers, but we have not checked them there.
The fine print, in plain words
Why this is free
We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.
This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.
Next snack
CSS container query and style queries
A card that reshapes itself to its box, not the screen — no media queries, no script.