Tillitsdone
down Scroll to discover

Understanding CSS column-fill for Multicolumn Layouts

CSS column-fill controls content distribution in multicolumn layouts.

Use it to balance or sequentially fill columns.

Options include 'balance', 'auto', and 'balance-all'.
thumbnail

Introduction

The column-fill property in CSS is a handy tool for managing how content is split across columns in a multicolumn layout. It controls whether columns are filled one by one or if content is evenly spread out. Mastering column-fill can make your web designs more readable and visually appealing, which is super important for web developers and designers. Let’s dive into the syntax, values, and how to use this property effectively.

Specification

The column-fill property is part of the CSS Multi-column Layout Module Level 1. This specification defines how content is divided and balanced across multiple columns. By following this specification, you can ensure your content is neatly organized across columns, making your web design clean and user-friendly.

Description

The column-fill property in CSS helps you manage how content is distributed within a multicolumn layout. It lets you control whether columns are filled one after the other or if the content is balanced evenly across all columns. Using column-fill can make your layouts more visually appealing and readable, perfect for content-heavy pages like articles, blogs, or documentation.

Syntax

The column-fill property is easy to use. It accepts two main values: auto and balance, along with some global values. Here’s the basic syntax:

/* Keyword values */
column-fill: auto;
column-fill: balance;
/* Global values */
column-fill: inherit;
column-fill: initial;
column-fill: revert;
column-fill: revert-layer;
column-fill: unset;

The default value is balance, which means the content will be evenly split across columns. The auto value fills columns one by one, which might leave some columns empty if there isn’t enough content.

Values

The column-fill property has several values that determine how content is distributed across columns:

  • auto: Fills columns one at a time. Content takes up only the space it needs, possibly leaving some columns empty.
  • balance: Divides the content evenly between columns. In fragmented contexts, like paged media, only the last fragment is balanced.
  • balance-all: Divides the content evenly between the columns. In fragmented contexts, all fragments are balanced.
  • initial: Sets the property to its default value, which is balance.
  • inherit: Inherits the column-fill property from its parent.
  • revert: Resets the property to the user agent’s default value.
  • revert-layer: Resets the property to the user agent’s default value for the relevant layer.
  • unset: Resets the property to its natural value, acting as inherit if the property is inherited, or as initial if it is not.

Examples

Balancing Column Content

HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Balancing Column Content</title>
<style>
p {
height: 7em;
background: #ff9;
columns: 3;
column-rule: 1px solid;
}
p.fill-auto {
column-fill: auto;
}
p.fill-balance {
column-fill: balance;
}
</style>
</head>
<body>
<h1>Balancing Column Content</h1>
<h2>column-fill: auto</h2>
<p class="fill-auto">
This paragraph fills columns one at a time. Since all of the text can fit in the first column, the others are empty.
</p>
<h2>column-fill: balance</h2>
<p class="fill-balance">
This paragraph attempts to balance the amount of content in each column.
</p>
</body>
</html>
Result

In this example, two paragraphs demonstrate the auto and balance values of the column-fill property.

  • column-fill: auto: The first paragraph fills the columns sequentially. Since all the text fits in the first column, the other columns remain empty.
  • column-fill: balance: The second paragraph attempts to balance the content evenly across all columns, creating a more uniform and visually appealing layout.

Additional Examples

<!DOCTYPE html>
<html lang="en">
<head>
<title>Additional Examples</title>
<style>
.column-container {
height: 300px;
border: 1px solid #ccc;
margin-bottom: 20px;
}
.column-fill-auto {
column-count: 3;
column-fill: auto;
}
.column-fill-balance {
column-count: 3;
column-fill: balance;
}
</style>
</head>
<body>
<h1>Additional Examples</h1>
<h2>column-fill: auto</h2>
<div class="column-container column-fill-auto">
This is a long paragraph that will be divided into multiple columns.
The content will fill the first column completely before moving to the next column.
Since the content is relatively short, the remaining columns may be empty.
</div>
<h2>column-fill: balance</h2>
<div class="column-container column-fill-balance">
This is a long paragraph that will be divided into multiple columns.
The content will be evenly distributed across all columns, ensuring that each column has approximately the same amount of text.
This creates a visually balanced layout that is easy to read.
</div>
</body>
</html>

Result

In this example, two div elements demonstrate the auto and balance values of the column-fill property.

  • column-fill: auto: The first div fills the columns sequentially. Since the content is relatively short, the remaining columns may be empty.
  • column-fill: balance: The second div evenly distributes the content across all columns, creating a visually balanced layout that is easy to read.

Interactive Example

