CSS Best Practices: XHTML, Defining Classes, Selectors
- Use XHTML - If you are not too familiar with XHTML you can stick to HTML, however, note that by using XHTML you will be ensuring that the website code will not be outdated when HTML is finally phased out. Furthermore using XHTML will allow XML devices to read the code, which is of course a good thing.
- Define general rules and main classes at the top of the stylesheet - This will help you during coding since it will be much easier for you to make any changes. By inserting general rules and/or main classes anywhere you wish to it will make it harder for you to find the information when you need it.
- Use the correct selector type - Make sure you know which selector (elements, ids, or classes) should be used. If you don’t choose the one that’s best for the line(s) of code you are generating you may still come up with the same end result but you will end up with a more complex code and larger CSS file. To choose which selector to use keep in mind that while classes can be used on any kind of HTML element you should use the body <body>, paragraphs <p> and heading <h1> elements to define general rules. Furthermore use ids to style only major portions of the web page.