Why Use Semantic HTML?

Convey meaning with HTML

An important principle in web design is the idea of using HTML elements to indicate what they actually are, rather than how they may appear in the browser by default. This is known as using semantic HTML.

What Is Semantic HTML?

Semantic HTML or semantic markup is HTML that introduces meaning to the web page rather than just presentation. For example, a <p> tag indicates that the enclosed text is a paragraph. This is both semantic and presentational because people know what paragraphs are, and browsers know how to display them.

On the flip side of this equation, tags such as <b> and <i> are not semantic. They define only how the text should look (bold or italic), and don't provide any additional meaning to the markup.

Examples of semantic HTML tags include:

  • Header tags <h1> through <h6>
  • <blockquote>
  • <code>
  • <em>

There are many more semantic HTML tags to use as you build a standards-compliant website.

Why You Should Care About Semantics

The benefit of writing semantic HTML stems from what should be the driving goal of any web page: the desire to communicate. By adding semantic tags to your document, you provide additional information about that document, which aids in communication. Specifically, semantic tags make it clear to the browser what the meaning of a page and its content is. That clarity is also communicated with search engines, ensuring that the right pages are delivered for the right queries.

Semantic HTML tags provide information about the contents of those tags that goes beyond just how they look on a page. Text that is enclosed in the <code> tag is immediately recognized by the browser as some type of coding language. Instead of trying to render that code, the browser understands that you are using that text as an example of the code for the purposes of an article or online tutorial.

Using semantic tags gives you many more hooks for styling your content, too. Perhaps today you prefer to have your code samples display in the default browser style, but tomorrow, you might want to call them out with a gray background color; later still, you might want to define the precise mono-spaced font family or font stack to use for your samples. You can do all of these things easily by using semantic markup and smartly applied CSS.

Using Semantic Tags Correctly

When using semantic tags to convey meaning rather than for presentation purposes, be careful that you don't use them incorrectly simply for their common display properties. Some of the most commonly misused semantic tags include:

  • blockquote — Some people use the <blockquote> tag for indenting text that is not a quotation. This is because blockquotes are indented by default. If you simply want to indent text that's not a blockquote, use CSS margins instead.
  • p — Some web editors use <p>&nbsp;</p> (a non-breaking space contained in a paragraph) to add extra space between page elements, rather than defining actual paragraphs for the text of that page. As in the previous example, you should use the margin or padding style property instead to add space.​
  • ul — As with <blockquote>, enclosing text inside a <ul> tag indents that text in most browsers. This is both semantically incorrect and invalid HTML, because only <li> tags are valid within a <ul> tag. Again, use the margin or padding style to indent text.
  • h1, h2, h3, h4, h5, and h6 — You can use heading tags to make fonts bigger and bolder, but if the text is not a heading, use the font-weight and font-size CSS properties instead.

By using HTML tags that have meaning, you create pages that impart more information than those that simply surround everything with <div> tags. 

Which HTML Tags Are Semantic?

Although nearly every HTML4 tag and all the HTML5 tags have semantic meanings, some tags are primarily semantic.

For example, HTML5 has redefined the meaning of the <b> and <i> tags to be semantic. The <b> tag doesn't convey extra importance; rather, the tagged text is typically rendered in bold. Likewise, the <i> tag doesn't convey extra importance or emphasis; rather, it defines text that is typically rendered in italics.

Semantic HTML Tags

<abbr> Abbreviation
<acronym> Acronym
<blockquote> Long quotation
<dfn> Definition
<address> Address for author(s) of the document
<cite> Citation
<code> Code reference
<tt> Teletype text
<div> Logical division
<span> Generic inline style container
<del> Deleted text
<ins> Inserted text
<em> Emphasis
<strong> Strong emphasis
<h1> First-level headline
<h2> Second-level headline
<h3> Third-level headline
<h4> Fourth-level headline
<h5> Fifth-level headline
<h6> Sixth-level headline
<hr> Thematic break
<kbd> Text to be entered by the user
<pre> Pre-formatted text
<q> Short inline quotation
<samp> Sample output
<sub> Subscript
<sup> Superscript
<var> Variable or user defined text
Format
mla apa chicago
Your Citation
Kyrnin, Jennifer. "Why Use Semantic HTML?" ThoughtCo, Jul. 31, 2021, thoughtco.com/why-use-semantic-html-3468271. Kyrnin, Jennifer. (2021, July 31). Why Use Semantic HTML? Retrieved from https://www.thoughtco.com/why-use-semantic-html-3468271 Kyrnin, Jennifer. "Why Use Semantic HTML?" ThoughtCo. https://www.thoughtco.com/why-use-semantic-html-3468271 (accessed April 19, 2024).