Grow your CSS skills. Land your dream job.

Last updated on:

Multiple Columns

Here is an example of a simple three-column class:

.three-col {
       -moz-column-count: 3;
       -moz-column-gap: 20px;
       -webkit-column-count: 3;
       -webkit-column-gap: 20px;
}

Of which you would apply to a block of text like so:

<p class="three-col">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>

Example

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

Note that the height of each column is auto-balanced, as per the spec.

Also note this demo and sample code is using moz and webkit vendor prefixes, should only work in Gecko (Firefox 1.5+, et al.) and Webkit (Safari 3+, Chrome, et al.) browsers. No native support in Internet Explorer or Opera yet that I know of.

All Related Properties

.three-col {
       -moz-column-count: 3;
       -moz-column-gap: 20px;
       -webkit-column-count: 3;
       -webkit-column-gap : 20px;
       -moz-column-rule-color:  #ccc;
       -moz-column-rule-style:  solid;
       -moz-column-rule-width:  1px;
       -webkit-column-rule-color:  #ccc;
       -webkit-column-rule-style: solid ;
       -webkit-column-rule-width:  1px;
}

You can also set the column-width (with prefixes) but it generally makes more sense to let it auto calculate that.

The rule ("rule", as in, a line) will split the gap down the middle. You can use the same values as you would a border.

Take care not to have your text blocks be so enormously tall that they are taller than a (fairly small) browser window, otherwise it's the same problem as text being wider than the browser window (scrolling back and forth to read = sucks). Also consider text-align: justify;

JavaScript Fallback

Is presented in this A List Apart article.

