HTML class attribute with spaces, it is a W3C valid class?

these are two different classes a & b separated by space. see w3c DOCS

class = cdata-list [CS]

this attribute assigns a class name or set of class names to an
element. Any number of elements may be assigned the same class name or
names. Multiple class names must be separated by white space
characters.


If you have two class

.a { font-weight: bold; }
.b { font-weight: normal; }

and assign in class=”a b” or class=”b a”, then later class will overwrite the prior class having same property, so font weight will be normal.

If you change the CSS definition order,

.b { font-weight: normal; }
.a { font-weight: bold; }

now the later class is bold, so “overwrite the prior class having same property” results font weight bold.

Leave a Comment