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> <ins class="adsbygoogle" style="display:inline-block;min-width:250px;max-width:1200px;width:100%;height:560px" data-ad-client="ca-pub-0316265116163263" data-ad-slot="3171973977"></ins> <script>(adsbygoogle = window.adsbygoogle || []).push({});</script> <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=" rightrail 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="/13429559/heres-whats-coming-to-hulu-in-august" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/ppds/15569703-df8e-4610-ba45-f30030d0b22a.png" data-srcset="https://cmeimg-a.akamaihd.net/100/ppds/15569703-df8e-4610-ba45-f30030d0b22a.png 1x, https://cmeimg-a.akamaihd.net/220/ppds/15569703-df8e-4610-ba45-f30030d0b22a.png 2x" alt="Here's What's Coming to Hulu in August"> </a> <div class="info"> <h2 class="title"> <a href="/13429559/heres-whats-coming-to-hulu-in-august" title="Here's What's Coming to Hulu in August">Here's What's Coming to Hulu in August</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/entertainment">Entertainment</a> </div> <div class="author"><span class="author-by">By: </span>Jill Layton</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/13429575/twitter-says-its-plan-to-stop-trolls-is-working" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/clsd/getty/f6fcd8e847254d329dc9a7f8d5b6a99d" data-srcset="https://cmeimg-a.akamaihd.net/100/clsd/getty/f6fcd8e847254d329dc9a7f8d5b6a99d 1x, https://cmeimg-a.akamaihd.net/220/clsd/getty/f6fcd8e847254d329dc9a7f8d5b6a99d 2x" alt="Twitter Says Its Plan to Stop Trolls Is Working"> </a> <div class="info"> <h2 class="title"> <a href="/13429575/twitter-says-its-plan-to-stop-trolls-is-working" title="Twitter Says Its Plan to Stop Trolls Is Working">Twitter Says Its Plan to Stop Trolls Is Working</a> </h2> <div class="category"> <a href="/around-the-home">Around The Home</a> </div> <div class="subcategory"> <a href="/entertainment">Entertainment</a> </div> <div class="author"><span class="author-by">By: </span>Jill Layton</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-download-a-ppt" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/12/250/fotolia_1369661_XS.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/12/250/fotolia_1369661_XS.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/12/250/fotolia_1369661_XS.jpg 2x" alt="How to Download a PPT"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-download-a-ppt" title="How to Download a PPT">How to Download a PPT</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>Amber Riippa</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/routers-that-can-be-used-for-verizon-fios-service" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/cppd/getty/article/41/252/84482588.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/cppd/getty/article/41/252/84482588.jpg 1x, https://cmeimg-a.akamaihd.net/220/cppd/getty/article/41/252/84482588.jpg 2x" alt="Routers that Can Be Used for Verizon FiOS Service"> </a> <div class="info"> <h2 class="title"> <a href="/articles/routers-that-can-be-used-for-verizon-fios-service" title="Routers that Can Be Used for Verizon FiOS Service">Routers that Can Be Used for Verizon FiOS Service</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>Ryan Heiser</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-remove-themes-from-tumblr" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/ppds/b3d98ef1-e5d0-4b4c-8c32-1348342aa578.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/ppds/b3d98ef1-e5d0-4b4c-8c32-1348342aa578.jpg 1x, https://cmeimg-a.akamaihd.net/220/ppds/b3d98ef1-e5d0-4b4c-8c32-1348342aa578.jpg 2x" alt="How to Remove Themes From Tumblr"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-remove-themes-from-tumblr" title="How to Remove Themes From Tumblr">How to Remove Themes From Tumblr</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 Meer</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-backup-a-computer-system-on-a-flash-drive" class="image"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/69/30/518481561.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/69/30/518481561.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/69/30/518481561.jpg 2x" alt="How to Backup a Computer System on a Flash Drive"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-backup-a-computer-system-on-a-flash-drive" title="How to Backup a Computer System on a Flash Drive">How to Backup a Computer System on a Flash Drive</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>Nick Davis</div> </div> </article> </div> <div id="rightrail2" class=" rightrail 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=70767fb80f0deb363a5bba3502b0507bed41f0e2"></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. Leaf Group Media.</div> </div> </div> </div> </footer> <script type="text/javascript" src="/ui/js/common.js?v=883766026b6a70293f914f492154d8c0ef216961" 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>