<!DOCTYPE html>
<html lang="en">
<head>
<title>Interactive Example</title>
<style>
.column-fill-example {
column-count: 3;
column-fill: balance;
height: 600px;
border: 1px solid #ccc;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>Interactive Example</h1>
<h2>Click the buttons to see different column-fill values</h2>
<button onclick="document.querySelector('.column-fill-example').style.columnFill = 'balance'">Balance</button>
<button onclick="document.querySelector('.column-fill-example').style.columnFill = 'auto'">Auto</button>
<button onclick="document.querySelector('.column-fill-example').style.columnFill = 'initial'">Initial</button>
<button onclick="document.querySelector('.column-fill-example').style.columnFill = 'inherit'">Inherit</button>
<div class="column-fill-example">
This is a long paragraph that will be divided into multiple columns.
The content will be distributed based on the selected column-fill value.
Click the buttons to see how the content is affected by different values.
This creates an interactive way to understand the column-fill property.
</div>
</body>
</html>

Result

In this interactive example, you can click the buttons to see how the content is distributed based on different column-fill values. This allows you to experiment with the column-fill property and observe its effects in real-time, enhancing your understanding of how it works.

Formal Definition

The column-fill property has specific characteristics:

  • Initial Value: balance
  • Applies To: Multicol Elements
  • Inherited: No
  • Computed Value: As Specified
  • Animation Type: Discrete

Formal Syntax

The column-fill property follows this syntax:

column-fill = auto | balance | balance-all | inherit | initial | revert | revert-layer | unset;

Specifications

The column-fill property is defined in the CSS Multi-column Layout Module Level 1. This module specifies how content should be divided and balanced across multiple columns, providing web developers with the tools needed to create well-organized and visually appealing multicolumn layouts.

The specifications for the column-fill property are as follows:

  • CSS Multi-column Layout Module Level 1: This specification outlines the behavior and usage of the column-fill property, detailing how it controls the distribution of content within columns. It explains the different values (auto, balance, and balance-all) and their effects on the layout.

By adhering to these specifications, developers can ensure that their multicolumn layouts are consistent and provide a high-quality user experience. The CSS Multi-column Layout Module Level 1 is an essential reference for web developers looking to implement advanced column-based designs.

Browser Compatibility

Ensuring that your web designs are compatible with various browsers is crucial for providing a consistent user experience. The column-fill property has varying levels of support across different browsers, and it’s important to be aware of these differences when implementing multicolumn layouts.

Here’s an overview of the browser compatibility for the column-fill property:

  • Google Chrome: The column-fill property is supported in Chrome version 50.0 and above.
  • Mozilla Firefox: Firefox supports the column-fill property starting from version 52.0.
  • Microsoft Edge: Edge supports the column-fill property from version 12.0 onwards.
  • Opera: Opera supports the column-fill property from version 37.0 and above.
  • Safari: Safari supports the column-fill property starting from version 9.0.

Browser Support

BrowserVersionRelease Date
Google Chrome50.0Apr 2016
Mozilla Firefox52.0Mar 2017
Microsoft Edge12.0Sep 2012
Opera37.0May 2016
Safari9.0Sep 2015

Interoperability Issues

While the column-fill property is generally well-supported, there are some interoperability issues and bugs across different browsers due to unresolved issues in the specification. It’s important to test your multicolumn layouts in multiple browsers to ensure consistent behavior.

Best Practices

  1. Set Heights: Always define a height for your multicolumn containers when using column-fill: auto to avoid issues in Chrome.
  2. Test in Different Browsers: Regularly test your layouts across various browsers to spot and fix inconsistencies.
  3. Use Fallbacks: Have backup layouts for browsers that don’t fully support column-fill.

FAQs

What does the column-fill property do in CSS?

The column-fill property controls how content is distributed across columns in a multicolumn layout.

What are the values for column-fill?

  • balance: Distributes content evenly across columns.
  • auto: Fills columns sequentially.
  • balance-all: Ensures all fragments are balanced.
  • initial: Sets the property to its default value.
  • inherit: Inherits the property from the parent element.
  • revert: Resets the property to the user agent’s default value.
  • revert-layer: Resets the property to the user agent’s default for the relevant layer.
  • unset: Resets the property to its natural value.

How does column-fill: balance work?

column-fill: balance divides content evenly between the columns, making them similar in height.

When should I use column-fill: auto?

Use column-fill: auto when you want content to flow naturally from one column to the next without balancing column heights.

Can I animate the column-fill property?

No, the column-fill property is not animatable.

Are there any browser compatibility issues with column-fill?

Yes, there are some issues. Chrome requires a defined height for column-fill: auto, while Firefox always uses this property, potentially leading to unexpected layouts.

How can I ensure browser compatibility with column-fill?

Always define a height for multicolumn containers, test layouts in different browsers, and use fallbacks for browsers that don’t fully support column-fill.

Related Properties

Understanding related properties can help you create better multicolumn layouts:

column-count

Defines the number of columns in a layout.

column-count: 3;

column-width

Sets the optimal width for columns.

column-width: 200px;

column-gap

Defines the space between columns.

column-gap: 20px;

column-rule

Adds a line between columns.

column-rule: 1px solid #ccc;

column-span

Allows an element to span across multiple columns.

column-span: all;

break-inside

Controls whether an element can break inside a column.

break-inside: avoid;

Using these properties effectively can enhance your multicolumn layouts.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.