Why is the doctype a different color from the <html> tags?

Question

Why is the doctype a different color from the tags?

Answer

Line one is not actually an HTML element or tag. As you discovered in the first exercise of this lesson, it is a declaration that lets the browser know that it is looking at an HTML5 document and it should be parsed accordingly.

Text editors like the one you are using in this workspace often use different colors to help developers distinguish between different pieces of code and to aid in overall readability.

34 Likes

Does that mean a browser can “see” and purposely pays attention to/reads any or all text in an HTML document that isn’t HTML? Or does it ignore everything except for the doctype (or perhaps other certain types of declarations/notes/etc)?

The browser doesn’t see, but it does parse raw text for recognizable HTML elements. We should note that the document as a whole is actually XML, of which HTML is a subset. Since the doctype declaration is outside of the <html></html> element, it is XML.

1 Like