HOWTO · HTML
How to Create Vertical Line in HTML
Create a vertical line on an HTML page with CSS border-left or a styled hr element, then place it between content using Flexbox or CSS Grid.
On this page
To create a vertical line on an HTML page, use CSS to set its height, thickness, and color. A border-left works well for a decorative divider; style an <hr> when it represents a thematic break; use Flexbox or CSS Grid to position a divider between content blocks. HTML alone does not control the line’s appearance.
Create a vertical line with CSS border-left
A left border is a simple decorative line. Give its element an explicit height, then set the border width and color. This Node.js script writes a complete example page to vertical-line.html; open that file in a browser to view it.
Here is a complete page generator. Run it with Node.js; it creates a page with two labels and a blue divider between them.
const { writeFileSync } = require("node:fs");
const page = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vertical line with a border</title>
<style>
.row { display: flex; align-items: center; }
.line {
height: 8rem;
border-left: 2px solid #2563eb;
margin-inline: 1rem;
}
</style>
</head>
<body>
<div class="row">
<span>Account details</span>
<div class="line" aria-hidden="true"></div>
<span>Preferences</span>
</div>
</body>
</html>`;
writeFileSync("vertical-line.html", page);
console.log("Created vertical-line.html");
The CSS sets an 8 rem line length and a 2 pixel thickness; change those values and the border color to match your page. margin-inline adds space on both sides in left-to-right and right-to-left layouts. The line is decorative, so aria-hidden="true" keeps it out of the accessibility tree. A percentage height depends on a containing block with a definite height; otherwise it may not resolve to the size you expect.
Adapt an hr element into a vertical line
The hr element, written as <hr> in HTML source, represents a thematic break between parts of a page. Use it when that meaning fits the content; CSS changes its appearance, not its meaning. Browsers apply default styling, so reset the border before drawing a narrow vertical rule. For example, use <hr class="vertical-rule"> and style it with width: 0; height: 8rem; border: 0; border-left: 2px solid #2563eb; margin: 1rem;. The visible width comes from the left border. This element stays in normal document flow and occupies its own line; place it in a Flexbox or Grid container when it belongs between side-by-side content.
Place a divider between content with Flexbox or Grid
Flexbox and Grid position a divider as a layout item, while a border or background draws the visible line. In a Flexbox row, place two content sections around a divider element; set the parent to display: flex; align-items: stretch; gap: 1rem;, give each section flex: 1;, and give the divider border-left: 2px solid #2563eb;. The line stretches to the row’s height, which follows the taller content section. Mark a decorative divider with aria-hidden="true".
For Grid, use three columns so the middle track is the line: grid-template-columns: minmax(0, 1fr) 2px minmax(0, 1fr); gap: 1rem;. Put the panels in the first and third columns and a divider element with background: #2563eb in the middle; the 2 pixel track controls its thickness. On narrow screens, stack the panels with a media query and replace the vertical rule with a horizontal border if that better suits the reading order. Choose border-left for a simple accent, <hr> for a meaningful thematic break, and Flexbox or CSS Grid when the divider belongs between layout items.