Is it correct to say that the <body> element is nested within the <html> element?


#1

Question

Is it correct to say that the <body> element is nested within the <html> element?

Answer

That is correct! The <html> tag is the root element of every page and it should always have <head> and <body> child elements. The <head> and <body> elements are siblings to each other and children to the <html> parent.


FAQ: Learn HTML Elements - Intro to HTML - HTML Structure
#4

To add to this, there is one other element permitted to be a direct child of <html></html> which is more commonly found in either the <head></head> after CSS links, or in the <body></body> element at the very bottom…

<script></script>

It may appear after the </body> tag, and is valid, though not typical.

Eg.

<!DOCTYPE html>
<html lang="en">
  <head>
    
  </head>
  <body>
    
  </body>
  <script src=""></script>
  <script>
    // JS code
  </script>
</html>

#5

Are elements also functions? or do they fall under both function and variable?


#6

No, they are HTMLElement objects that make up the nodes from which the DOM is constructed. Are not variables, either. Both functions and variables are properties of the scripting language, usually JavaScript, but it could also be Python, Ruby, etc.


#7

i am so confused :(:cry:


#8

so <head>, <body> and <script> are all children of <html>, correct?


#9

Yes and no. The convention is to write the script tag inside either/or both head and body. While browsers might accept a script outside of the head/body elements, the specification recommends,

Permitted parents Any element that accepts metadata content, or any element that accepts phrasing content.

The HTML root element can only have two children… HEAD and BODY.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html