Introduction
CSS Multi-Column Layout allows text content to flow naturally across multiple columns, similar to newspapers and magazines. Properties such as column-count, column-width, column-gap, and column-rule give you control over the number, size, spacing, and appearance of columns. This technique is especially useful for articles, blogs, documentation, and text-heavy layouts. In this chapter, you will practice these properties through simple CSS Multi-Column layout practice questions with solutions
Question 1: Create a Two-Column Layout
Problem Statement
Write CSS to divide content into two columns.
CSS Code
.article {
column-count: 2;
}
Output
The content is automatically distributed across two columns.
Explanation
column-countspecifies the number of columns.2creates two equal columns.- The browser automatically flows the content from one column to the next.
Question 2: Create a Three-Column Layout
Problem Statement
Write CSS to divide an article into three columns.
CSS Code
.article {
column-count: 3;
}
Output
The article content flows across three columns.
Explanation
column-count: 3creates three columns.- The available width is divided among the columns.
- This is useful for magazine-style layouts.
Question 3: Set the Preferred Column Width
Problem Statement
Write CSS to specify an approximate column width of 200px.
CSS Code
.article {
column-width: 200px;
}
Output
The browser attempts to create columns with an approximate width of 200px based on the available space.
Explanation
column-widthdefines the preferred width of each column.- The browser determines how many columns can fit.
- Unlike
column-count, you specify the preferred column size rather than a fixed number.
Question 4: Add Space Between Columns
Problem Statement
Create a two-column layout with a 30px gap between the columns.
CSS Code
.article {
column-count: 2;
column-gap: 30px;
}
Output
Two columns appear with 30px of space between them.
Explanation
column-count: 2creates two columns.column-gap: 30pxcontrols the space between them.- A suitable gap can make multi-column text easier to read.
Question 5: Add a Rule Between Columns
Problem Statement
Create a two-column layout with a 1px solid gray line between the columns.
CSS Code
.article {
column-count: 2;
column-gap: 30px;
column-rule: 1px solid gray;
}
Output
A vertical gray line appears between the two columns.
Explanation
column-rulecreates a visual divider between columns.1pxsets the rule thickness.
Question 6: Control Column Rule Properties
Problem Statement
Create a three-column layout with a 2px dashed blue rule between the columns.
CSS Code
.article {
column-count: 3;
column-gap: 25px;
column-rule-width: 2px;
column-rule-style: dashed;
column-rule-color: blue;
}
Output
The content is divided into three columns with a 2px dashed blue line between them.
Explanation
column-rule-widthcontrols the thickness.column-rule-stylecontrols the line style.column-rule-colorcontrols the rule color.column-gapcontrols the space between columns.
Question 7: Make Content Span Across All Columns
Problem Statement
Write CSS so that a heading spans across all columns instead of remaining inside a single column.
CSS Code
.article {
column-count: 3;
}
.article-heading {
column-span: all;
}
Output
The heading spans across the entire multi-column layout.
Explanation
column-span: allmakes the element span across all columns.- This is useful for article headings and section titles.
- The property affects the element within a multi-column container.
Question 8: Control How Columns Are Filled
Problem Statement
Write CSS to fill columns sequentially based on their available height.
CSS Code
.article {
column-count: 3;
height: 400px;
column-fill: auto;
}
Output
The content fills the columns sequentially using the available 400px height.
Explanation
column-fill: autocontrols how content is distributed when the container has a constrained height.height: 400pxgives the multi-column container a fixed height.- The content flows through the columns according to the available space.
Question 9: Create a Responsive Multi-Column Layout
Problem Statement
Create a multi-column layout that automatically determines the number of columns based on a preferred width of 220px.
CSS Code
.article {
column-width: 220px;
column-gap: 25px;
}
Output
The browser automatically adjusts the number of columns according to the available width while targeting approximately 220px per column.
Explanation
column-widthprovides the preferred width.column-gapcontrols the spacing between columns.- As the available width changes, the browser can change the number of columns.
Question 10: Build a Complete Multi-Column Layout
Problem Statement
Create a professional article layout with three columns, a 25px gap, and a 1px solid light-gray rule between the columns.
CSS Code
.article {
column-count: 3;
column-gap: 25px;
column-rule: 1px solid lightgray;
line-height: 1.6;
}
Output
The article is displayed in three readable columns with spacing and visual dividers between them.
Explanation
column-count: 3creates three columns.column-gap: 25pxadds spacing.column-rulecreates a divider.line-height: 1.6improves text readability.- This combination is useful for newspaper-style and magazine-style layouts.
Key Takeaways
column-countcontrols the number of columns.column-widthdefines the preferred width of columns.column-gapcontrols the space between columns.column-rulecreates a visual divider between columns.column-rule-widthcontrols rule thickness.column-rule-stylecontrols the rule style.column-rule-colorcontrols the rule color.column-span: allallows an element to span across all columns.column-fillcontrols how content is distributed when the container has a constrained height.- Multi-column layouts are useful for articles, magazines, newspapers, documentation, and blogs.
Frequently Asked Questions (FAQs)
1. What is CSS Multi-Column Layout?
CSS Multi-Column Layout allows content to flow across multiple columns within a single container.
Example:
.article {
column-count: 2;
}
2. What does column-count do?
column-count specifies the desired number of columns.
.article {
column-count: 3;
}
3. What does column-width do?
column-width specifies the preferred width of each column.
.article {
column-width: 220px;
}
The browser determines how many columns can fit within the available width.
4. How do I add space between columns?
Use column-gap.
.article {
column-gap: 30px;
}
5. How do I add a line between columns?
Use column-rule.
.article {
column-rule: 1px solid gray;
}
6. How can an element span across all columns?
Use column-span: all.
.article-heading {
column-span: all;
}
7. Where are multi-column layouts commonly used?
They are commonly used for articles, newspapers, magazines, documentation, blogs, and other text-heavy layouts.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.
