Opinions for writing good CSS

A great run down of useful advice to help you write good CSS.


This is a fantastic article by Andrew Walpole, packed full of useful and pragmatic advice. I like this part the most:

Specifically, sometimes you need to write some CSS that either you aren’t 100% confident about why you need it. This is the perfect place to express that skepticism in a comment, both for you and anyone else reviewing the code in the future. While there are other good reasons to use comments, including this confidence metadata for a solution opens up quick-win opportunities to revisit things later in an effort to refactor and improve the codebase. It also may signal spots where tough-to-track bugs may appear later.

I’ll add to this that comments are super valuable for explaining a decision to either yourself, 6 months down the line, but most importantly, to a team member that hasn’t got a clue why you’ve done what you’ve done.

You can never write too many comments and code — regardless of how good you think you are — is never self documenting!

Check it out