CSS
🎯 CSS columns Property
The columns CSS property is a shorthand property used to create multi-column layouts. It allows you to define both the preferred column width and the maximum number of columns in a single declaration.
Instead of writing column-width and column-count separately, you can use the columns property to simplify your CSS code and create responsive newspaper-style layouts.
🔹 Why Use columns?
-
Benefits
- Combines column-width and column-count into one property.
- Simplifies multi-column layout creation.
- Creates responsive and flexible content layouts.
- Ideal for articles, magazines, blogs, and news websites.
🧩 Basic Usage
The following example creates columns with a preferred width of 200px and a maximum of 3 columns.
article {
columns: 200px 3;
}
The browser automatically determines the most suitable column arrangement based on the available space.
🔹 Syntax
columns: column-width column-count;
The order of values does not matter. Both examples below are valid:
columns: 200px 3;
columns: 3 200px;
🔹 columns Values
1️⃣ auto
Allows the browser to calculate both the column width and column count automatically.
div {
columns: auto;
}
2️⃣ column-width
Specifies only the preferred width of each column.
div {
columns: 250px;
}
3️⃣ column-count
Specifies only the maximum number of columns.
div {
columns: 3;
}
4️⃣ initial
Resets the property to its default value and removes the multi-column layout.
div {
columns: initial;
}
5️⃣ inherit
Inherits the columns value from the parent element.
div {
columns: inherit;
}
💡 Practical Example
.article-content {
columns: 250px 3;
column-gap: 30px;
}
This creates a responsive multi-column layout where each column aims to be 250px wide, with a maximum of three columns and a 30px gap between them.
-
🧠 Summary
- columns is the shorthand form of column-width and column-count.
- It allows you to define column width and column quantity in one line.
- The browser automatically creates the most suitable multi-column structure.
- Commonly used for article layouts, blogs, magazines, and news content.
