Smashing Magazine is a site I vist almost on a daily basis. They have great articles on writing code, using CSS as well as resources for lots of F REE stuff. Today’s article is 12 Principles For Keeping Your Code Clean by Chris Coyier.
Beautiful HTML is the foundation of a beautiful website. When I teach people about CSS, I always begin by telling them that good CSS can only exist with equally good HTML markup. A house is only as strong as its foundation, right? The advantages of clean, semantic HTML are many, yet so many websites suffer from poorly written markup.
Let’s take a look at some poorly written HTML, discuss its problems, and then whip it into shape! Bear in mind, we are not passing any judgment on the content or design of this page, only the markup that builds it.
He includes the following with good examples and explanations:
- Strict DOCTYPE – while I practice this (using the strict doctype) I do not recommend it for everyone.
- Character set & encoding characters – not using the code for the ampersand will quite often cause validations problems
- Proper indentation – has no bearing on how the page is rendered, but it has a huge effect on the readability of the code.
- Nest your tags properly
- Eliminate unnecessary divs
- Use better naming conventions – rather than a class called bigredtext perhaps important would be more appropriate
- Leave typography to the CSS –
- Class/id the <body>
- Logical ordering
- Just do what you can
You can read 12 Principles For Keeping Your Code Clean on the Smashing Magazine website. At the same time, you might want to sign up for their RSS feed.