Comments

  1. Permalink to comment#

    just ordinary question like always :-)

    is IE also compatible with this column-count?

    thanks

    • Permalink to comment#

      Hi, I was just refreshing myself on this technique and tested it in a bunch of different browsers. IE 9 and under provide no support to this at all, so you should use a jQuery plugin as a fallback.

      I tested in the IE 10 platform tester and it does indeed work, and without vendor prefixes. I guess better late than never.

    • I’m taking a web design class and everyone else is putting a simple 2 column layout into use and I can’t figure it out. I already get the html part but I can’t seem to figure out how to get the columns to appear on my site/sites. It seems pretty simple but I just don’t get it. I only got 1 column going so far, that’s all I can seem to do so far. I know everything else about the design and the layout of the column (floating, padding, width, etc.) but I can’t get the foundation down. His site is http://www.htmldog.com

  2. Vessel
    Permalink to comment#

    He says in the article..

    “sample code is using moz and webkit vendor prefixes, should only work in Gecko (Firefox 1.5+, et al.) and Webkit (Safari 3+, Chrome, et al.) browser”

    It looks like IE is not a compatible browser at this time.

    • Jack Nycz
      Permalink to comment#

      Still, it degrades nicely to a single column – yet again, IE users get the information in a logical, normal manner, just not as visually pleasing!

    • Permalink to comment#

      It works in IE with the JS fallback.

  3. Permalink to comment#

    The ALA article was from 2005. I wonder if anyone has come up with any new fallback scripts in the last six years. Mainly for IE since probably 99.9997% of other CSS browsers in use these days probably support the multi-column layout module.

    • Permalink to comment#

      Yes, in fact this doesn’t work in IE9 either, and the scripts from that article are from the early ’00s

  4. Permalink to comment#

    who cares of IE6 :P

    IE is losing market anyway.. bring on the CSS2.1 + :)

  5. Permalink to comment#

    good, nice artical

  6. Matt

    This seems to work in the latest version of Opera. Using Opera 11.10 and Dragonfly I was able to apply the css. Here is a <a href="http://dl.dropbox.com/u/886672/css-tricks/multiple-columns-works-in-opera.png">screenshot</a&gt;

    • Permalink to comment#

      -moz-column-count:2; /* Firefox /
      -webkit-column-count:2; /
      Safari and Chrome */
      column-count:2;

  7. Gigi
    Permalink to comment#

    Does this work with just text? Or can one use images along with text? Fairly newcomer so excuse the seemingly silly ?

  8. I wrote a blog article on this just the other day :) Great Stuff. Wish it had IE support though…

  9. j.logan
    Permalink to comment#

    Another jquery fallback can be found here: http://welcome.totheinter.net/columnizer-jquery-plugin/

    I just started looking into this tonight, so i haven’t had much of a chance to test it…..have no idea if its a better option than the ALA thing

  10. Alec
    Permalink to comment#

    Is it me or is the text blurred, for a site which aims to teach, maybe you should get that sorted out.

  11. Just gotta be careful about applying columns to more than one paragraph as Webkit browsers will wrap margin around to the next column making it look wonky. That behaviour pretty much makes them unusable for me.

    This is a 2.25 year old problem as described here, and somehow not improved since

  12. sarfaraz
    Permalink to comment#

    http://welcome.totheinter.net/columnizer-jquery-plugin/

    chk this might help i was looking for same.

  13. Useful tip, but sad on “No native support in Internet Explorer or Opera yet that I know of”.

  14. Shirish - HTML Developer

    Is it working in “webpage print.” I checked it with same css property, but not working. If anyone aware with print option let me know.

  15. karthick
    Permalink to comment#

    Its working good.

    What happens if the content is too large. I need to find the number of columns if the content is too large. I have implemented a slider but its keep on sliding have to stop with last content.

  16. AgusP

    These property not working all in FF!! bastard

  17. Permalink to comment#

    Just wrote about this and used Codepen to embed a working example but need to fix the width so the pen works. The code works in WordPress but not in the Pen. http://wpsites.net/web-design/style-content-columns/#Add_Simple_Hover_Effect

    How do i do this?

  18. I tried using this today and the example given here is not a good one. If you apply the columns-count to multiple paragraphs (which is the most probable case), it will break the paragraphs in to columns instead of the whole area. It becomes very hard to read. So what you should do is apply it to a whole div / section.

    • Permalink to comment#

      I would disagree. The example is very good. It’s clear, concise and works great used in the example the author has provided. You simply have a different need, and the class can be applied very easily to any element you require (such as an enclosing div). “What you should do” is apply the lesson as needed. :)

  19. Nice Article. This was right what i was looking for. Somehow I wonder if it would make sense for blog post to increase readability on large desktop screens.

  20. Philippe Verdy
    Permalink to comment#

    This page suggests using column count and leave the browser compute the column width.
    But experience shows that adaptation to various redering devices and better adaptation to the content is exactly the OPPOSITE !

    You should better specify the column-width and not specify at all the colmun-count !

    There are good reasons for that:
    – The content can only be rendered according to some minimum widths of some elements.
    – Easier reasing for text column is when columns do not exceed about 40 em (36 em is fine)
    – in this width of 36 to 40em, it remains possible to insert illustration images
    – for narrow lists, items are generally short and typical list of toponyms or people names will fit very well in all cases within 18 em
    – the browser will then compute the number of columnns that can fit in the rendering window: best experience is when you use the full width of the screen each time as possible because it avoids scrolling.
    – if you specify a number of columns, space will be either wasted on large screens (notably on notebooks and HDTV) so they’ll need to scroll down to read the content,, or lines of text will be too long for easy reading or the columns will be to narrow to fit the content very well, and reading will be also difficult or illustration images will no longer fit.

    When the browser computes the number of columns with this initial width, it would remain unused space to the right, but the browser will then distribute that space equally on this number of columns.
    – If only 2 columns can fit and not the third one it means that up to one half of a column wil lbe added to each column, so the minimal colmun-width of 18 em specified will become an effective colmuns width of 27 em, which is still reasonnably easy to read.
    – If only 1 column can fit in the specified width, there could up to 36 em in the only column remaining: you reach the limit that human brain and eye can read a text (36 em is about 80 characters, i.e. the typical number of columns on a terminal or on a printed text with font size 13 pt on a standard A4 or letter page in portrait mode).
    – now if the screen is so narrow that a single column of 18 em cannot fully fit, the browser will start reducing it, but the reduction will never reach zero (otherwise the terminal would not even be usable at all, even the smallest terminals, i.e. smartphones in portrait mode, offer a display area allowing to read about 40 characters, i.e. about 18 to 20 em.

    So effectively I suggest using ALWAYS column-width: 36 em for paragraphs of text, and column-width never lower than 9 em for narrow lists of toponyms, or people names, or phone numbers. If you know the datatype of elements in a list and its expected length, you may use a narrower width (count about 0.5em per character).

    Abandon completely the idea of using column-count, this is not nice at all !

    But don’t forget to specify a column gap: it should be about 1em (use 0.5em to 2em only if you decide to use column-rule, and use only 1 px column-rules, either in colid or dotted styles (avoid dashed).

    Summary:

    { column-width: 18em; column-gap: 1em; } without rules, or

    { column-width: 18em; column-gap: 0.5em; column-rule: 1px solid; }

    Forget playing with other options.

    Now it will be time to think about somethin else! pass time controlling column breaks inside elements where they are undesirable: notably it is often undesirable to have a table row being split across columns of a multi-columns layout. Style your “tr” elements with “column-break-inside : avoid”. You should also control page breaks inside the same elements, if possible (ideally we should be able to avoid horizontal column or page breaks within colgroups of tables, but unfortunately the CSS3 module still offers no support for that; what this means is that you should design your data tables so that they will fit cleanly within a single colmun of 36 em. Otherwise create tables one below the other (and don’t use them in a multi-column container.

    Make sure that all your pages look OK with a 150% zoom level, on a smartphone. Look at how it behaves on a wide notebook, or in a very large and tall HDTV, seen at about 3 meters of distance. My suggestions work great on all devices, and with all assistive settings like zoom level.

    Try first using my suggestions for your contents: it should work on all browsers. on all devices except when a user use very high levels of zoom (but this is not their normal reading experience

    You’ll also see that for printed documents at font sizes of 9pt smaller than on screen at 12pt, 18em is also an excellent choice as it saves paper ! This saving is even more important if you print in landscape orientation: you can fit more column, and the rendered column width is nearer from the ideal line sizes !
    The small print of footnotes (when you hae many of them, will fit in more columns that won’t eat a lot of the page surface and users can read more text in the main section of your document without having to read footnotes or turning pages.

    And please press the browser editors by submitted your bugs so they correct the quirks in the CSS multi-column module. Cast your bugs if browsers fail to render your multicolmuns contents correctly with my suggestion.

  21. Mike
    Permalink to comment#

    Checking this page April 2, 2014, using IE 11 on Windows 7 . . . no columns.

  22. it’s all cool but.. it’s not the same that Wookmark for example because if you want to print out your articles by date this feature will not help you – old posts will be shawn at the top of the page

  23. Harry
    Permalink to comment#

    Hi, this is a simple but elegant solution, but on narrow screens the columns are very squeezed (in a responsive design).

    Is there a way to add something like a column-min-width=250px, so that if the screen/container is smaller than that, then the content will be shown as one column (or the 2nd column will move below the 1st)?

    Thanks!

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

```
<div>Example code</div>
```

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".