sw1337
sw1337

Reputation: 989

HTML validation in Visual Studio 2019?

I'm using the community edition of VS 2019.

I'm just trying to put together a quick static HTML/CSS landing page. I can't figure out how to get the HTML validation to work. I made some syntax mistakes on purpose and it's not underlining anything. I made sure HTML validation was enabled in the options.

What am I missing?

Screenshot showing no highlighting of HTML errors

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <asdasd>
</body>
asdasdas
</html>
gfhfghfh gfhgfh

Upvotes: 1

Views: 991

Answers (2)

Stokely
Stokely

Reputation: 15809

Welcome back to the 1990's world of HTML "tag soup"!

The real reason your page accepts this "markup mess" is because after 2010, the W3C lost its power over the HTML5 standard. Browser vendor "steering committees" at the WHATWG.org then took over the HTML5 standards (Apple, Mozilla, Google, and Microsoft) to speed up implementations with greater flexibility. The W3C had better plans for HTML5, but let this org take over. As a result, they ripped HTML away from the only standard left (SGML) and defined a very loose "living standard" for HTML5 with many inconsistencies that we are now stuck with. It means HTML implementations change constantly in the browsers with no consistent recommendations or any requirement that HTML follow any real agreed upon "Web Standards", structure, or rules. So, we are now back to how things were in 1996 again...tag soup.

If you want to try something more structured, try "XHTML5 polyglot". You have a better chance at using a true markup structure that validates as XML, while using the best of HTML5. You can deliver XHTML5 now in either the HTML syntax using text/html, or the XHTML syntax using application/xhtml+xml. Support is good in most modern browsers.

Upvotes: 0

Jimmy
Jimmy

Reputation: 28386

It's weird to look at, and certainly non-conformant to an XML-based syntax, but it's a renderable HTML file... at least, browsers will handle it fine, incorporating the free-floating text into the DOM tree. For example:

Visual Studio and Chrome showing the posted example code

This behavior is actually defined, even though it technically does create parse errors. When there is content placed after the body tag, it is processed as though it were in the body. Even when it's after the </html> tag, it falls under a similar rule for "after after body", which also appends it to the body contents.

Takeaway: HTML is a messy language and has more flexibility than sanity in how it handles content.

Bonus: one could even claim that you can omit the <html>, <head>, and <body> tags. As long as you have a Doctype, this it's completely valid - it doesn't even trigger a parse error (unlike your original case which is a parse error but still handled); even omitting the doctype will work, but puts the browser into a quirks mode to handle it.

Upvotes: 1

Related Questions