Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there speed benefits of putting CSS attributes in alphabetical order?

Tags:

css

parsing

I hope this question isn't too weird and arbitrary. When I'm viewing some CSS using Firebug, I've noticed that the CSS properties for each tag are in alphabetical order.

Is it trying to tell us something?

Apart from the obvious benefit of being able to find the property you're after more quickly, I was wondering this: Is it quicker for a browser to apply the properties if they are in alphabetical order in the original stylesheet?

For example is this...

body {
  background: #222;
  color: #DDD;
  font-size: 0.85em;  
}

#content {
  background: #444;
  padding: 1em;
}

p {
  border-bottom: 0.9em;
  line-height: 1.2em;
  text-align: justify;
}

...better than this...?

body {
  font-size: 0.85em;
  background: #222;
  color: #DDD;  
}

#content {
  padding: 1em;
  background: #444;
}

p {
  text-align: justify;
  line-height: 1.2em;
  border-bottom: 0.9em;
}

Can this be tested effectively?

This would obviously be replicated throughout the entire stylesheet so would a browser benefit from doing things in order and, if so, would it be worth revisiting past stylesheets to reorder things?

-- edit --

Ok, a slight alteration to my question: What if the attributes are always in the same order for each tag. Background always before border always before color etc and so on (I know I've missed some!) for each and every tag. Alphabetical would aid you in keeping things in order rather than being the optimal method.

Looks like the overwhelming consensus is that it matters not, however!

like image 939
Scott Brown Avatar asked Nov 04 '22 16:11

Scott Brown


1 Answers

There's definitely no speed benefit in ordering your styles alphabetically.

If you want real speed benefits, you should minify your CSS.

There are so many programs to do that, but here's one of them: CSSTidy. This program also has the option to put your styles in alphabetical order (if you want that for your benefit).

like image 94
Joseph Silber Avatar answered Nov 11 '22 14:11

Joseph Silber