Search code examples
htmlseparatorrfc

What are the valid attributes separators in Hypertext Markup Language?


I.E:

  • <a href="foo.com" class="bar">
  • <a/href="foo.com"/class="bar">

Space and / are two valid separator between href and class.

  • In which RFC is this defined?
  • What are the other valid attributes separators?

Sample: https://jsfiddle.net/yeg58qun/


Solution

  • HTML hasn't been maintained in an RFC document for decades. You can find two slightly incompatible specifications, one a W3C TR and the other maintained by the WHATWG. Most browsers follow their own nebulous intersection of the two.

    The only valid attribute separator is whitespace. This isn't stated normatively in the spec, but one of the parse errors that can be triggered when validating markup is called missing-whitespace-between-attributes:

    This error occurs if the parser encounters attributes that are not separated by ASCII whitespace (e.g., <div id="foo"class="bar">). In this case the parser behaves as if ASCII whitespace is present.

    That last sentence would also explain why your markup seems to work as expected.