Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS columns Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 29 - Views
⏳ 4 mins
💬 1 Comment
CSS columns Property

Photo Credit to CodeToFun

🙋 Introduction

The columns property in CSS is a shorthand property that allows web developers to set the number and width of columns for an element.

This property is particularly useful for creating multi-column layouts, which can enhance the readability and aesthetics of your content.

💡 Syntax

The syntax for the columns property combines the column width and the number of columns.

Syntax
Copied
Copy To Clipboard
element {
  columns: column-width column-count;
}

🎛️ Default Value

The default value for the columns property is auto auto, which means the browser will automatically determine the width and number of columns based on the content and available space.

🏠 Property Values

ValueDescription
column-widthSpecifies the ideal width of each column. Can be any valid length value (e.g., px, em, %, etc.).
column-countSpecifies the number of columns. Must be a positive integer.

📄 Example

In this example, we'll create a three-column layout with each column being 200 pixels wide.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS columns Example</title>
  <style>
    .multicolumn {
      columns: 200px 3;
    }
  </style>
</head>
<body>
  <h1>Multi-Column Layout</h1>
  <div class="multicolumn">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla convallis egestas rhoncus. Donec facilisis fermentum sem, ac viverra ante luctus vel.</p>
    <p>Ut sit amet massa bibendum, scelerisque velit eu, sodales libero. Maecenas semper lacus nec ligula tincidunt, vitae iaculis nisi faucibus. Sed facilisis suscipit odio, et euismod sapien tincidunt vel.</p>
    <p>Integer convallis libero et ligula ultricies, a bibendum lacus posuere. Vivamus ullamcorper vehicula massa, a efficitur turpis tincidunt vel. Integer eu mauris enim.</p>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The columns property is widely supported in modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. As with any CSS property, it is advisable to test your design across different browsers to ensure consistent behavior.

🎉 Conclusion

The columns property is a powerful and convenient way to create multi-column layouts in your web design.

By specifying the width and number of columns, you can easily control the flow and appearance of your content. Experiment with different configurations to find the best layout for your content and enhance the user experience on your website.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy