Create Masonry Layout with CSS (Grid with variable-sized contents arranged in columns)

Source code for examples in my article here.

Grid

  • 👎 doesn't handle variable size

Masonry layout using Grid

Flex

  • 👍 handles variable size
  • 👎 need to set the height of container to wrap items into the second column
  • 👎 doesn't put the second item in second column, rather puts it as the second item in first column

Masonry layout using Flex

Flex (Firefox)

  • 👎 perfect but only in firefox

Masonry layout using Flex in Firefox

column-count

  • 👍 handles variable size
  • 👍 no need to set the height of container to wrap items into the second column
  • 👎 doesn't put the second item in second column, rather puts it as the second item in first column

Masonry layout using column-count