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
<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:
My bold text and my bold and emphasized text
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
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up
This tutorial series will guide you through creating and further customizing this website using HTML, the standard markup language used to display documents in a web browser. No prior coding experience is necessary but we recommend you start at the beginning of the series if you wish to recreate the demonstration website.
Click below to sign up and get $100 of credit to try our products over 60 days!