What Are the Two Main Parts of an HTML Document?

The two main parts of an HTML document are the head and the body. Each section contains specific information. The head section contains information that is useful to the Web browser and search engines but is not visible to the reader. The body section contains the information that you want the visitor to see. The document is specifically formatted so that Web browsers are able to parse the information and present it to the visitor correctly.

Structure of an HTML document

An HTML document must be formatted correctly to be read by a Web browser. The following is a general outline of a typical HTML document:

<!DOCTYPE> Information for Web browser and search engines Contents visible to reader

Both the tags and the tags are contained within the main tag. Both sections must be terminated with the "</>" characters for the document to be read.

Head Contents

The head section of the document contains the site's title, keywords for search engines, scripts and the location of a cascading style sheet that should be used in formatting the page. Typical HTML tags used in the head section include the , <link>, <style>, <meta> and <script> tags.</p> <p class="section-content">The <title> tag defines the title of the document. The <link> tag links an external resource, such as a CSS file, to the document. The <style> tag defines document styles. The <meta> tag is used to define the author, keywords and description of the document. The <script> tag defines a script that is to be run on the visitor's computer. If the head section is not placed in the document, the contents of the document are still displayed by the browser.</p> <h2 class="section-title">Body Contents</h2> <p class="section-content">The body section is used to format the actual Web page. Most of the HTML tags, such as the paragraph tag (<p class="section-content">), the anchor tag (<a>), the headings tags (<h1> to <h6>) and the section tag (<div>) are used in this section of the document. Server side scripts are also placed in this section of the document. If you do not have a body section in your HTML document, nothing is displayed in the Web browser.</p> <h2 class="section-title">DOCTYPE</h2> <p class="section-content">The only thing not included between the <html> tags is the DOCTYPE declaration. If used, it should be the first line in the HTML document. It is used to tell the Web browser what version of HTML the document is using. The browser uses this declaration to render the page correctly. The DOCTYPE declaration can be ommitted, but the browser may not present your page correctly.</p> </article> <div class="article-close"></div> <div id="slot3" class=" module " data-device="mobile" data-loc="btf" data-slot="slot3" data-sizes="[[300, 250]]"></div> <script> if ((isMobile() && 'mobile' === 'mobile') || (!isMobile() && 'mobile' === 'desktop')) { googletag.cmd.push(function() { googletag.display("slot3"); }); } </script> <div id="DMINSTR" type="adimpression" class="adsense" data-type="adTracking" name="&adunit_id=5706684770&ad_unit_type=CNT&ad_unit_network=GAS&revenue_basis=CPC&ad_position=C1&revenue_tag=pub-0316265116163263"> <div id="google-article-block"> <script type="text/javascript"> if ( !isMobile() ) { google_ad_client = 'pub-0316265116163263'; google_ad_channel = '5706684770'; google_ad_output = 'js'; google_max_num_ads = '4'; google_ad_type = 'text'; google_image_size = '336x280'; google_url ='bottom'; google_label_text = 'Sponsored Links'; document.write('<scr' + 'ipt language="JavaScript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js"></scr' + 'ipt>'); } </script> </div> </div> <div id="taboola-below-article-thumbnails" class="taboola"></div> <script type="text/javascript"> window._taboola = window._taboola || []; _taboola.push({ mode: 'thumbnails-a', container: 'taboola-below-article-thumbnails', placement: 'Below Article Thumbnails', target_type: 'mix' }); </script> <a class="fb-button-show" data-fb-target="fb-initial0" onclick="showFacebookComments(this)" data-event="expand comments"> <div class="fb-comment-button"> <div class="fb-icon"> <icon class="social-share-facebook svg"></icon> </div> Show Comments </div> </a> <div class="fb-comments-wrapper" id="fb-initial0"> <div class="fb-comments" data-href="https://www.techwalla.com/articles/what-are-the-two-main-parts-of-an-html-document" data-width="970" data-numposts="5"></div> </div> </section> <aside class="right-rail"> <div id="rightrail1" class=" module " data-device="desktop" data-loc="atf" data-slot="rightrail1" data-sizes="[[300, 250], [300, 600]]"></div> <script> if ((isMobile() && 'desktop' === 'mobile') || (!isMobile() && 'desktop' === 'desktop')) { googletag.cmd.push(function() { googletag.display("rightrail1"); }); } </script> <div class="section-heading-container hidden-on-mobile"> <h2 class="section-heading">Related Articles</h2> </div> <div class="related-articles hidden-on-mobile"> <article class="related-article related-article--around-the-home"> <a href="/40816/backing-up-your-raw-photo-files-online" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/ppds/e89dba7d-c5ff-42f2-955e-3bc09e9002d2.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/ppds/e89dba7d-c5ff-42f2-955e-3bc09e9002d2.jpg 1x, https://cmeimg-a.akamaihd.net/220/ppds/e89dba7d-c5ff-42f2-955e-3bc09e9002d2.jpg 2x" alt="Backing Up Your RAW Photo Files Online"> </a> <div class="info"> <h2 class="title"> <a href="/40816/backing-up-your-raw-photo-files-online" title="Backing Up Your RAW Photo Files Online">Backing Up Your RAW Photo Files Online</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/productivity">Productivity</a> </div> <div class="author"><span class="author-by">By: </span>Jackie Dove</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/essential-apps-for-expecting-moms" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="//img.techwallacdn.com/tw-product-hero/tw/4b/d3/4bd3cb0d1709ad4bd75c9d9448d03f2f.jpg" data-srcset="//img.techwallacdn.com/tw-product-hero/tw/4b/d3/4bd3cb0d1709ad4bd75c9d9448d03f2f.jpg 1x, //img.techwallacdn.com/tw-product-hero/tw/4b/d3/4bd3cb0d1709ad4bd75c9d9448d03f2f.jpg 2x" alt="10 Essential Apps for Expecting Moms"> </a> <div class="info"> <h2 class="title"> <a href="/articles/essential-apps-for-expecting-moms" title="10 Essential Apps for Expecting Moms">10 Essential Apps for Expecting Moms</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/smart-home">Smart Home</a> </div> <div class="author"><span class="author-by">By: </span>Techwalla Contributor</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-delete-or-hide-guides-in-adobe-photoshop" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/176/123/480182833.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/176/123/480182833.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/176/123/480182833.jpg 2x" alt="How to Delete or Hide Guides in Adobe Photoshop"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-delete-or-hide-guides-in-adobe-photoshop" title="How to Delete or Hide Guides in Adobe Photoshop">How to Delete or Hide Guides in Adobe Photoshop</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/productivity">Productivity</a> </div> <div class="author"><span class="author-by">By: </span>Andrew Tennyson</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-increase-the-signal-of-a-u-verse-2wire-modem" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/56/27/77005528.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/56/27/77005528.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/56/27/77005528.jpg 2x" alt="How to Increase the Signal of a U-Verse 2Wire Modem"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-increase-the-signal-of-a-u-verse-2wire-modem" title="How to Increase the Signal of a U-Verse 2Wire Modem">How to Increase the Signal of a U-Verse 2Wire Modem</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/productivity">Productivity</a> </div> <div class="author"><span class="author-by">By: </span>Eoghan McCloskey</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-lay-out-avery-5160" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/232/200/588995214.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/232/200/588995214.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/232/200/588995214.jpg 2x" alt="How to Lay Out Avery 5160"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-lay-out-avery-5160" title="How to Lay Out Avery 5160">How to Lay Out Avery 5160</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/productivity">Productivity</a> </div> <div class="author"><span class="author-by">By: </span>Debbie Glasser</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-set-reminders-on-microsoft-outlook-calendars" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/cpcd/upload/image/55/50/848BA89D-0EBE-482B-860C-0BEC36FD5055/848BA89D-0EBE-482B-860C-0BEC36FD5055.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/cpcd/upload/image/55/50/848BA89D-0EBE-482B-860C-0BEC36FD5055/848BA89D-0EBE-482B-860C-0BEC36FD5055.jpg 1x, https://cmeimg-a.akamaihd.net/220/cpcd/upload/image/55/50/848BA89D-0EBE-482B-860C-0BEC36FD5055/848BA89D-0EBE-482B-860C-0BEC36FD5055.jpg 2x" alt="How to Set Reminders on Microsoft Outlook Calendars"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-set-reminders-on-microsoft-outlook-calendars" title="How to Set Reminders on Microsoft Outlook Calendars">How to Set Reminders on Microsoft Outlook Calendars</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/productivity">Productivity</a> </div> <div class="author"><span class="author-by">By: </span>Diana Bailey</div> </div> </article> </div> <div id="rightrail2" class=" module " data-device="desktop" data-loc="btf" data-slot="rightrail2" data-sizes="[[300, 250], [300, 600]]"></div> <script> if ((isMobile() && 'desktop' === 'mobile') || (!isMobile() && 'desktop' === 'desktop')) { googletag.cmd.push(function() { googletag.display("rightrail2"); }); } </script> </aside> </div> </div> <div id="out-of-page" class="" data-slot="out-of-page"> <script> googletag.cmd.push(function() { googletag.display("out-of-page"); }); </script> </div> <div class="article-separator"></div> <script type="text/javascript"> window.addEventListener('scroll', function() { if (!window.hasPinterest) { var scriptTag = document.createElement('script'); scriptTag.src = '//assets.pinterest.com/js/pinit.js' scriptTag.setAttribute('data-pin-hover', 'true') scriptTag.setAttribute('data-pin-tall', 'true') scriptTag.setAttribute('data-pin-save', 'true') if (isMobile()) { scriptTag.setAttribute('data-ping-save', 'false') } var parent =document.getElementsByTagName('script')[0]; parent.parentNode.insertBefore(scriptTag, parent) window.hasPinterest = true; } }); </script> <script async type="text/javascript" src="/ui/js/infiniteScroll.js?v=947c7bd6da1246020d04073563b598aa3bb006c6"></script> <script type="text/javascript"> window._taboola = window._taboola || []; _taboola.push({flush: true}); </script> </main> <footer class="footer"> <div class="body-row black"> <div class="container"> <div class="row"> <div class="col-xs-12 col-md-12 col-lg-2"> <div id="bottomSocial"> <a data-event="facebook" target="_blank" href="https://www.facebook.com/pages/Techwalla/1116406528374498" class="social_facebook footer-social--facebook svg"></a> <a data-event="twitter" target="_blank" href="https://twitter.com/techwallahq" class="social_twitter footer-social--twitter svg"></a> </div> </div> <div class="col-xs-12 col-lg-7"> <div id="footer-menu"> <ul> <li><a href="/how-we-score">HOW WE SCORE</a></li> <li><a href="/about">ABOUT US</a></li> <li><a href="/about#contact">CONTACT US</a></li> <li><a href="/terms-of-use">TERMS</a></li> <li><a href="/privacy-policy">PRIVACY POLICY</a></li> <li><a href="/copyright-policy">COPYRIGHT POLICY</a></li> <li><a href="/advertise">Advertise</a></li> </ul> </div> </div> <div class="col-xs-12 col-md-12 col-lg-3"> <div class="newsletter"> <form class="tw-newsletter-footer"> <div class="input-group form-group newsletter-signup"> <input type="email" name="email" placeholder="Enter email for updates" class="form-control" required> <div type="submit" class="input-group-btn"><button class="btn newsletter-btn"><span class="footer-capture-submit svg"></span></button></div> <div class="message-invalid"> <p class="copy">An error occurred. Try again later.</p> </div> </div> </form> <div class="message-success">Thanks for signing up!</div> </div> </div> </div> </div> </div> <div id="attribution" class="body-row black"> <div class="container"> <div class="row"> <div class="col-xs-12"> <div class="leaf-logo"></div> </div> <div id="copyright" class="col-xs-12">© 2017 Leaf Group Ltd.</div> </div> </div> </div> </footer> <script type="text/javascript" src="/ui/js/common.js?v=a9e615450e182f9b83d0e3ffc1ab63ffec7585d3" async="async"></script> <!-- Capture Modals --> <!-- Capture --> <div id="email-capture" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Capture content--> <div class="modal-content email-capture"> <div class="modal-header"> <div class="x-close email-capture-close-icon svg" data-dismiss="modal" alt="close modal"> </div> </div> <div class="modal-body"> <h4 class="modal-title">Get great tech advice delivered to your inbox.</h4> <p>Keep your family productive, connected, entertained, and safe.</p> <div class="main-content"> <form class="form-centered auth-form email-form" method="post" action="/subscribe" autocomplete="off"> <fieldset class="form-group"> <input type="text" name="email" id="email" class="form-control" placeholder="Email" required /> <div class="message-invalid"> <p class="copy">Please enter a valid email.</p> </div> </fieldset> <fieldset class="form-group"> <input type="submit" class="submit btn" value="SUBSCRIBE" /> </fieldset> </form> </div> </div> </div> </div> </div> <!-- Quantcast Tag --> <script> var ezt = ezt ||[]; (function(){ var elem = document.createElement('script'); elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://pixel") + ".quantserve.com/aquant.js?a=p-4dIM5nVs2rFio"; elem.async = true; elem.type = "text/javascript"; var scpt = document.getElementsByTagName('script')[0]; scpt.parentNode.insertBefore(elem,scpt); }()); var quantcastCategory = 'Around The Home'; var quantcastSubCategory = 'Productivity'; var quantcastLabel = 'Techwalla'; quantcastLabel += quantcastCategory ? ('.' + quantcastCategory) : ''; quantcastLabel += quantcastSubCategory ? ('.' + quantcastSubCategory) : ''; var qcdata = { qacct: 'p-4dIM5nVs2rFio', uid: '', labels: quantcastLabel, } ezt.push(qcdata); </script> <noscript> <img src="//pixel.quantserve.com/pixel/p-4dIM5nVs2rFio.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/> </noscript> <!-- End Quantcast Tag --> <script type="text/javascript" src="//s.skimresources.com/js/101174X1558374.skimlinks.js" async="async"></script> </body> </html>