Column layouts

You will often need to create a layout which has a number of columns, and CSS provides several ways to do this. Whether you use Grid, Flexbox or Multi-column layout will depend on what you are trying to achieve, and in this recipe we explore these options.

three different styles of layouts which have two columns in the container.

Requirements

There are a number of design patterns you might want to achieve with your columns:

  • A continuous thread of content broken up into newspaper-style columns.
  • A single row of items aranged as columns, with all heights being equal.
  • Multiple rows of columns lined up by row and column.

The recipes

You need to choose different layout methods in order to achieve your requirements.

A continuous thread of content — multi-column layout

If you create columns using multi-column layout your text will remain as a continuous stream filling each column in turn. The columns must all be the same size, and you are unable to target an individual column or the content of an individual column.

You can control the gaps between columns with the column-gap property, and add a rule between columns using column-rule.

Download this example

Use multicol when:

  • You want your text to display in newspaper-like columns.
  • You have a set of small items you want to break into columns.
  • You do not need to target individual column boxes for styling.

A single row of items with equal heights — flexbox

Flexbox can be used to break content into columns by setting flex-direction to row, however flexbox targets the elements inside the flex container and will place each direct child into a new column. This is a different behavior to what you saw with multicol.

There is currently no way to add a rule between flex items, and browser support for the column-gap and row-gap properties is limited. Therefore to create gaps between items use a margin.

Download this example

Flexbox can also be used to create layouts where the flex items wrap onto new rows, by setting the flex-wrap property on the container to wrap. These new flex lines will distribute space along that line only — the items in the new line will not line up with items in the line above, as you'll see in the example below. This is why flexbox is described as one-dimensional. It is designed for controlling layout as a row or a column, but not both at the same time.

Download this example

Use flexbox:

  • For single rows or columns of items.
  • When you want to do alignment on the cross axis after laying out your items.
  • When you are happy for wrapped items to share out space along their line only and not line up with items in other lines.

Lining items up in rows and columns — grid layout

If what you want is a layout where items line up in rows and columns then you should choose CSS Grid Layout. Grid Layout works on the direct children of the grid container in a similar way to the manner in which flexbox works on the direct children of the flex container, however with CSS Grid you can line your items up in rows and columns — it is described as two-dimensional.

Download this example

Use Grid:

  • For multiple rows or columns of items.
  • When you want to be able to align the items on the block and inline axes.
  • When you want items to line up in rows and columns.

Browser compatibility

The various layout methods have different browser support. See the charts below for details on basic support for the properties used.

column-width

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

50

Yes -webkit-

12

12 -webkit-

50

1.5 -moz-

1011.13 -webkit-
Intrinsic sizes No ? No No No No
On display: table-caption Yes Yes37 Yes Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes

50

Yes -webkit-

Yes

Yes -webkit-

50

4 -moz-

Yes Yes

5.0

Yes -webkit-

Intrinsic sizes No ? ? No No No ?
On display: table-caption Yes50 Yes37 Yes Yes5.0

column-rule

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

50

Yes -webkit-

12 -webkit-

52

3.5 -moz- 1

10

11.1

15 -webkit-

3 -webkit-
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes

50

Yes -webkit-

?

52

Yes -moz-

? ?

5.0

Yes -webkit-

1. Before Firefox 3, the default value for the normal keyword was 0 and not 1em.

flex

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

29

21 -webkit-

12

12 -webkit-

201 2

20 — 613

49 -webkit-

44 -webkit- 4

18 — 285

116 7

10 -ms- 8 9

12.1

9

6.1 -webkit-

FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support

29

21 -webkit-

29

25 -webkit-

Yes

Yes -webkit-

?12.1

Yes

7.1 -webkit-

?

1. Since Firefox 28, multi-line flexbox is supported.

2. Before Firefox 32, Firefox wasn't able to animate values starting or stopping at 0.

3. Flex items that are sized according to their content are sized using fit-content, not max-content.

4. From version 44: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.

5. From version 18 until version 28 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

6. Internet Explorer 11 ignores uses of calc() in the flex-basis part of the flex syntax. This can be worked around by using the longhand properties instead of the shorthand. See Flexbug #8 for more info.

7. Internet Explorer 11 considers a unitless value in the flex-basis part to be syntactically invalid (and will thus be ignored). A workaround is to always include a unit in the flex-basis part of the flex shorthand value. See Flexbug #4 for more info.

8. Internet Explorer 10 and 11 ignore uses of calc() in the flex-basis part of the flex syntax. This can be worked around by using the longhand properties instead of the shorthand. See Flexbug #8 for more info.

9. Internet Explorer 10 and 11 consider a unitless value in the flex-basis part to be syntactically invalid (and will thus be ignored). A workaround is to always include a unit in the flex-basis part of the flex shorthand value. See Flexbug #4 for more info.

flex-wrap

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

29

21 -webkit-

1228111179
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support

29

21 -webkit-

29

25 -webkit-

125212.19.2 ?

1. Partial support due to large number of bugs present. See Flexbugs.

grid-template-columns

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

57

291

16

52

402

No

44

283

10.1
minmax()

57

291

12

52

402

?

44

283

10.1
repeat()

57

Yes4

16

57

52 — 575

Yes — 526

No

44

Yes7

10.1
fit-content()291651 No4410.1
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support57

57

291

16

52

402

4410.36.0
minmax() No ?12

52

402

No10.3 ?
repeat() ? ? No

57

52 — 575

Yes — 526

?10.3 ?
fit-content()575716514410.37.0

1. From version 29: this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.

2. From version 40: this feature is behind the layout.css.grid.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

3. From version 28: this feature is behind the Enable experimental Web Platform features preference.

4. This feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.

5. calc() doesn't work in repeat() (see bug 1350069).

6. Until version 52 (exclusive): this feature is behind the layout.css.grid.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

7. This feature is behind the Enable experimental Web Platform features preference.

Resources on MDN

Document Tags and Contributors

Contributors to this page: rachelandrew, chrisdavidmills
Last updated by: rachelandrew,