The following HTML is right or wrong?
<div class="navbar" class="menu">foo</div>
Do the 2 classes both work?
To specify two classes you can give space between them like
<div class="navbar menu">foo</div>
class
is not a tag but an attribute. Having multiple attributes of the same name is an error.
[...]; if there is already an attribute on the token with the exact same name, then this is a duplicate-attribute parse error and the new attribute must be removed from the token.
https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state
Usually browsers will just ignore the second attribute. So in your case, class="menu"
is ignored and only the navbar
class is applied. To use both classes write class="navbar menu"
.