2.2.2 [HTML] Section 6.8, Language codes

C0005:

The specification states:

 White space is not allowed within the language-code.

All Document Modes (All Versions)

White space is removed when it is the leading character in the hreflang attribute. White space located elsewhere in the attribute string, or that trails the string, is not removed. When hreflang is accessed from the DOM, trailing white spaces and embedded white spaces are kept.

White space in the lang attribute is handled in the same way.