58 bytes of css to look great nearly everywhere

58 bytes of css to look great nearly everywhere

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).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.