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="btf-styleframe-ad-0"></div> <script> // dynamically add styleframe if config and device are correct var btfStyleFrameInset = document.createElement('ins'); btfStyleFrameInset.className = 'adsbygoogle'; btfStyleFrameInset.dataset.adClient = "ca-pub-0316265116163263"; btfStyleFrameInset.dataset.adSlot = "3171973977"; btfStyleFrameInset.style.display = 'inline-block'; btfStyleFrameInset.style.minWidth = '250px'; btfStyleFrameInset.style.maxWidth = '1200px'; btfStyleFrameInset.style.width = '100%'; btfStyleFrameInset.style.height = '500px'; var styleFrameDiv = document.getElementById("btf-styleframe-ad-0"); if (!isMobile()) { styleFrameDiv.appendChild(btfStyleFrameInset); (adsbygoogle = window.adsbygoogle || []).push({}); } </script> <div id="slot1-3" class=" slot module " data-device="mobile" data-loc="btf" data-slot="slot1-3" data-sizes="[[300, 250]]"></div> <script> if ((isMobile() && 'mobile' === 'mobile') || (!isMobile() && 'mobile' === 'desktop')) { googletag.cmd.push(function() { googletag.display("slot1-3"); }); } </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-1" class=" rightrail module " data-device="desktop" data-loc="atf" data-slot="rightrail1-1" data-sizes="[[300, 250], [300, 600]]"></div> <script> if ((isMobile() && 'desktop' === 'mobile') || (!isMobile() && 'desktop' === 'desktop')) { googletag.cmd.push(function() { googletag.display("rightrail1-1"); }); } </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="/articles/blender-vs-rhino" class="image" data-event="rc_right_rail" data-info="0"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/103/24/477721517.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/103/24/477721517.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/103/24/477721517.jpg 2x" alt="Blender Vs. Rhino"> </a> <div class="info"> <h2 class="title"> <a href="/articles/blender-vs-rhino" title="Blender Vs. Rhino" data-event="rc_right_rail" data-info="0">Blender Vs. Rhino</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>Shea Laverty</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/html-coding-to-change-the-width-of-a-paragraph" class="image" data-event="rc_right_rail" data-info="1"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/83/133/186309877.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/83/133/186309877.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/83/133/186309877.jpg 2x" alt="HTML Coding to Change the Width of a Paragraph"> </a> <div class="info"> <h2 class="title"> <a href="/articles/html-coding-to-change-the-width-of-a-paragraph" title="HTML Coding to Change the Width of a Paragraph" data-event="rc_right_rail" data-info="1">HTML Coding to Change the Width of a Paragraph</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>Steve McDonnell</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-reduce-the-spacing-between-lines-in-html" class="image" data-event="rc_right_rail" data-info="2"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/cache.gettyimages.com/xc/78463455.jpg?v=1&c=EWSAsset&k=2&d=82EB172C4407816C6F0D77DE904C82C2165739EB2D9AE7A5577A452F297A9963" data-srcset="https://cmeimg-a.akamaihd.net/100/cache.gettyimages.com/xc/78463455.jpg?v=1&c=EWSAsset&k=2&d=82EB172C4407816C6F0D77DE904C82C2165739EB2D9AE7A5577A452F297A9963 1x, https://cmeimg-a.akamaihd.net/100/cache.gettyimages.com/xc/78463455.jpg?v=1&c=EWSAsset&k=2&d=82EB172C4407816C6F0D77DE904C82C2165739EB2D9AE7A5577A452F297A9963 2x" alt="How to Reduce the Spacing Between Lines in HTML"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-reduce-the-spacing-between-lines-in-html" title="How to Reduce the Spacing Between Lines in HTML" data-event="rc_right_rail" data-info="2">How to Reduce the Spacing Between Lines in HTML</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>Richard Graham</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/15-killer-ways-to-spook-up-your-porch-for-halloween" class="image" data-event="rc_right_rail" data-info="3"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/tw/d3/f3/d3f3e6ffe8d0c05b5ae00a50a1767ebc.jpeg" data-srcset="https://cmeimg-a.akamaihd.net/100/tw/d3/f3/d3f3e6ffe8d0c05b5ae00a50a1767ebc.jpeg 1x, https://cmeimg-a.akamaihd.net/220/tw/d3/f3/d3f3e6ffe8d0c05b5ae00a50a1767ebc.jpeg 2x" alt="15 Killer Ways to Spook Up Your Porch for Halloween"> </a> <div class="info"> <h2 class="title"> <a href="/articles/15-killer-ways-to-spook-up-your-porch-for-halloween" title="15 Killer Ways to Spook Up Your Porch for Halloween" data-event="rc_right_rail" data-info="3">15 Killer Ways to Spook Up Your Porch for Halloween</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>Jill Layton</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-to-make-a-static-web-page" class="image" data-event="rc_right_rail" data-info="4"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/59/240/fotolia_1630159_XS.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/59/240/fotolia_1630159_XS.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/59/240/fotolia_1630159_XS.jpg 2x" alt="How to Make a Static Web Page"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-to-make-a-static-web-page" title="How to Make a Static Web Page" data-event="rc_right_rail" data-info="4">How to Make a Static Web Page</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>Alex Smith</div> </div> </article> <article class="related-article related-article--around-the-home"> <a href="/articles/how-many-youtube-tags-are-too-many" class="image" data-event="rc_right_rail" data-info="5"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/83/50/86092712.jpg" data-srcset="https://cmeimg-a.akamaihd.net/100/photos.demandstudios.com/getty/article/83/50/86092712.jpg 1x, https://cmeimg-a.akamaihd.net/220/photos.demandstudios.com/getty/article/83/50/86092712.jpg 2x" alt="How Many YouTube Tags Are Too Many?"> </a> <div class="info"> <h2 class="title"> <a href="/articles/how-many-youtube-tags-are-too-many" title="How Many YouTube Tags Are Too Many?" data-event="rc_right_rail" data-info="5">How Many YouTube Tags Are Too Many?</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>Geoff Whiting</div> </div> </article> </div> <div id="rightrail1-2" class=" rightrail module " data-device="desktop" data-loc="btf" data-slot="rightrail1-2" data-sizes="[[300, 250], [300, 600]]"></div> <script> if ((isMobile() && 'desktop' === 'mobile') || (!isMobile() && 'desktop' === 'desktop')) { googletag.cmd.push(function() { googletag.display("rightrail1-2"); }); } </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 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=9e7c624c2883de9fd7f2f04de171a08e59ddd549" 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> <!-- Capture --> <div id="ls-capture" class="modal fade" role="dialog"> <div class="modal-dialog"> <a id="ls-promo-link" href="http://www.livestrong.com/slideshow/556938-20-fitness-gadgets-that-actually-work/?utm_source=techwall.com&utm_medium=referral&utm_content=url_id&utm_campaign=Techwalla" target="_blank" data-event="livestrong_popup_slideshow_gadget_click"> <div class="modal-content ls-capture"> <div class="modal-header"> <div class="x-close ls-capture-close-icon svg" data-dismiss="modal" alt="close modal"> </div> </div> </div> </a> </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 --> </body> </html>