slowdev

I stopped writing CSS that does nothing

For half a year I carried the same set of rules from project to project. Margin resets, list resets, box-sizing for everything, tidy margin: 0 on headings. Half of it affected nothing: there wasn't a single place in the project where those rules ever applied.

It's easy to check: delete the block and see whether anything changed. Usually it doesn't. But the hand still reaches to copy “battle-tested” CSS, because that feels safer.

What survived the cleanup:

  • box-sizing: border-box — kept, it saves arithmetic.
  • :where() for resets — it doesn't raise specificity, which is convenient.
  • gap instead of sibling margin — fewer conditions in your head.
  • No global element styles apart from body and links.

Instead of resetting lists there simply are no lists that need markers now. Instead of zeroing headings, one class on a text block.

The stylesheet ended up three times shorter. Load time didn't change, but opening it a month later stopped being scary. Sometimes the only optimisation that works is deletion.