Mastering CSS Columns Property with example

  • css
  • 80 Views
  • 6 Min Read
  • 4 May 2024

Hi developer! In this article, we've explained everything you need to know about the CSS column property. After reading this article carefully, we are sure that you will master the CSS column property.

 

Let's dive in!

 

 

Column-count property

 

The column-count property divides an HTML element into multiple columns.

 

Here are the values for the column-count property:

 

number: Specifies the number of columns an element should be divided into.

 

auto: This is the default value. It lets the browser determine the number of columns based on other properties, like column width.

 

Syntax:

 

column-count: number | auto;
 
<head>
    <style>
        .container {
            background-color: thistle;
            columns: 4;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-count Property</h1>
    <div class="container">
        <p>Lorem ipsum dolor sit ...(200 words)... fugit dolorem. </p>
    </div>
</body>

 

CSS column property

 

 

Column-fill property

 

The column-fill property determines how content fills columns.

 

Here are the values for the column-fill property:

 

balance: This is the default value. It attempts to balance the content evenly across columns.

 

auto: Specifies that the browser should fill columns sequentially, regardless of the balance of content.

 

Syntax:

 

column-fill: balance | auto;

 

<head>
    <style>
        div {
            background-color: thistle;
            column-count: 3;
            font-size: 25px;
            height: 200px;
        }

        .container-1 {
            column-fill: auto;
        }

        .container-2 {
            column-fill: balance;
        }
    </style>
</head>

<body>
    <h1>The column-fill Property auto value</h1>
    <div class="container-1">
        Lorem ipsum dolor ...(100 Words)... aliquam.
    </div>

    <h1>The column-fill Property balance value </h1>
    <div class="container-2">
        Lorem ipsum dolor ...(100 Words)... aliquam.
    </div>
</body>

 

CSS column property

 

 

Column-gap property

 

The column-gap property is used to set the gap between columns.

 

Here are the values for the column-gap property:

 

length: You can specify the length of the gap between columns (px, %, and more).

 

normal: This is the default value. Specifies the common spacing between columns.

 

Syntax:

 

column-gap: length | normal;

 

<head>
    <style>
        .container {
            column-count: 4;
            column-gap: 100px;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-gap Property </h1>
    <div class="container">
        Lorem ipsum dolor ...(100 Words)... aliquam.
    </div>
</body>

 

CSS column property

 

 

Column-rule-color property

 

The column-rule-color property is used to specify the color of the rule in the middle of the column.

 

Syntax:

 

column-rule-color: color;
 
<head>
    <style>
        .container {
            column-count: 4;
            column-rule-color: steelblue;
            column-rule-style: solid;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-rule-color Property </h1>
    <div class="container">
        Lorem ipsum dolor ...(100 Words)... aliquam.
    </div>
</body>

 

CSS column property

 

 

Column-rule-style property

 

The column-rule-style property sets the style of the rule between columns.

 

Here are the values for the column-rule-style property:

 

none: No style is applied (default).

 

hidden: The rule is hidden.

 

dotted: The rule is a series of dots.

 

solid: The rule is a solid line.

 

double: The rule is a double line.

 

groove: The rule is a 3D grooved line.

 

ridge: The rule is a 3D ridged line.

 

inset: The rule is a 3D inset line.

 

outset: The rule is a 3D outset line.

 

Syntax:

 

column-rule-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset;

 

<head>
    <style>
        body {
            width: 50%;
        }

        .container {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: dotted;
            column-rule-width: 10px;
            font-size: 25px;
        }

        .container-2 {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: groove;
            column-rule-width: 10px;
            font-size: 25px;
        }

        .container-3 {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: double;
            column-rule-width: 10px;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-rule-style Property </h1>
    <div class="container">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>

    <h1>The column-rule-style Property </h1>
    <div class="container-2">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>

    <h1>The column-rule-style Property </h1>
    <div class="container-3">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>
</body>

 

CSS column property

 

 

Column-rule-width property

 

The column-rule-width property determines the width of the rule between columns.

 

Here are the values for the column-rule-width property:

 

length: Sets the width to a specific length (e.g., pixels).

 

medium: Default value, representing a medium width.

 

thin: Represents a thin width.

 

thick: Represents a thick width.

 

Syntax:

 

column-rule-width: medium | thin | thick;
 
<head>
    <style>
        body {
            width: 50%;
        }

        .container {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: solid;
            column-rule-width: 10px;
            font-size: 25px;
        }

        .container-2 {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: outset;
            column-rule-width: thick;
            font-size: 25px;
        }

        .container-3 {
            column-count: 3;
            column-rule-color: steelblue;
            column-rule-style: inset;
            column-rule-width: thin;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-rule-width Property </h1>
    <div class="container">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>

    <h1>The column-rule-style Property </h1>
    <div class="container-2">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>

    <h1>The column-rule-style Property </h1>
    <div class="container-3">
        Lorem ipsum dolor ...(40 Words)... nam accusamus natus.
    </div>
</body>

 

CSS column property

 

 

Column-rule property

 

The column-rule property is a shorthand for specifying column width, style, and color.

 

column-rule-width: Sets the width between columns (the default is medium).

 

column-rule-style: Sets the style of the rule between columns (the default is none).

 

column-rule-color: Sets the color of the rule between columns (the default is the element's color).

 

Syntax:

 

column-rule: column-rule-width column-rule-style column-rule-color;
 
<head>
    <style>
        body {
            width: 50%;
        }

        .container {
            column-count: 4;
            column-rule: 10px double thistle;
            font-size: 25px;
        }

        .container-1 {
            column-count: 2;
            column-rule: 10px double;
            color: red;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The column-rule Property </h1>
    <div class="container">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dicta ad, ut minus molestiae
        asperiores
        possimus laboriosam! Repudiandae placeat corporis beatae sint nulla tempora quidem provident, veritatis,
        explicabo ratione facere minima deleniti voluptatibus aut nobis, nam accusamus natus.
    </div>

    <h1>The column-rule Property</h1>
    <div class="container-1">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dicta ad, ut minus molestiae
        asperiores
        possimus laboriosam! Repudiandae placeat corporis beatae.
    </div>
</body>

 

CSS column proeprty

 

 

Column-span property

 

The column-span property determines the number of columns an element spans.

 

Here are the values for the column-span property:

 

none: Default value; the element spans one column.

 

all: The element spans all columns.

 

Syntax:

 

column-span: none | all;
 
<head>
    <style>
        .container {
            column-count: 3;
            font-size: 25px;
            background-color: thistle;
        }

        .container-2 {
            margin-top: 100px;
        }

        .heading-1 {
            column-span: all;
        }

        .heading-2 {
            column-span: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1 class="heading-1">The column-span Property all value </h1>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur eaque magnam quidem, possimus
        officia
        sunt. Culpa, explicabo eveniet. Fugiat, nulla itaque. Beatae nihil consectetur amet rem. Quo quia illo
        cumque. Hic asperiores, ex non quas a sunt modi nisi earum nostrum reprehenderit harum et ea obcaecati,
        ipsam vitae autem nulla?
    </div>

    <div class="container container-2">
        <h1 class="heading-2">The column-span Property none value </h1>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur eaque magnam quidem, possimus
        officia
        sunt. Culpa, explicabo eveniet. Fugiat, nulla itaque. Beatae nihil consectetur amet rem. Quo quia illo
        cumque. Hic asperiores, ex non quas a sunt modi nisi earum nostrum reprehenderit harum et ea obcaecati,
        ipsam vitae autem nulla?
    </div>
</body>

 

CSS column property

 

 

Column-width property

 

The column-width property is used to specify the width of the column.

 

Column width is a flexible property. Consider column-width to be a suggestion for the browser's minimum width. The columns will stop and collapse into one column once the browser can no longer fit at least two columns to your specified width. 

 

Here are the values for the column-width property:

 

auto: This value is the default. The width of the column will be set by the browser.

 

length: A length that indicates the column widths. You can set the value in a variety of ways by providing the value in units such as px, %, and more.

 

Syntax:

 

column-width: auto | length;

 

<head>
    <style>
        .container-1 {
            column-width: 200px;
            font-size: 25px;
            border: 1px solid;
        }

        .container-2 {
            column-width: 500px;
            font-size: 25px;
            border: 1px solid;
        }
    </style>
</head>

<body>
    <h1>The column-width Property </h1>
    <div class="container-1">
        Lorem ipsum dolor ... (80 Words) ... vitae.
    </div>

    <h1>The column-width Property </h1>
    <div class="container-2">
        Lorem ipsum dolor ... (80 Words) ... vitae.
    </div>
</body>

 

CSS column property

 

 

Columns property

 

The columns property is a shorthand property for column width and column count.

 

Column width defines the width of each column, while column count defines the maximum number of columns.

 

column-width: This value defines the minimum width for each column.

 

column-count: This value defines the maximum number of columns.

 

auto: This is the default value. This value sets both column-width and column-count to auto.

 

Syntax:

 

columns: auto | column-width column-count;
 
<head>
    <style>
        .container-1 {
            columns: 100px 5;
            font-size: 25px;
        }

        .container-2 {
            columns: 200px 3;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <h1>The columns Property </h1>
    <div class="container-1">
        Lorem ipsum dolor ... (80 Words) ... vitae.
    </div>

    <h1>The columns Property </h1>
    <div class="container-2">
        Lorem ipsum dolor ... (80 Words) ... vitae.
    </div>
</body>

 

CSS column proeprty

 

 

Conclusion

 

Mastering CSS columns lets you create multi-column layouts easily. You can design responsive and visually appealing web pages by learning their various properties, like column-count, column-width, and column-span. Practice with examples to enhance the content presentation on your website.

 

I am sure you have become a master of CSS column properties by now. If you still have any questions about this topic or related to web development, then you can ask us those questions by using the question box given below.

Didn't find your answer? Add your question.

Share

Comments (0)

No comments yet. Be the first to comment!

About Author

Username

Meet Soni ( meetsoni )

Software Engineer

Joined On 13 Feb 2024

More from Meet Soni

Top 10 React Carousel Component Libraries for 2024

react-js

9 Jul 2024

Discover the top 10 React carousel libraries for 2024. Choose the best carousel based on i....

What is the spread operator in JavaScript with example?

javascript

9 Jul 2024

Learn how we can easily manipulate arrays, strings, and objects with the help of the sprea....

Top 4 Ways Centering a Div or Text Inside a Div using CSS

css

4 May 2024

Learn 4 techniques to make it easier to center a div container both horizontally and verti....

20 Amazing CSS Properties You Need to know - Part 2

css

4 May 2024

Learn about such properties of CSS with which you can easily make your website more attrac....

20 Amazing CSS Properties You Need to know - Part 1

css

9 May 2024

Learn 10 CSS properties that many developers do not know about. By understanding these all....

30 Keyboard Shortcuts You Might Not Know for Windows

programming

4 May 2024

Learn 30 Windows shortcut keys that will make it easier to use the system. In this post, w....

Popular Posts from Code Mafias

10 Fun Websites for Stress Relief and Relaxation During Coding Breaks

programming

11 Nov 2024

Top 10 fun websites for coders to relax during breaks. Recharge with interactive games, ar....

Mastering HTML: Top 12 Unique HTML Tags with Examples

html

4 May 2024

Through this article, learn those essential HTML tags that many developers do not know abo....

Top 60 Eye-Catching Button Designs Users Can’t Wait to Click - With Source Code

ui-ux

11 Oct 2024

Discover 60 eye-catching button designs with source code, crafted with HTML and CSS to enh....

How to Upload Code to GitHub: Quick Steps and Detailed Instructions for Beginners

github

16 Sep 2024

In order to upload (push) your project to GitHub, it involves multiple steps that need to ....

How to install MongoDB on windows in 2024

mongodb

2 May 2024

MongoDB is a Database Management System based on NoSQL (Not Only SQL) and utilizes JSON-li....

How to Implement Undo Functionality for Deleting Items in Your React App

react-js

28 Sep 2024

Learn how to implement undo functionality for deleting items in React. Follow a step-by-st....