Explore the Concept of Semantic HTML
In this step, you'll learn about semantic HTML and why it's important in web development. Semantic HTML uses tags that clearly describe the meaning of the content, making web pages more accessible, readable, and SEO-friendly.
Traditional HTML tags like <div>
and <span>
don't provide any information about the content they contain. In contrast, semantic HTML tags describe the purpose and structure of the content.
Let's create a simple HTML file to demonstrate semantic HTML concepts. Open the WebIDE and create a new file called semantic-example.html
in the ~/project
directory.
touch ~/project/semantic-example.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Semantic HTML Example</title>
</head>
<body>
<div>Website Header</div>
<div>Navigation Menu</div>
<div>Main Content</div>
<div>Sidebar</div>
<div>Footer</div>
</body>
</html>
Now, let's transform this example using semantic HTML tags:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Semantic HTML Example</title>
</head>
<body>
<header>Website Header</header>
<nav>Navigation Menu</nav>
<main>Main Content</main>
<aside>Sidebar</aside>
<footer>Footer</footer>
</body>
</html>
Key semantic HTML tags include:
<header>
: Represents introductory content
<nav>
: Defines navigation links
<main>
: Specifies the main content of the document
<article>
: Represents an independent, self-contained piece of content
<section>
: Defines a section in a document
<aside>
: Contains content tangentially related to the main content
<footer>
: Represents the footer of a document
Benefits of Semantic HTML:
- Improved accessibility for screen readers
- Better SEO optimization
- More meaningful and readable code
- Easier styling and maintenance
When you preview the HTML file in a browser, there won't be any visual changes, but the underlying structure will be more descriptive and meaningful.
Notes: Learn more about How to preview HTML files in the WebIDE.