locked
HTML page without Head and Body tag RRS feed

  • Question

  • User1241685987 posted

    Hello,

    Are Head and Body tags semantic elements? 

    Can we create HTML pages without Head and Body tags? What are the benefits when we use these tags?

    Thanks 

    Monday, June 10, 2019 11:05 PM

All replies

  • User839733648 posted

    Hi life24,

    Are Head and Body tags semantic elements? 

    Can we create HTML pages without Head and Body tags? What are the benefits when we use these tags?

    As per the MDN on <head>:

    The HTML <head> element represents a collection of metadata about the document, including links to or definitions of scripts and style sheets.

    This means that everything that goes in the <head> tag is not seen by the user (basically),

    but is used to include relevant information and dynamic content that is processed by the browser.

    Pay attention to the notes: HTML5-compliant browsers automatically create a <head> element if its tags are omitted in the markup.

    As per the MDN on <body>:

    The HTML <body> element represents the content of an HTML document. There is only one <body> element in a document.

    This means that everything that the user sees on the page goes in the <body> tag (basically), and that there is only one.

    You could omit the head and body tags in your page because this is certainly allowed by the HTML specs.

    Here is a sample to show this.

    testing.html

    <!DOCTYPE html>
    <meta charset="utf-8" />
    <title>Page Title</title>
    <style>
        div {
            color: red;
        }
    </style>
    <div>Some html</div>

    how it work:

    For more about the tags, you could refer to this link: https://stackoverflow.com/questions/5641997/is-it-necessary-to-write-head-body-and-html-tags

    Best Regards,

    Jenifer

    Tuesday, June 11, 2019 2:24 AM
  • User-1038772411 posted

    life24,

    Yes , You are free to omit head and body tags from your html code. 

    There is no cons of omitting html , head , body tags since they are optional as per w3cPlease check out the link, The global structure of an HTML document.

    Benefits : Size will be reduced . Even though it is small size, considering page serves many times in a day , may small reductions in size can be significant at that volume of traffic .

    Since the earlier versions of html, do not have these tags, almost every brower works correctly. But if you want add some attributes like, <html lang=”en”> how would you do ? If you want to have some attributes, you need to use a wrapper, like div. So, for the convenience sake, they prepared some predefined wrappers like head,body,etc. However, some browsers might not be able to convert the code or separate the code in the head,body etc tags.

    I tried on google chrome and these are the results . Google chrome automatically, converts the code into html and body tags. You can see the results below .

    Thank You.

    Tuesday, June 11, 2019 11:49 AM
  • User1241685987 posted

    Thank you for your reply,

    Could you please explain more about this?

    Benefits : Size will be reduced . Even though it is small size, considering page serves many times in a day , may small reductions in size can be significant at that volume of traffic .

    Thanks

    Wednesday, June 12, 2019 9:43 AM
  • User839733648 posted

    Hi life24,

    HTML is a widely-used, standard document format for publishing content on the Internet.

    Foremost, everything on the Internet is connected.

    You are encouraged use standard practices, so that what you are trying to accomplish can be well-received by others. 

    You should use head and body tags in your HTML documents.

    Much like the C programming language makes use of optional header files to parse your program.

    A browser can use the information within the head tag to parse and render an HTML document. So it is body tag.

    For more about the tag, you could refer to: 

    https://www.w3.org/TR/html401/struct/global.html

    https://forums.adobe.com/thread/2051531 

    Best Regards,

    Jenifer

    Friday, June 14, 2019 8:39 AM