Andy Vaughn

Single-line CSS

This is somewhat of a personal post. “Personal” in the sense that the information is very subjective and not objective. However, I will try and persuade you of my opinion.

“CSS declarations should be written on a single line.” — me

p {font-size: 1.8em; line-height: 1.5; color: #000; margin: 0 0 1.5em;}

…as opposed to:

p {
font-size: 1.8em;
line-height: 1.5;
color: #000;
margin: 0 0 1.5em;
}

Here’s why:

  1. Conventional indenting styles, such as K&R or BSD Kernal Normal Form are originally for scripting or compiled languages that can nest calls. CSS very, very rarely nests declarations.
  2. CSS documents get extremely long, extremely fast.
  3. When scanning or modifying CSS, you search by tag, class, or ID, not by style.
  4. It reduces document size.

I’ve been writing single-line CSS for the last three years, and I’ve found it to be amazingly easier to read, edit, scan, and teach. I suggest trying it.

Check out my CSS and tell me what you think.

Posted by Andy Vaughn on April 5, 2010

Leave a Comment