Tillitsdone
down Scroll to discover

CSS Column-gap Enhance Layout Spacing

The CSS `column-gap` property enhances layout spacing by controlling the gap between columns in flex, grid, and multi-column layouts.

Available options include normal, length, and percentage values.
thumbnail

Introduction

The column-gap property in CSS is a handy tool for web developers. It lets you control the space between columns in different layouts. Originally used in multi-column layouts, it now works with flexbox and grid layouts too.

This property enhances the look and readability of web pages. By defining the gap between columns, developers can create user-friendly and engaging designs.

Specification

The column-gap property is defined in several CSS specifications:

  • CSS Box Alignment Module Level 3: Makes column-gap applicable to multi-column, flexbox, and grid layouts.
  • CSS Grid Layout Module Level 2: Uses column-gap to manage space between grid items.
  • CSS Multi-column Layout Module Level 1: Introduced column-gap for multi-column layouts.

These specifications ensure that layouts are consistent and predictable across different browsers and devices.

Syntax

The column-gap property is easy to use. Here’s the syntax:

/* Keyword value */
column-gap: normal;
/* Length values */
column-gap: 3px;
column-gap: 2.5em;
/* Percentage value */
column-gap: 3%;
/* Global values */
column-gap: inherit;
column-gap: initial;
column-gap: revert;
column-gap: revert-layer;
column-gap: unset;

Values

The column-gap property supports various values:

  1. normal: Uses the browser’s default spacing (usually 1em for multi-column layouts, 0 for others).
  2. <length>: Defines the gap size using length values (e.g., 3px, 2.5em).
  3. <percentage>: Defines the gap size using percentage values (e.g., 3%).

Global values like inherit, initial, revert, revert-layer, and unset offer additional flexibility.

Formal Definition

Here’s a formal definition of the column-gap property:

Initial valuenormal
Applies toMulti-column elements, flex containers, grid containers
InheritedNo
PercentagesRefer to the corresponding dimension of the content area
Computed valueAs specified, with lengths made absolute, and normal computing to zero except on multi-column elements
Animation typeA length, percentage, or calc()

Formal Syntax

column-gap = normal | <length-percentage [0,]>
<length-percentage> = <length> | <percentage>

Examples

Flex Layout

HTML:

<div class="flexbox">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

CSS:

.flexbox {
display: flex;
flex-flow: row wrap;
height: 100px;
column-gap: 20px;
}
.flexbox > div {
border: 1px solid green;
background-color: lime;
flex: 200px;
}
div:nth-of-type(3n) {
flex: 300px;
}

Note: To set vertical space between flex rows, use the row-gap property. The gap shorthand can set both row-gap and column-gap.

Grid Layout

HTML:

<div id="grid">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

CSS:

#grid {
display: grid;
height: 100px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 100px;
column-gap: 20px;
}
#grid > div {
border: 1px solid green;
background-color: lime;
}

Multi-Column Layout

HTML:

<p class="content-box">
This is some multi-column text with a 40px column gap created with the CSS `column-gap` property. Don't you think that's fun and exciting? I sure do!
</p>

CSS:

.content-box {
column-count: 3;
column-gap: 40px;
}

Browser Compatibility

The column-gap property is widely supported across modern web browsers:

  • Google Chrome: Since version 50.0.
  • Firefox: Since version 52.0.
  • Internet Explorer/Edge: Since version 10.0.
  • Opera: Since version 37.0.
  • Safari: Since version 9.0.

See Also

For further reading, check out these resources:

Benefits of Using column-gap

  1. Consistency: Ensures uniform spacing between columns.
  2. Readability: Improves the readability of multi-column text.
  3. Aesthetics: Enhances the visual appeal of your layout.
  4. Ease of Use: Simple to use and manage.

By using the column-gap property, you can create clean, responsive, and visually appealing designs that enhance the user experience.

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.