A Calendar in Three Lines of CSS

A calendar layout can be built with surprisingly little CSS. The trick, as demonstrated in an article on a site with no byline, is a seven-column grid: the day cells are grid items that flow onto it naturally, and the only extra step is pushing the first day into the right starting column with grid-column-start.

Markup questions worth asking

The layout trick is fun, but the markup choice is open to debate:

  • An <ol> beats a <ul> here, since days are clearly ordered.
  • Treating the days as a list isn't a problem — it may even suit the content of the calendar, assuming that content has some semantic meaning.
  • What does feel odd is putting the day-of-the-week titles as the first items in that same list. That feels like it belongs in a separate list.
  • Or the whole thing could be a <table>, given that it's arguably tabular data — you might reasonably want to cross-reference and see every Thursday, for instance.

For another, similar approach, there's the site's collection of CSS Grid starter templates.