Saturday, June 22, 2024

Ten HTML Tags for More Modern Pages

HTML Tutorial

Most modern web developers dig into HTML tags as they create web pages. If you have been writing HTML for a while, then you are used to using a variety of standard tags ranging from  and <embed> to <table>. Over time, however, the best tags used to obtain the most value from your HTML have changed. Indeed, HTML has evolved from being just simple markup to something that is more semantic in nature. 

By evolving to a more semantic paradigm, HTML markup not only indicates to a browser how to display the content of your web page, but it can also present the context of your markup. This context can be used to get more value from the content, whether in your own programs or by third parties, including the search engines.

How to Modernize HTML

So, what are a few of the key things in HTML that you should be using today to get the most semantic value? In the following web development tutorial, I will present 10 HTML tags that can help give your pages much more meaning.

Expanding <Body> to Include Header, Footer, and Main Sections

While you have a body in your HTML document identified with a <body> tag, web developers should (or could) also have header, footer, and main sections. Each of these help to organize the overall content within your HTML document. 

The <header> tag is not the same thing as the <head> tag. The <head> tag comes before the <body> tag and generally includes metadata that is not displayed. While it can contain other tags (including scripting), it is outside of the main HTML document’s <body> tag.

The <header> tag is placed within the <body> tag. It should be used instead of a <div> or other tag to contain the introductory content and navigational links presented in the current HTML document. This can include headings, a logo or icon for the page, and other information. Here is an example use of a header tag:


  <h1>My Page Heading</h1>

  <!-- My page Navigation --> 


The <footer> tag is also placed within the <body> tag and is generally used to contain information that would go at the foot of a page; items such as sitemap, contact information, navigational links, authorship information, copyright information, and a link to terms of use.

Finally, the <main> tag is used to contain the unique content on the given page. Structures on your page that carry over to other pages such as the header, footer, and side elements should not be contained in the <main> tag. 


Navigation on a Page with <nav>

As mentioned, the navigation on a page often happens in the header. To help better present your HTML content, you can identify and contain your primary navigation with a <nav> tag. The <nav> tag is generally used to identify a list of navigation links. Here is an example of how to use the <nav> tag in HTML:


  <a href="/java/">Java</a> |

  <a href="/ms/">Microsoft and .NET</a> |

  <a href="/lang/">Languages</a> |

  <a href="/mobile/">Mobile</a>

  <a href="/guides/">Guides</a>

  <a href="/arch/">Architecture and Design</a>

  <a href="/more/">More</a>


Articles and Asides in HTML

While the <footer>, <main>, and <header> tags help align the main areas of your page, you should also identify the content – or articles – within your page. While this has often been done with <div> tags, it is better to be more explicit and use the <article> tag. You can use the <article> tags around the specific article content. If you have more than one article on a page, then each can be wrapped in its own tags. 

Sometimes within page content or an article, additional information is included. This is often indirectly related to what is being stated. For example, an article might include a comment about a related topic or provide information on where the reader can go for additional information. This added information can be wrapped in an <aside> tag to help better identify it. The <aside> tag is generally used within the content of <article> tags or within the sidebar content on a document.

Dump Embed for <Audio> and <Video>

If you have been using the <embed> tag, then you should stop. You should switch to a more specific tag such as <audio>, <video>, or <img>. In many cases, if you are still using the <embed> tag, you might find that there are browsers that do not display your content properly. 

The <video> tag can be used to embed a video into your web document, such as a movie clip or video stream. It is generally used with one or more <source> tags that identify the content to be displayed. If more than one <source> tag is included, then the browser will look for the first one with a video type supported by the browser. Most browsers support MP4, WebM, and Ogg formats (Safari might not support Ogg). The overall format of embedding a video is:

<video width="640" height="480" controls>

  <source src="movie.mp4" type="video/mp4">

  Your browser does not support the video tag.


The text included within the <video> tag will only be displayed if the source video format is not supported.

The <audio> tag works in the same way but plays an audio file. Like with the <video> tag, you can include a “controls” attribute that will display audio controls as well. The following would play the sound.mp3 audio file:

<audio width="640" height="480" controls>

  <source src="sound.mp3" type="audio/mp3">

  Your browser does not support the audio tag.


Grouping Images with a Caption in HTML

The <img> tag should be familiar to anyone that has done HTML. In the past, if you included a caption with an image, you might have helped organize your HTML by enclosing the image and caption in a <div> tag:


  <img src=”” alt=”my image”>

  <br>My image caption


While this works, it is not the best way to create the most meaningful HTML. Rather, the first thing you should change is to use a <figure> tag to enclose the image and caption instead of the <div> tag. The <figure> tag helps to clarify and identify that an image or photograph is being included. Additionally, the figure caption can be identified with a <figcaption> HTML tag. The following presents more meaningful HTML for displaying the same image. Here is how you use the <figure> and <figcaption> tags in HTML:


  <img src=”” alt=”my image”>

  <figcaption>My image caption</figcaption>


To <Div> or not to <Div>

Most of the tags presented in this article replace what is commonly done with <div> tags and <span> tags. While these tags can continue to be used, any time you can be more specific with what is within your document, you increase the semantic and overall value of your page. As such, if you find you are using a <div>, you should stop and consider whether there is another, more appropriate, tag. Of course, using <div> tags is better than not using any tagging to structure your content. 

Modernizing HTML Tutorial

All the tags presented in this article are basic HTML, with many having been introduced with HTML5. While ten tags are presented to help make your code easier to read and more meaningful semantically, there are other tags that have been added as well. The main takeaway is that as HTML evolves, tags are being added to help make your markup not only easier to read, but also more meaningful to others that need to take a closer look as well, including search engines. If search engines understand your markup better, then they are more likely to present your page higher in the search engine page results or SERPs, leading to more traffic to your website.

Read more HTML5 web development and programming tutorials.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Popular Articles