As with HTML, novices often make mistakes when writing CSS. Common student errors in writing CSS include:
- Failing to properly punctuate statements. Just as HTML requires ending tags, in CSS each statement begins and ends with curly brackets ({}), and each individual style declaration ends with a semi-colon (;). If one of these punctuation marks is omitted, problems will result.
- Spelling or typographical errors. Simple errors, such as a style declaration of h1 {font-size:18ps;} instead of h1 {font-size:18px;}, will result in a lack of implementation of the intended style.
- Confusing classes and IDs. As noted above, class selectors and ID selectors are two methods for defining style elements. Classes are designed for to be applied to multiple elements or in multiple situations, whereas IDs are intended for a single, specific element that is ordinarily used just once.
- Redundancy. As style sheets grow in size, it is not uncommon for redundant or repetitious style declarations to spring up. These can create issues with functionality, for example, if you have two different style declarations for one element. Even when they do not create issues with functionality, they create inefficiencies by increasing the size of the code and requiring extra effort to maintain. Avoid redundant or repetitive style declarations.
- Using inline styles. As we have noted, inline styles are not recommended because they run counter to the purpose of CSS to separate formatting from functional organization. It is best to avoid them altogether if possible.