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

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

CSS allows an HTML element to have multiple classes:

Nibbles

But is there a limit

4条回答
  •  遥遥无期
    2020-12-29 21:40

    You're only limited by the maximum length of an (X)HTML attribute's value, something covered well by this answer.

    Browsers are often very forgiving of standards violations, so individual browsers may allow much longer class attributes. Additionally you are likely able to add a practically infinite number of classes to a DOM element via JavaScript, limited by the amount of memory available to the browser.

    For all intents and purposes, there is no limit. I'm assuming you're asking out of curiosity; it goes without saying that if you're seriously worried about hitting this limit, you've done something very wrong.

提交回复
热议问题