19

I'd assume that this would be faster:

#dialog .videoContainer { width:100px; }

than:

.videoContainer { width:100px; }

Of course disregarding that .videoContainer in the first example would only be styled under the #dialog tag.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Ryan
  • 4,354
  • 2
  • 42
  • 78
  • I think you have it backwards... I'm not sure though. If the `#dialog` is not necessary i would not use it – Drew Galbraith Oct 02 '11 at 01:03
  • @Drew - I'm assuming that parsing id's is the fastest it would then only look under #dialog no? – Ryan Oct 02 '11 at 01:05
  • 3
    Google has some good tips on writing selectors: http://code.google.com/speed/page-speed/docs/rendering.html#UseEfficientCSSSelectors – Pat Oct 02 '11 at 01:06

1 Answers1

26

CSS selectors are matched from right to left.

Therefore, .videoContainer should be "faster" than #dialog .videoContainer because it misses out testing for #dialog.

However, this is all irrelevant at best - you'll never notice the difference. For normally sized pages, the amount of time we're talking about is so insignificant as to be nonexistent.

Here's a relevant answer by an expert that you should read: Why do browsers match CSS selectors from right to left?

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349