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="mobile300x250_btf" class="module"></div><script type="text/javascript">(function(){var ads = {"mobile":"300x250_btf"};if ( isMobile() && ads.mobile ) {googletag.cmd.push(function() {googletag.display("mobile300x250_btf");});}})()</script> <div id="DMINSTR" type="adimpression" data-type="adTracking" name="&adunit_id=4702029177&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 = '4702029177'; 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"></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> <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> </section> <aside class="right-rail"> <div id="desktop300x250_300x600_atf" class="module"></div><script type="text/javascript">(function(){var ads = {"desktop":"300x250_300x600_atf"};if ( !isMobile() && ads.desktop ) {googletag.cmd.push(function() {googletag.display("desktop300x250_300x600_atf");});}})()</script> <div class="section-heading-container"> <h2 class="section-heading">Related Articles</h2> </div> <div class="related-articles"> <article class="related-article related-article--around-the-home"> <a href="/40808/18-times-it-just-didnt-pay-to-be-an-early-adopter" class="image"> <img src="https://cmeimg-a.akamaihd.net/default/ppds/fe27cfaa-4151-497e-bafe-020b0bed8c3b.jpg" alt="18 Times It Just Didn’t Pay to Be An Early Adopter"> </a> <div class="info"> <h2 class="title"> <a href="/40808/18-times-it-just-didnt-pay-to-be-an-early-adopter" title="18 Times It Just Didn’t Pay to Be An Early Adopter">18 Times It Just Didn’t Pay to Be An Early Adopter</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> </article> <article class="related-article related-article--around-the-home"> <a href="/40806/how-to-stop-familytreenow-from-giving-your-personal-info-away-for-free" class="image"> <img src="https://cmeimg-a.akamaihd.net/default/ppds/bbc730b4-8aaf-4bf5-bcc8-7230351342c8.png" alt="How to Stop FamilyTreeNow From Giving Your Personal Info Away For Free"> </a> <div class="info"> <h2 class="title"> <a href="/40806/how-to-stop-familytreenow-from-giving-your-personal-info-away-for-free" title="How to Stop FamilyTreeNow From Giving Your Personal Info Away For Free">How to Stop FamilyTreeNow From Giving Your Personal Info Away For Free</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> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-check-the-toner-level-on-a-brother" class="image"> <img src="http://photos.demandstudios.com/184/139/fotolia_2719316_XS.jpg" alt="How to Check the Toner Level on a Brother"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-check-the-toner-level-on-a-brother" title="How to Check the Toner Level on a Brother">How to Check the Toner Level on a Brother</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> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-delete-something-from-my-favorites-list" class="image"> <img src="https://cmeimg-a.akamaihd.net/default/photos.demandstudios.com/getty/article/115/253/492677678.jpg" alt="How to Delete Something From My Favorites List"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-delete-something-from-my-favorites-list" title="How to Delete Something From My Favorites List">How to Delete Something From My Favorites List</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> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-delete-solitaire-from-windows" class="image"> <img src="https://cmeimg-a.akamaihd.net/default/photos.demandstudios.com/getty/article/251/183/86536752.jpg" alt="How to Delete Solitaire From Windows"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-delete-solitaire-from-windows" title="How to Delete Solitaire From Windows">How to Delete Solitaire From Windows</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> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-rip-cds-with-vlc" class="image"> <img src="http://cache.gettyimages.com/xc/86499730.jpg?v=1&c=EWSAsset&k=2&d=82EB172C4407816C2B5CE92F8225D038C2284D1E1E7273F2756150677CBA603C" alt="How to Rip CDs With VLC"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-rip-cds-with-vlc" title="How to Rip CDs With VLC">How to Rip CDs With VLC</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> </article> </div> <div id="desktop300x250_btf" class="module"></div><script type="text/javascript">(function(){var ads = {"desktop":"300x250_btf"};if ( !isMobile() && ads.desktop ) {googletag.cmd.push(function() {googletag.display("desktop300x250_btf");});}})()</script> </aside> </div> </div> <script type="text/javascript"> window._taboola = window._taboola || []; _taboola.push({flush: true}); </script> <script type="text/javascript"> if (isMobile()) { document.write('<scr'+'ipt async defer data-pin-hover="true" data-pin-tall="true" data-pin-round="true" data-pin-save="false" src="//assets.pinterest.com/js/pinit.js"></scr'+'ipt>'); } else { document.write('<scr'+'ipt async defer data-pin-hover="true" data-pin-tall="true" data-pin-save="true" src="//assets.pinterest.com/js/pinit.js"></scr'+'ipt>'); } </script> <div id="outofpage"><script type="text/javascript">googletag.cmd.push(function() { googletag.display("outofpage"); });</script></div> </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" data-icon="" class="social_facebook"></a><a data-event="twitter" target="_blank" href="https://twitter.com/techwallahq" data-icon="" class="social_twitter"></a></div> </div> <div class="col-xs-0 col-md-2 col-lg-0"></div> <div class="col-xs-12 col-md-8 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="/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 data-icon="" class="elegant-icons"></span></button></div> </div> </form> </div> </div> </div> </div> </div> <div id="attribution" class="body-row black"> <div class="container"> <div id="leaf-logo" class="col-xs-12 col-md-12 col-lg-2"></div> <div id="copyright" class="col-xs-12 col-md-12 col-lg-8">© 2017 Leaf Group Ltd.</div> </div> </div> </footer> <script type="text/javascript" src="/ui/js/common.js"></script> <!-- 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 --> <div id="outofpage"><script type="text/javascript">googletag.cmd.push(function() { googletag.display("outofpage"); });</script></div> <script type="text/javascript" src="//s.skimresources.com/js/101174X1558374.skimlinks.js"></script> </body> </html>