How to display an unordered list in two columns?
To effortlessly create a two-column layout for an unordered list, apply the column-count
CSS property:
Your HTML should be:
This partition your list into two columns, guaranteeing a balance distribution of list items.
Taking advantage of modern CSS
Apart from column-count
, modern CSS gives us a feast of extensive options to prepare multi-column layouts while preserving the semantic structure.
Grid layout to the rescue
Grid layout converges to an elegant solution:
This solution produces a two-column grid for your list items and fares quite well for responsive designs.
Responsive designs and legacy browsers
While wielding modern options, pay critical attention to responsive designs and tailoring to legacy browsers. float: left
combined with a calculated width could serve effectively:
List column magic with JavaScript
For previous-generation browsers that might not support CSS Grid or column-count
, bring in JavaScript to manipulate the DOM effectively:
This logic effectively splits the list in half and distributes the items evenly in two separate columns.
Was this article helpful?