58 bytes of CSS to look great nearly everywhere

The original page seems to have disappeared from the Internet1 (see: link rot), so the original contents are kept here.

When making this website, I wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;

Let’s break this down.

  • max-width: 38rem It appears that the default font size for most browsers is 16px, so 38rem is 608px. Supporting 600px displays at a minimum seems reasonable.

  • padding: 2rem If the display’s width goes under 38rem, then this padding keeps things looking pretty good until around 256px. While this may seem optional, it actually hits two birds with one stone - the padding also provides sorely-needed top and bottom whitespace.

  • margin: auto This is really all that is needed to center the page, because main is a block element under semantic html5.

A key insight: it took me a surprising number of iterations to arrive at this point. Perhaps that speaks to the fact that I know nothing about “modern” web development, or, as i’m more inclined to believe, just how hard it is to keep it simple in a world of complication.

[!Update] Following some discussion (see footer), I’ve since changed the padding to 1.5rem for a happier compromise between mobile and desktop displays.

[!Update 2] The ch unit was brought to my attention here, and I quite like it! I’ve since changed to 70ch / 2ch, which looks nearly the same with 2 less bytes, except that the padding is a little bit smaller (a good thing for mobile).

  1. A cached version can still be seen, hopefully, at ↩︎