multiple classes on single element html
css, html
Solution
Short Answer
Yes.
Explanation
It is a good practice since an element can be a part of different groups, and you may want specific elements to be a part of more than one group. The element can hold an infinite number of classes in HTML5, while in HTML4 you are limited by a specific length.
The following example will show you the use of multiple classes.
The first class makes the text `color` red.
The second class makes the `background-color` blue.
See how the DOM Element with multiple classes will behave, it will wear both CSS statements at the same time.
Result: multiple CSS statements in different classes will stack up.
You can read more about CSS Specificity.
CSS
.class1 {
color:red;
}
.class2 {
background-color:blue;
}
HTML
<div class="class1">text 1</div>
<div class="class2">text 2</div>
<div class="class1 class2">text 3</div>
Live demo
Problem
Is it a good practice to use many classes on one single HTML element? For example: ``` <div class="nav nav-centered nav-reversed navbar navigation-block"></div> ``` I don't mean that two or three classes on one element is bad, but how about four, five or even six?