Breaking the rules - Class

I tried something different. I created two different classes within one element,
e.g (h2 class=“red-text”; class=“larger-text”),
expecting the second class as my output but the result was the opposite; the first class was the output. Why is this so since browsers read HTML from top-bottom and the second instruction takes precedence over the first?


You’re making several assumptions there, but you could always go read the HTML spec. But it could also just be undefined behaviour, potentially different between browsers.

1 Like

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.

I’d stick to applying classes the way you’re supposed to, as @lynxlynxlynx mentioned you’ll run into a lot of issues.

1 Like

I believe doing things the abnormal way is a great way to learn after you have mastered the rule.
I just want to know why the first class became the output instead of the second. Thanks for the reply anyway.

My guess would be that the browsers only looks for the property ‘class=’ once to make sure only valid HTML gets rendered. Might be wrong though this is way out of my league :face_with_hand_over_mouth:

1 Like

Your guess might be valid. But then every browser is expected to read every line of code.

This is not SGML or XHTML, so reading doesn’t guarantee anything. Browsers are also a forest of hacks.

1 Like

With time, i’ll get to know better.