xigoi

How to make a minimal website usable

Minimal websites are cool. Most “modern” websites include a lot of unnecessary bloat with tons of tracking scripts and annoying layout elements that take up half of the page. It's nice to get rid of all of this fluff and build a website from the ground up. Even plain HTML is a big improvement; however, the resulting site will look quite ugly and have some usability problems. Here are some little bits of code that can be added to improve the experience without creating another overweight monster.

HTML

Character encoding

ASCII has been obsolete for a long time. We need Unicode, especially if using a different language than English. Put this in your <head> to use the UTF-8 encoding:

<meta charset="utf-8">

Viewport

By default, pages always display in a wide format designed for desktop computers. However, browsing on phones and other smaller screens is common nowadays. To make the page work well on them, put this in your <head>:

<meta name="viewport" content="width=device-width, initial-scale=1">

CSS

Maximum page width

Just like there are small screens, there are also wide screens. And reading text is painful when it spans across your whole Full HD monitor. Consider setting a maximum width for your page like this:

body {
  max-width: 800px;
  margin: auto;
}

If you'd also like to prevent the page from hugging the edge of the screen on narrow devices, you can use something like this:

body {
  width: min(800px, calc(100% - 8px));
  margin: auto;
}

Line height

Text is more readable if it's not tightly pressed on top of itself. Empirical observations suggest that 1.4 is the optimal line height:

body {
  line-height: 1.4;
}

Horizontal scrolling in code blocks

If you're using <pre> elements on your page to include snippets of code, it can easily happen that they're too long to fit on the screen. The default behavior is to make the whole page wider, which is annoying when reading the text outside. Instead, you can allow the code blocks themselves to be scrolled horizontally without affecting what's around them:

pre {
  overflow-x: auto;
}