GithubHelp home page GithubHelp logo

Comments (6)

sideshowbarker avatar sideshowbarker commented on June 2, 2024 7
<!DOCTYPE html>
<html lang="en">
Some text
</html>
Element head is missing a required instance of child element title.

There's no head element, so it can't miss anything.

Open that source in a browser devtools and what you’ll see is that there is in fact a head element in that document. (And what’s more, there’s also a body element in that document.)

It’s important to understand this.

It’s true that in the source above there is no <head> start tag nor </head> end tag — but the head element is still there.

It’s important to understand the difference between elements and tags. For some elements, the start tags and end tags can be omitted. For the head element, both the start tag and the end tag can be omitted.

But even in a document where the head element’s start tag or end tag are both omitted, that document still has a head element. Every HTML document has a head element — even if the head element has no contents (like the one above).

Consider the following document served as text/html:

Some text

That’s the entire source for the document. It has no markup in that source — no tags at all. But if it’s served as text/html and parsed by an HTML parser, it in fact contains three elements: an html element, a head element, and body element.

If you want confirmation of that fact:

  1. Create a completely empty file named foo.html (or whatever)
  2. Put just the text Some text into that file
  3. Open that foo.html file in a browser (any browser).
  4. Open the inspect in devtools in the browser.
  5. Look at what it shows.

If you do the steps above, you’ll see that the HTML document represented by the source above is identical to the document represented by this source:

<html><head></head><body>Some text
</body></html>

The start tags and end tags for the html, head, and body elements are all optional. So the only difference between the source in the above two cases is that in the first case, the start tags and end tags have been completely omitted. But it’s still the same document.

In other words, for understanding HTML documents, it’s important — and even necessary — to not just consider the source but to instead consider what an HTML parser does with that source when it creates an actual HTML document from it.

It’s also important to understand that the HTML checker (validator) doesn’t just look at the source it’s given; instead the checker first parses that source (just as browsers do) and then checks the resulting HTML document the parser creates.

So, what the HTML checker “sees” (and what browsers see) doesn’t look like the tags-omitted source in the first case above but instead looks like the source in the second case above, with all the optional tags included.

In yet other words, when looking at some HTML markup/source, it’s necessary to understand what HTML document that source represents — which minimally includes understanding that every HTML document has html, head, and body elements, even if the source for the document doesn’t have start tags or end tags for any of those elements.

from validator.

Madhusri02 avatar Madhusri02 commented on June 2, 2024

Actually this code does't show any error when i workout . As it still shows the error for you, I can conclude that it requires tag as it includes the metadata . check out the code with tag

from validator.

tbytedev avatar tbytedev commented on June 2, 2024

I don't say I fully understand what you wrote, but I think this error occurs not only for me, but for everyone who visits https://validator.w3.org/. I'm sorry, but I forgot to mention, that I typed that short html code there. And there was a link to this github repo, so that if I notice any errors, I can report them here. So I assumed that it's not necessary to mention. And I don't understand what metadata you are referring.

from validator.

scottaohara avatar scottaohara commented on June 2, 2024

the title element is required in most cases.

while the head element isn't required - that's because browsers will automatically inject it for you.

so you can do the following:

<!DOCTYPE html>
<html lang="en">
<title>Test</title>
<body>
....
</body>
</html>

to both not have to have a head element, but still have the required title element that the browser will make sure is placed into the head element they inject.

from validator.

tbytedev avatar tbytedev commented on June 2, 2024

The reason I made this issue is that I think the error message is incorrect. So the problem was not that I couldn't make a valid HTML file, and I need some help how to correct my 4 line long code. I made that code deliberately to demonstrate how to reproduce that error message. As the code doesn't contain head element the validator shouldn't say that the head element is missing something. It should just say that the title tag is required.

from validator.

scottaohara avatar scottaohara commented on June 2, 2024

appreciate the clarification @tbytedev, as it was not clear that you didn't understand this from your original comments -
specifically:

There's no head element, so it can't miss anything.

that reads to me that you're saying because a head isn't present, the title isn't required. Not, "this error message is confusing because even though the title is required, it's implying i need to declare a head element, which i don't"

and to that point i generally agree with you. It would be good to get the error message updated so it could more generally state that regardless of whether a head element is present (edit: in the provided source), a title element still need to be specified by the author.

whether that be done by updating the output to state that the document's implicitly added head element is missing the title element. Or, to maybe instead use the more general REQUIRED_ELEMENTS_MISSING = "Required elements missing.".toCharArray(); rather than the missing required child message, to mitigate the mention of the implicit or explicit head element entirely.

edit: but to sideshowbarker's comment that follows, there really doesn't seem to be an issue here at all and this again just seems to be a misunderstanding of what the validator is actually saying with this error message

from validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.