Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

limits

CSS allows an HTML element to have multiple classes:

<div class="cat persian happy big"> Nibbles </div> 

But is there a limit on how many classes are allowed per item?

like image 486
Tony the Pony Avatar asked Dec 04 '10 17:12

Tony the Pony


People also ask

How many classes can an HTML element have?

There is no limit to how many class names you can add to a single HTML element. But keep in mind that you need to keep the class names intuitive and descriptive. I'd recommend you put 10 class names at maximum in a single HTML element to keep your project maintainable.

Can an HTML element have multiple classes?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.

Is there a limit to CSS?

A stylesheet may contain up to 65,534 rules. A document may use up to 4,095 stylesheets.

How many classes are there in CSS?

Multiple classes can be applied to a single element in HTML and they can be styled using CSS. In this article, we will stick to only two classes. But the concepts used in assigning two classes can be extended to multiple classes as well.


1 Answers

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.

like image 95
meagar Avatar answered Sep 21 '22 10:09

meagar