Why do we need the tag after the declaration?

Why do we need the tag after the declaration? This seems redundant. We tell the browser that it is dealing with an html file via the Doctype declaration; then we have to tell it again with the tag once it starts parsing the code? Can the function of tags not be passed off to the DTD?

11 Likes

The DTD is not HTML, but SGML. It tells the user agent that the root element of the document is <html></html>. The de facto namespace is HTML5. Other than that the declaration has no part in DOM.

30 Likes

Hey there, just started learning html but like Nathan here, I feel a redundancy in the writing. I’ve been reading your reply a couple of times but I’m still confused. I’m sure your answer is probably clear to most people here but if you were to bring it down a level from newbie 2.0 to newbie 1.0, what would it look like? Thank you

27 Likes

3 On SGML and HTML

The above refers back to HTML 4.01 as it relates to SGML. HTML is a subset of SGML.

With the advent of HTML5 and the present day Living Standard a lot of the technical boilerplate was shooed into the background, such as the long and complex DTD and namespace declarations; and a number of meta data components such as ‘content-type’, etc. were made moot. That’s where the de facto aspect comes in.

<!DOCTYPE html>

Looks like an HTML comment, almost, doesn’t it? But it is not HTML, only an HTML DTD to declare the root element of the document. That is where the real HTML begins.

<html lang="en">
  <!-- everything in here is HTML -->
</html>
32 Likes

mark <body< and win the coding winning storke

1 Like

Hello newbie 1.0 :slightly_smiling_face:, as a member of the newbie 2.0 squad myself, i totally understand you. So I hope this helps: As you know, is not a HTML tag, but rather, just a message to the web browser telling it what it’s looking at and dealing with. On the flip side, thing tag serves as a container, this ‘container’ serves as a ‘bracket’ (for lack of a better word. What this bracket does is tell the web browser that the opening and closing tags are where all related code will begin and end. I hope this helps. Cheers

54 Likes

Hi, Roy. I am still confused about the concept of DTD. I heard that HTML 5 is not based on SGML, so there is no requirement to quote DTD. And Here is what I find in the Stackoverflow say that there is no HTML5 DTD( DTDs have been regarded by the designers of HTML5 as too limited in expressive power, and HTML5 validators (basically the HTML5 mode of http://validator.nu and its copy at Ready to check - Nu Html Checker) use schemas and ad hoc checks, not DTD-based validation. Moreover, HTML5 has been designed so that writing a DTD for it is impossible. ). :confounded:This is completely confusing for a newbie 1.0 like me.

Could you please elaborate on the relationship between DTD and HTML 5? AND what is the role of the DTD in detail?

No. I think you’ve done enough already in terms of following up on the details to arrive at a conclusion.

However, DTD is SGML, not HTML. The current one is the compromise. No DTD can be used to describe HTML5. but we can describe the root element, html.

<!DOCTYPE html>

and then rely upon the local namespace to provide all the support, which is what is happening.

Don’t forget that HTML5 is XML compliant, which as it happens does include the DTD since modern XML has absorbed SGML. What we have is an XML document that gets defaulted to text/html if not specified otherwise.

1 Like

Doctype declaration <!DOCTYPE html> tells the user agent that the root element of the document is <html></html> . Is this redundant? Cuz it is very obvious that <HTML> </html> is root element.

AND what is the relationship between SGML and HTML 5? I know that XML is a simplified modification of SGML, and SGML is the parent of XML and HTML.

1 Like

No it’s not. A malformed page would suggest that the first element encountered is the root element. This is a necessary declaration.

XML

3 Likes

could you please talk more specifically? :joy:

Again, no. It’s a long and windy road that needs some serious perusing of W3 pages, and all its internet accoutrements.

2 Likes

Anyway. Thank you. I still have a lot to learn :smile:

1 Like

Please do let us know anything more that you discover. We’re all ears. Keep digging!

3 Likes

2 posts were split to a new topic: The meaning of DOM

Hello , I’m new here. I’ve been thinking why not use the body tag to start the html structures instead of html? Like in one of the previous lessons , body tag was generally used to start writing html elements. Also I know that head and body they are sibling elements and html is the parent. But mostly I saw the page starting with body tags. Can you pls answer this?

BODY is the content container which elements are rendered in the window viewport. The document proper is contained in the HTML element; this includes the meta data supporting it.

It would be rather strange to see a document type declaration that looks like this:

<!DOCTYPE body>

The body is not the document root.

What is DTD? Also, what is SGML?

1 Like
  1. SGML (Standard Generalized Markup Language):
  • SGML is a standard for defining markup languages.
  • It is a metalanguage, which means it provides a framework for defining markup languages rather than being a markup language itself.
  • SGML was developed to create a standard for the representation of documents with complex structures and rich semantics.
  • It allows the definition of document structure, elements, and their relationships in a way that is independent of the specific application or platform.
  1. DTD (Document Type Definition):
  • DTD is a specific application of SGML and is used to define the structure and the legal elements and attributes of an XML document.
  • In the context of XML (eXtensible Markup Language), DTD is a set of rules that define the valid elements and attributes of an XML document.
  • DTD specifies the structure of the document, including the order and nesting of elements, the allowed attributes for each element, and the document’s overall organization.
1 Like