Effective CSS Writing

December 4, 2006

CSS writing becomes fun, just like coding becomes poetry when its is optimized and is effective. Here are some quick tips on make CSS go that extra mile of maintainability, clarity and Optimization.

W3C Validation a free service that checks Cascading Style Sheets (CSS) in (X)HTML documents or standalone for conformance to W3C recommendations.
» Validator Link

Use CSS Shorthand
CSS shorthand properties allow authors to specify the values of several properties with a single property

What i do as a practise is keep a ready list of shorthand properties handy on my desk. It helps to refer to the right properties fast.

Structure CSS for effectiveness
HTML Elements
HTML elements can be included in style definitions for optimized and maintainable code instead of defining classes individually

Use of ID and Class with Element Definition
Use ID and class in conjunction with HTML element definition,

When to use ID when to use Class
ID’s should be used only if the definition in the HTML is provided only once in the entire HTML document. ID’s are meant especially for cases where javascript requires to access objects in the document.

Keep it organized, clean
Organize placement of CSS definitions in related block. Further Comments placed for a block of related definitions helps.