1

Will it work faster if I define class with

input.classname

or if I only define

.classname

in CSS?

Ales
  • 527
  • 2
  • 8
  • 24
  • You could try and make a benchmark. Other than that, for the flexibility I believe its better to use `.classname` rather than `element.classname` so you can apply the class on different element. However in some cases you may want to style all the elements in the same way, but one slightly different. The `element.classname` can come in handy. But that could also be done using an other class. – GreyRoofPigeon Jul 15 '13 at 07:03

3 Answers3

3

Technically yes, there is a very slight difference in speed. But you don't need to worry about CSS matching speed. It's microseconds (as in millionths of a second).

What you should worry about is specificity.

See my answer here.

Community
  • 1
  • 1
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

No, CSS rules are matched right to left. That is to say, they will have the same performance.

matt3141
  • 4,303
  • 1
  • 19
  • 24
0

Browsers read CSS selectors from right to left. So I assume that only the classname is faster. I would not tag-qualify classes despite you wanted to have some styling be different depending on the element.

MiRaIT
  • 149
  • 3