Jens Oliver Meiert

5 CSS Tips Every Web Developer Should Know About

Published on Nov 11, 2008 (updated Dec 17, 2023), filed under (feed). (Share this on Mastodon or Bluesky?)

Of all the tips this site shares, the following ones may be special. Let’s quickly run through what might be essential for every web developer to know about CSS. Main focus: maintainability, though differently.

  1. Reference only one style sheet in the markup. Instead of including x style sheet references in every document, include one (meaning one) and import any other style sheets from there, or, even better in complex projects (to avoid unnecessary HTTP requests), have that one style sheet generated out of other style sheets.

  2. Specify media types within style sheets, not markup. Do not use the media attribute on link elements—or anywhere in the HTML—but instead specify media types either when importing or through @media rules.

  3. Use appropriate ID and class names. Avoid them, use functional names, fall back to generic or neutral names, and keep them as short as possible but as long as necessary.

  4. Avoid “reset” style sheets unless you customize them. Reset style sheets come with two disadvantages: unnecessary code (mostly due to rules that reset styling of elements that aren’t used at all) and redundant code (due to declarations that later get overwritten). Reset style sheets that cannot even be tailored are certain to introduce both problems, and since most styling differences are easy to spot anyway, it is usually best not to use resets at all.

  5. Structure rules and declarations. Sort and group by selectors, use declarations just once (at least within “modules”), alphabetically sort declarations, and comment wisely. Be careful not to overdo it.

At the end of the day, web development is about probabilities, which is exactly the reason for the first three tips that all aim to minimize the likelihood of HTML changes. To be continued.

About Me

Jens Oliver Meiert, on November 9, 2024.

I’m Jens (long: Jens Oliver Meiert), and I’m a web developer, manager, and author. I’ve worked as a technical lead and engineering manager for small and large enterprises, I’m an occasional contributor to web standards (like HTML, CSS, WCAG), and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)