How to Use the CSS column-rule Property
This article provides an overview of the CSS column-rule
property, explaining its syntax, component sub-properties, and practical
implementation. You will learn how this property draws visual divider
lines between multi-column text layouts, how it interacts with column
spacing, and how to effectively use it in responsive web design.
What is the CSS
column-rule Property?
The column-rule property in CSS is used in multi-column
text layouts to draw a vertical dividing line between adjacent columns.
It acts similarly to a standard border property, such as
border-left or border-right, but applies
specifically to the space separating columns generated by the CSS
Multi-column Layout module.
Syntax and Sub-Properties
column-rule is a shorthand property that combines three
individual properties into a single declaration:
.container {
column-rule: <column-rule-width> <column-rule-style> <column-rule-color>;
}The individual sub-properties include:
column-rule-width: Sets the thickness of the line. It accepts standard CSS length units (such aspx,em,rem) or keywords likethin,medium, andthick. The default value ismedium.column-rule-style: Defines the appearance of the line. It accepts standard border styles such asnone,hidden,solid,dashed,dotted,double,groove,ridge,inset, andoutset. The default value isnone. A style other thannoneorhiddenmust be defined for the line to be visible.column-rule-color: Sets the color of the rule using any valid CSS color value (hex, RGB, HSL, or named colors). If omitted, it defaults to the element'scurrentcolor.
Shorthand Example
.newspaper-layout {
column-count: 3;
column-gap: 40px;
column-rule: 2px solid #ccc;
}How
column-rule Draws Borders Between Columns
Understanding how the browser renders a column rule is key to avoiding layout bugs:
- Drawn Only Between Columns: Unlike regular element borders, a column rule never appears on the outer edges (left, right, top, or bottom) of the container. It is only rendered between adjacent columns. If content is not long enough to break into multiple columns, the rule does not render.
- Rendered Centered Within
column-gap: The column rule is drawn directly in the center of thecolumn-gap. - No Layout Space Consumption: The rule does not push
columns apart or consume physical box-model width. If the
column-rule-widthis thicker than thecolumn-gap, the rule will simply overflow into the adjacent text columns rather than expanding the gap. To prevent text overlap, ensure that yourcolumn-gapis always wider than yourcolumn-rule-width. - Matches Column Height: The height of the rule matches the height of the columns, extending from the top of the column text down to the bottom.
Complete Practical Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.article-columns {
column-count: 2;
column-gap: 3rem;
column-rule: 1px dashed #666666;
line-height: 1.6;
font-family: sans-serif;
}
</style>
</head>
<body>
<div class="article-columns">
<p>
Multi-column layouts allow content to flow naturally from one column to
the next. Using the column-rule property provides visual separation
similar to traditional newspaper print.
</p>
<p>
Because the rule is drawn within the column gap without taking up layout
space, it allows designers to add structure without recalculating container
widths or positioning manual dividers.
</p>
</div>
</body>
</html>