How many number of CSS classes can be assigned for an HTML element.
-
5You intend to store your database as CSS classes or what? – Darin Dimitrov Sep 06 '10 at 06:51
-
Some interviewer asked me like this.And i want the exact number of it which browser support how many classes. – Ugesh Gali Sep 06 '10 at 06:54
-
13It's a horrible interview question. There's no reason why anybody would need to *know* this. For all practical intents and purposes, if you're using more than 5 on a single element, then most likely you're doing something wrong. – Yi Jiang Sep 06 '10 at 06:58
-
+1 on "it's a horrible interview question". – janosrusiczki Sep 06 '10 at 06:59
-
1I thought it was good practice to create a class for each and every styling, then add that class to the element? class=" fontred sizelarge alightleft5px alignright150px" /end scarcasm – Sphvn Sep 06 '10 at 07:01
-
1I guess the interviewer was expecting an answer: "infinity unless the browser has a practical limitation". If this is not the answer he is expecting then don't join the company. If the company hired him then it must be full of such idiots. – sv_in Sep 06 '10 at 08:17
-
possible duplicate of [CSS: Is there a limit on how many classes an HTML can have?](http://stackoverflow.com/questions/4354921/css-is-there-a-limit-on-how-many-classes-an-html-can-have) – user229044 Jan 17 '14 at 14:36
5 Answers
I don't think there's a limit. A quick Google search yielded this.

- 1,920
- 2
- 20
- 41
-
5Good find. For those who don't want to click the link, the answer is "over 2000" – mpen Sep 06 '10 at 06:56
-
And even then, is this a limit on the number of classes or the length of the class string? – froggythefrog Oct 11 '19 at 18:31
The standard does not specify any limitation, but individual browsers may have practical ones.

- 278,309
- 50
- 514
- 539
There are no such limitations imposed by the specification:
class
The attribute, if specified, must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.
A set of space-separated tokens is a string containing zero or more words separated by one or more space characters, where words consist of any string of one or more characters, none of which are space characters.of which are space characters.

- 1
- 1

- 72,802
- 19
- 102
- 127
I'm pretty sure IE6 only supports up to 2. Modern browers have no limit as far as i know.

- 84,970
- 20
- 145
- 172

- 21
- 2
One of the lesser known tricks with CSS is the fact that you don't have to limit your elements to just one class. If you need to set multiple classes on an element, you add them simply by separating them with a space in your attribute. For example:
<p class="pullquote btmmargin left">...</p>
So there is no limit on no of classes you apply.

- 175,020
- 35
- 237
- 263
-
yes so the ans is there is no limit on no of classes you apply on one element – Pranay Rana Sep 06 '10 at 07:01
-