Home > Enterprise >  Trying to understand the head tag in html
Trying to understand the head tag in html

Time:07-11

I am new to HTML and started with my first lesson. I am unable to understand the head tag clearly and need help to understand it clearly.

As I read about the head tag, it says "The head of an HTML document is the part that is not displayed in the web browser when the page is loaded."

However when I try in my lab exercise with the below code in my html file, the content inside the h1 tag that is within the head tag is displayed in the web browser, which is confusing me as I was expecting that, whatever I write inside the head tag will not be displayed in the browser, as per what I read. Can someone give me clarity on this.

<!DOCTYPE html>
<html>
  <head>
    <title>First Lesson</title>
    <h1>Hello World!</h1>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

CodePudding user response:

Html tag head contains machine-readable information, which not displayed, like metadata, scripts, styles. He also inherits all of the properties html element and browser parse him, like common html tag. More information: link, link

CodePudding user response:

Modern HTML is very tolerant. You can now get away with not closing tags, or even no tags at all (remove the <h1> tags and "hello world!" will still be displayed) You could put the <title> in the body and it will still be displayed in the browser tag. Although it still works, it is incorrect and fails HTML markup validation. Any of the tags that meant to be in the head <title> <style> <base> <meta> etc. Won't be displayed on the page.

  •  Tags:  
  • html
  • Related