Skip to main content

CSS Multiple Column Layouts

By SamK
0
0 recommends
Topic(s)

The CSS multi-column layout provides a straightforward way to create multiple columns of text, similar to the layout used in newspapers.

CSS Multi-columns Properties

  • column-count - Specifies the number of columns an element should be divided into
  • column-fill - Specifies how to fill columns
  • column-gap - Specifies the gap between the columns
  • column-rule - A shorthand property for setting all the column-rule-* properties
  • column-rule-color - Specifies the color of the rule between columns
  • column-rule-style - Specifies the style of the rule between columns
  • column-rule-width - Specifies the width of the rule between columns
  • column-span - Specifies how many columns an element should span across
  • column-width - Specifies a suggested, optimal width for the columns
  • columns - A shorthand property for setting column-width and column-count

CSS column-count  Property

The column-count property defines how many columns an element should be split into.

div {
 column-count: 3;
}

column-count-demo

CSS column-fill Property

The column-fill property specifies how to fill columns, balance or auto.

div {
 column-count: 3;
 column-fill: balance;
}

Css-column-fill-property-demo

CSS column-gap Property

The column-gap property sets the space between columns.

For instance, the following CSS creates a 60-pixel gap between the columns:

div {
  column-count: 3;
  column-gap: 60px;
}

column-gap property Demo

CSS column rules

The column-rule-style property defines the appearance of the line drawn between columns.

div {
  column-rule-style: solid;
}

column-rule-style Demo

The column-rule-width property sets the thickness of the line between columns. 

div {
  column-rule-width: 2px;
}

column-rule-width Demo

The column-rule-color property specifies the color of the rule between columns:

div {
  column-rule-color: lightgreen;
}

column-rule-color Demo

The column-rule property is a shorthand property for setting all the column-rule-* properties.

The following example sets the width, style, and color of the rule between columns:

div {
  column-rule: 2px solid lightgreen;
}

column-rule-demo

CSS column-span Property

The column-span property determines how many columns an element should span.

For example, the following CSS makes the <h2> element span across all columns:

h2 {
  column-span: all;
}

column-span Property Demo

CSS Column Width

The column-width property sets a recommended width for the columns.

For example, the following CSS suggests an optimal column width of 100 pixels:

div {
  column-width: 90px;
}

CSS Column Width Demo

CSS columns Property

The columns property is a shorthand that combines:

  • column-width
  • column-count
div {
  column-width: 90px;
  column-count: 3;
}

columns-demo

Questions & Answers