(window.webpackJsonp=window.webpackJsonp||[]).push([[59],{556:function(e,t,a){"use strict";a.r(t);var s=a(56),n=Object(s.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"html-container-elements"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#html-container-elements"}},[e._v("#")]),e._v(" HTML container elements")]),e._v(" "),a("p",[e._v("Now that we've looked at which elements "),a("em",[e._v("can't")]),e._v(" be nested, let's take a look at some elements which are specifically designed to contain other elements.")]),e._v(" "),a("div",{pre:!0},[a("h2",{pre:!0,attrs:{id:"section-elements"}},[a("a",{pre:!0,attrs:{class:"header-anchor",href:"#section-elements"}},[e._v("#")]),e._v(" "),a("code",[e._v("
")]),e._v(" elements")])]),a("p",[e._v("The content of a "),a("code",[e._v("
")]),e._v(" element represent a thematically related group of elements, but which form a component of a larger whole.")]),e._v(" "),a("p",[e._v("For example, perhaps we have a website with several blog posts on the home page, but the home page also features an area with links to various pieces of merchandise. There is a clear division in the content here, with the blogs being one thematically related group, and ther merch links being another.")]),e._v(" "),a("p",[e._v("We could use "),a("code",[e._v("
")]),e._v(" elements to distinguish these two distinct groups.")]),e._v(" "),a("div",{staticClass:"language-html extra-class"},[a("pre",{pre:!0,attrs:{class:"language-html"}},[a("code",[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("body")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("section")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("\x3c!-- Merch items --\x3e")]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("section")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("\x3c!-- Blog posts --\x3e")]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n")])])]),a("div",{staticClass:"custom-block tip"},[a("p",{staticClass:"custom-block-title"},[e._v("An alternative approach to the merch store")]),e._v(" "),a("p",[e._v("In a moment we're going to discuss another element called "),a("code",[e._v("
")]),e._v(". In the example above, it may actually make more sense to wrap the merch section in an "),a("code",[e._v("
")]),e._v(" element instead.")]),e._v(" "),a("p",[e._v("See what you think after reading the section on "),a("code",[e._v("
")]),e._v(" elements.")])]),e._v(" "),a("p",[e._v("We can also place sections within other elements, including within other "),a("code",[e._v("
")]),e._v(" elements. Our individual blog posts might have subsections, for example, and perhaps we have different types of merch on sale.")]),e._v(" "),a("p",[e._v("As a general rule of thumb, "),a("code",[e._v("
")]),e._v(" elements should contain headings, but this isn't a requirement. If you're writing a heading somewhere on your site, it's probably because you're marking a shift in topic, and this is often a good indicator of where a new section begins.")]),e._v(" "),a("div",{pre:!0},[a("h2",{pre:!0,attrs:{id:"article-elements"}},[a("a",{pre:!0,attrs:{class:"header-anchor",href:"#article-elements"}},[e._v("#")]),e._v(" "),a("code",[e._v("
")]),e._v(" elements")])]),a("p",[a("code",[e._v("
")]),e._v(' elements are a somewhat tricky element to understand, because the name "article" comes with a lot of conceptual baggage.')]),e._v(" "),a("p",[e._v("An "),a("code",[e._v("
")]),e._v(" element is used to mark a self-contained composition within a document. That means the content makes sense on its own as a standalone work. In the example site we talked about when discussing "),a("code",[e._v("
")]),e._v(", the individual blog posts would have been wrapped in "),a("code",[e._v("
")]),e._v(" elements, but likely so would the little cards containing the information for the merch items.")]),e._v(" "),a("p",[e._v("The MDN has another "),a("a",{attrs:{href:"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article",target:"_blank",rel:"noopener noreferrer"}},[e._v("really good example"),a("OutboundLink")],1),e._v(" of using "),a("code",[e._v("
")]),e._v(" elements:")]),e._v(" "),a("div",{staticClass:"language-html extra-class"},[a("pre",{pre:!0,attrs:{class:"language-html"}},[a("code",[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("article")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[e._v("class")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')]),e._v("forecast"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("h1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("Weather forecast for Seattle"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("article")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[e._v("class")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')]),e._v("day-forecast"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("h2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("03 March 2018"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("p")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("Rain."),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("article")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[e._v("class")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')]),e._v("day-forecast"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("h2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("04 March 2018"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("p")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("Periods of rain."),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("article")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[e._v("class")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')]),e._v("day-forecast"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("h2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("05 March 2018"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("<")]),e._v("p")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(">")])]),e._v("Heavy rain."),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("")])]),e._v("\n")])])]),a("p",[e._v("Here they have a weather forecast widget which is wrapped in an "),a("code",[e._v("
")]),e._v(" element.")]),e._v(" "),a("p",[e._v("This may seem a little weird, but if we think back to what an "),a("code",[e._v("
")]),e._v(" is really for, it's a perfectly reasonable use case. The forecast widget makes sense completely on its own. It's a self-contained composition that makes sense removed from the content around it.")]),e._v(" "),a("p",[e._v("One interesting thing, however, is that the "),a("code",[e._v("
")]),e._v(" contains other "),a("code",[e._v("
")]),e._v(" elements. Each of the daily forecasts is also wrapped in an "),a("code",[e._v("
")]),e._v(". This again makes some sense. We can completely understand the meaning of the forecasts for the individual days, even if we pluck them out of the contect of the weather widget. Many people have something very similar on their desktops after all, or as a widget on their phone.")]),e._v(" "),a("p",[a("code",[e._v("
")]),e._v(" elements are actually one of your go-to elements, so don't forget about them.")]),e._v(" "),a("div",{pre:!0},[a("h2",{pre:!0,attrs:{id:"div-elements"}},[a("a",{pre:!0,attrs:{class:"header-anchor",href:"#div-elements"}},[e._v("#")]),e._v(" "),a("code",[e._v("
")]),e._v(" elements")])]),a("p",[a("code",[e._v("
")]),e._v(" elements, much like "),a("code",[e._v("")]),e._v(" elements, are very generic by design. They don't carry any inherent meaning, which makes them very useful as generic grouping elements.")]),e._v(" "),a("p",[e._v("We use "),a("code",[e._v("
")]),e._v(" elements primarily to aid in styling a page or to add behaviour to some section of the browser window.")]),e._v(" "),a("p",[e._v("They should be used very sparingly, because we have a lot of more specific container types which describe the content of our document far better, such as "),a("code",[e._v("
")]),e._v(".")]),e._v(" "),a("p",[e._v("When you're about to add "),a("code",[e._v("
")]),e._v(" to your document, take a moment to think if there's something which you can use instead which better describes the group of elements you're placing inside the "),a("code",[e._v("
")]),e._v(".")]),e._v(" "),a("div",{pre:!0},[a("h2",{pre:!0,attrs:{id:"header-elements"}},[a("a",{pre:!0,attrs:{class:"header-anchor",href:"#header-elements"}},[e._v("#")]),e._v(" "),a("code",[e._v("
")]),e._v(" elements")])]),a("p",[a("code",[e._v("
")]),e._v(" elements are used for introductory content, or things like a header bar which contains a logo and navigation links. In this context the "),a("code",[e._v("
")]),e._v(" element's content is not really vital to the site. If we switch out the logo and change the menu, the overall meaning of the page likely hasn't changed at all.")]),e._v(" "),a("p",[e._v("We can actually have several "),a("code",[e._v("
")]),e._v(" elements in a document, and they're permitted inside other elements, such as "),a("code",[e._v("
")]),e._v(" elements.")]),e._v(" "),a("p",[e._v("We can see this in the documentation on the "),a("a",{attrs:{href:"https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML_sections_and_outlines#Other_Semantic_HTML_elements_used_in_Sectioning",target:"_blank",rel:"noopener noreferrer"}},[e._v("MDN Web Docs"),a("OutboundLink")],1),e._v(":")]),e._v(" "),a("blockquote",[a("p",[e._v("The header can also be used inside other semantic elements such as "),a("code",[e._v("
")]),e._v(" or "),a("code",[e._v("
")]),e._v(". A section header might contain the section's heading, author name, etc. "),a("code",[e._v("
")]),e._v(", "),a("code",[e._v("
")]),e._v(", "),a("code",[e._v("