Table of Contents
This tutorial will teach you how to nest HTML elements in order to apply multiple HTML tags to a single piece of content.
HTML elements can be *nested*, meaning that one element can be placed inside another element. Nesting allows you to apply multiple HTML tags to a single piece of content. For example, try pasting the following code snippet inside your index.html file:
<strong>My bold text and <em>my bold and emphasized text</em></strong>
Save your file and reload it in the browser. (For instructions on creating an index.html file, please see our tutorial here or for loading the file in your browser, see our tutorial here.) You should receive something like this:
<strong>My bold text and <em>my bold and emphasized text</em></strong>
Nesting Best Practices
Note that it is recommended to always close nested tags in the reverse order that they were opened.
For example, in the example below, the <em> tag closes first as it was the last tag to open. The <strong> tag closes last as it was the first to open.
This sentence contains HTML elements that are <strong><em>nested according to best practices</em></strong>.
As a counter example, the following HTML code contains tags that are *not* nested according to best practices, as the <strong> tag closes *before* the <em> tag:
This sentence contains HTML elements that are <strong><em>not nested according to best practices</strong></em>.
While not technically necessary for rendering your HTML in the browser, nesting your tags in the proper order can help improve the readability of your HTML code for you or other developers.