CSS: Is there a limit on how many classes an HTML element can have?

前端 未结 4 405
一向
一向 2020-12-29 21:09

CSS allows an HTML element to have multiple classes:

Nibbles

But is there a limit

4条回答
  •  一整个雨季
    2020-12-29 22:03

    There is no technical limit (barring the amount of memory the browser may be consuming), but one should heavily consider having loads of classes on any element as the browser will have to parse all the classes, apply those styles and render the page.

    Also, if you need to search the DOM for elements of a particular class and elements contain loads of classes, you may likely see a performance issue if the JavaScript interpreter has to parse loads of classes.

提交回复
热议问题