{"id":239,"date":"2013-01-29T14:45:00","date_gmt":"2013-01-29T14:45:00","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=239"},"modified":"2013-01-29T14:45:00","modified_gmt":"2013-01-29T14:45:00","slug":"html-anatomy-html5-document","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/html-anatomy-html5-document\/","title":{"rendered":"What Is HTML? The Anatomy of an HTML5 Document"},"content":{"rendered":"<h2>DOCTYPE<\/h2>\n<p>The very first thing that you typically see in an HTML file is the DOCTYPE declaration. Before HTML5, this could be a very confusing bit of code that looked something like this:<\/p>\n<div>\n<div>\n<div id=\"highlighter_690296\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>There\u2019s a lot going on here and every bit of it speaks to either the web browser, the reader or both. The \u201cPUBLIC\u201d part just speaks to the availability, the DTD stands for <em>Document Type Definition<\/em>, which declares the version of HTML being used and the final section is a URL pointing to where the DTD can be found.<\/p>\n<p>The words \u201cloose,\u201d (or transitional) \u201cstrict\u201d and \u201cframeset\u201d refer to different versions of HTML 4, which allowed for slightly different markup. These were essentially just to help transition developers from older versions of HTML.<\/p>\n<h3>The HTML5 DOCTYPE<\/h3>\n<p>There are several DOCTYPEs to choose from, which can be monumentally confusing for new developers. Fortunately, HTML5 completely simplifies the situation with a refreshingly simple DOCTYPE:<\/p>\n<div>\n<div>\n<div id=\"highlighter_167126\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>See how easy that is by comparison? It really is a beautiful thing.<\/p>\n<h3>What Does the DOCTYPE Do?<\/h3>\n<p>Now we\u2019ve seen what a DOCTYPE <em>looks like<\/em> but we haven\u2019t really discussed what it <em>does<\/em>. The answer is that the DOCTYPE tells the browser which type of HTML to expect, which in turn affects how the browser renders the page.<\/p>\n<p>As you explore web development more, you\u2019ll learn that there\u2019s a huge emphasis on \u201cstandards-based development.\u201d The general idea is that if we all follow certain rules and standards, web development will be a more cohesive and consistent practice. This is better for developers, better for browsers and most importantly, better for users.<\/p>\n<p>DOCTYPEs were originally designed to trigger \u201cstandards mode\u201d in browsers, which meant that the page was rendered using newer web standards. Similarly, older pages without a DOCTYPE triggered \u201cquirks mode\u201d in browsers, which allowed for older practices to be used that wouldn\u2019t function properly in standards mode.<\/p>\n<p>The new, very simple HTML5 DOCTYPE is supported in all major browsers, and it triggers standards mode in all of them. The DOCTYPE also helps you <a href=\"http:\/\/validator.w3.org\/\">validate<\/a> your code, which ensures that current standards are being adhered to. Every page that you create should use a DOCTYPE and hopefully be fully standards compliant.<\/p>\n<h2>Root Element<\/h2>\n<p>After the DOCTYPE, the HTML really begins. This is indicated by the HTML Root Element. If your entire HTML is a tree, this is the root from which everything else sprouts.<\/p>\n<p>The Root Element is defined by a \u201ctag,\u201d which we learned about in our last article. In this case, it\u2019s the \u201cHTML\u201d tag.<\/p>\n<div>\n<div>\n<div id=\"highlighter_730464\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;!-- Everything Goes Here --&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>Notice that the root element includes a language attribute, in our case English. Always be sure to indicate the appropriate language for every page you create.<\/p>\n<p>Everything else that we will add to this page is situated inside of the Root Element. It is the container for every scrap of information and piece of content, the only exclusion being the DOCTYPE.<\/p>\n<h2>Head Element<\/h2>\n<p>The next thing you\u2019ll encounter in an HTML document is the \u201chead\u201d section. The head tag is exactly what you\u2019d expect it to be:<\/p>\n<div>\n<div>\n<div id=\"highlighter_598312\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;!-- Some Code Goes Here --&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>The stuff that goes into the head section is primarily informational, it tells both you and the browser certain things about the page such as the title, the charset, etc. This is also where you traditionally load in important external resources.<\/p>\n<p>There are a few important things that go into a head tag. Let\u2019s look at them one by one.<\/p>\n<h3>Meta Tags<\/h3>\n<p>As you can probably guess, meta tags hold metadata about the page. Metadata takes many forms and can include keywords, authors, descriptions, etc. Here are a few notable inclusions:<\/p>\n<p><strong>Charset<\/strong><br \/>\nThis is pretty boring stuff, the charset is typically set to <a href=\"http:\/\/en.wikipedia.org\/wiki\/UTF-8\">UTF-8<\/a> and essentially tells the browser which character encoding to use.<\/p>\n<p>Your pages should definitely include an indication of which charset to use. Don\u2019t over think it, it\u2019s just one of those things you need to stick in your template. Below is a typical charset declaration in HTML5.<\/p>\n<div>\n<div>\n<div id=\"highlighter_779252\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>meta<\/code> <code>charset<\/code><code>=<\/code><code>\"utf-8\"<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>This is yet another thing that has gotten easier with HTML5. Check out the version of this snippet required for HTML 4.01:<\/p>\n<div>\n<div>\n<div id=\"highlighter_540972\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>meta<\/code> <code>http-equiv<\/code><code>=<\/code><code>\"content-type\"<\/code> <code>content<\/code><code>=<\/code><code>\"text\/html; charset=UTF-8\"<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>Some other typical metatags include description and author. Here\u2019s a quick, self-explanatory example of each of these:<\/p>\n<p><strong>Description<\/strong><\/p>\n<div>\n<div>\n<div id=\"highlighter_468459\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>meta<\/code> <code>name<\/code><code>=<\/code><code>\"description\"<\/code> <code>content<\/code><code>=<\/code><code>\"Some description about your page\"<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>Author<\/strong><\/p>\n<div>\n<div>\n<div id=\"highlighter_540650\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>meta<\/code> <code>name<\/code><code>=<\/code><code>\"author\"<\/code> <code>content<\/code><code>=<\/code><code>\"Josh Johnson\"<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<h3>Title<\/h3>\n<p>Another thing that goes inside the head portion of your document is the title tag. This is a very simple piece of code that simply states whatever you\u2019d like the title of the page to be. Here\u2019s an example:<\/p>\n<div>\n<div>\n<div id=\"highlighter_729190\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>This title is usually shown to the user at the very top center of the browser window, on a tab, etc.<\/p>\n<div><img alt=\"screenshot\" src=\"http:\/\/designshack.net\/wp-content\/uploads\/htmlanatomy-1.jpg\" width=\"510\" \/><\/div>\n<h3>Links and Scripts<\/h3>\n<p>The last thing we\u2019ll discuss regarding the head tag is the inclusion of external resources. In a very simple web page, you\u2019ll typically see these take the form of a stylesheet or script:<\/p>\n<div>\n<div>\n<div id=\"highlighter_941226\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>link<\/code> <code>rel<\/code><code>=<\/code><code>\"stylesheet\"<\/code> <code>href<\/code><code>=<\/code><code>\"style.css\"<\/code><code>&gt;<\/code><\/div>\n<div><code>&lt;<\/code><code>script<\/code> <code>src<\/code><code>=<\/code><code>\"js\/jquery.js\"<\/code><code>&gt;&lt;\/<\/code><code>script<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>Here I\u2019m essentially loading my CSS file as well as jQuery (a JavaScript library) into the page. If these resources are included in the source files but not linked to in the head section, they will not function. Note that the links for these could either point to something in the local folder hierarchy (as above) or something hosted on another web server.<\/p>\n<p>The link used above for the CSS file uses a <em>link relation<\/em> (rel=\u201dstylesheet\u201d). For more on link relations, check out <a href=\"http:\/\/blog.whatwg.org\/the-road-to-html-5-link-relations\">this article<\/a>.<\/p>\n<p>Also, as an alternative to linking to external files, you can embed code right into the head element. Here\u2019s an example with CSS, but the same can be done via the \u201cscript\u201d tag and JavaScript (embedded scripts are often placed at the end of the body element instead).<\/p>\n<div>\n<div>\n<div id=\"highlighter_8036\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;<\/code><code>style<\/code> <code>type<\/code><code>=<\/code><code>\"text\/css\"<\/code><code>&gt;<\/code><\/div>\n<div><code>\u00a0\u00a0\u00a0\u00a0<\/code><code>a { text-decoration: none; }<\/code><\/div>\n<div><code>\u00a0\u00a0\u00a0\u00a0<\/code><code>p { color: #333; }<\/code><\/div>\n<div><code>&lt;\/<\/code><code>style<\/code><code>&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<h2>Body Element<\/h2>\n<p>The final portion of an HTML page is the most important. Everything inside of the body element defines the content and structure of your page. As far as development time, you\u2019ll likely use a set template for everything above and spend a few minutes customizing it for specific projects. The rest of your HTML time will be spend inside the body element.<\/p>\n<div>\n<div>\n<div id=\"highlighter_520269\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;!-- Page Content Goes Here --&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<h2>Putting it All Together<\/h2>\n<p>Now that we\u2019ve walked through each individual piece of an HTML file, let\u2019s put it all together into one extremely basic HTML5 template.<\/p>\n<div>\n<div>\n<div id=\"highlighter_258370\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>01<\/div>\n<div>02<\/div>\n<div>03<\/div>\n<div>04<\/div>\n<div>05<\/div>\n<div>06<\/div>\n<div>07<\/div>\n<div>08<\/div>\n<div>09<\/div>\n<div>10<\/div>\n<\/td>\n<td>\n<div>\n<div><code>\u00a0\u00a0<\/code><code>&lt;<\/code><code>meta<\/code> <code>charset<\/code><code>=<\/code><code>\"utf-8\"<\/code><code>&gt;<\/code><\/div>\n<div><code>\u00a0\u00a0<\/code><\/div>\n<div><code>\u00a0\u00a0<\/code><code>&lt;<\/code><code>meta<\/code> <code>name<\/code><code>=<\/code><code>\"description\"<\/code> <code>content<\/code><code>=<\/code><code>\"A Very Basic HTML5 Anatomy\"<\/code><code>&gt;<\/code><\/div>\n<div><code>\u00a0\u00a0<\/code><\/div>\n<div><code>\u00a0\u00a0<\/code><code>&lt;<\/code><code>link<\/code> <code>rel<\/code><code>=<\/code><code>\"stylesheet\"<\/code> <code>href<\/code><code>=<\/code><code>\"style.css\"<\/code><code>&gt;<\/code><\/div>\n<div><code>\u00a0\u00a0<\/code><code>&lt;<\/code><code>script<\/code> <code>src<\/code><code>=<\/code><code>\"js\/jquery.js\"<\/code><code>&gt;&lt;\/<\/code><code>script<\/code><code>&gt;<\/code><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><code>&lt;!-- Page Content Goes Here --&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<h2>An Overview<\/h2>\n<p>A thousand apologies for the mundane nature of this topic, beginners are often turned off by boredom at this point but hang in there, the real fun of HTML is everything between the body tags, which we haven\u2019t even discussed!<\/p>\n<p>All of these pieces were necessary to accurately paint the picture of what an HTML document actually is. We now see that an HTML document has a DOCTYPE that tells the browser how to render the page and helps ensure the proper standards are being used.<\/p>\n<p>We also know that there\u2019s a set hierarchy to how HTML pages are structured. Just about everything but the DOCTYPE is thrown into the root element, meaning it is the \u201cparent element\u201d of the head and body elements, which in turn have their own children.<\/p>\n<div><a href=\"http:\/\/designshack.net\/articles\/html\/deeper-study-into-the-wwws-document-object-model\/\"><img alt=\"screenshot\" src=\"http:\/\/designshack.net\/wp-content\/uploads\/dom-tree-graphic.jpg\" width=\"510\" \/><\/a><\/div>\n<p>The basic structure of an HTML document is referred to as the DOM, or the Document Object Model. This is almost always metaphorically referred to as a tree and depicted like image above. Our own Jack Rocheleau wrote an in-depth look into the DOM titled <a href=\"http:\/\/designshack.net\/articles\/html\/what-is-html-the-anatomy-of-an-html5-document\/Deeper%20Study%20Into%20the%20WWW%E2%80%99s%20Document%20Object%20Model\">Deeper Study Into the WWW\u2019s Document Object Model<\/a>. For the next set in understanding the basic structure of an HTML page, check out that article.<\/p>\n<h2>Conclusion<\/h2>\n<p>This article represents a very brief overview of how an HTML skeleton is structured and the types of things that are typically included. It is by no means exhaustive, but should serve as a good basic introduction to these topics.<\/p>\n<p>When you\u2019re just starting out in code, most people will simply give you a template for all of the code above without really explaining what it all does. This can leave a sizable hole in your education so it\u2019s important to read through this information and attempt to understand what you can.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DOCTYPE The very first thing that you typically see in an HTML file is the DOCTYPE declaration. Before HTML5, this could be a very confusing bit of code that looked something like this: 1 There\u2019s a lot going on here and every bit of it speaks to either the web browser, the reader or both. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[9,7],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/239"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}