This tutorial aims to enable you to structure your web content more effectively using semantic tags in HTML. By the end of this tutorial, you will have a solid understanding of how semantic HTML can lead to more readable and accessible code, and you'll be able to apply semantic HTML in your own projects.
Prerequisites: Basic knowledge of HTML and web development.
Semantic HTML involves using HTML5 tags that provide meaning to the structure of the content on the web page. It makes the webpage more accessible and improves its SEO.
Examples of semantic tags include <header>
, <footer>
, <article>
, <section>
, <nav>
, etc. These tags tell the browser and the developer about the type of content they contain.
<div>
for everything.<nav>
for navigation, <main>
for the main content, and <footer>
for the footer content.<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<header>
<!-- This is where your header content (like a logo or a title) goes -->
</header>
<nav>
<!-- This is where your navigation links go -->
</nav>
<main>
<!-- This is where the main content of your webpage goes -->
</main>
<footer>
<!-- This is where your footer content goes -->
</footer>
</body>
</html>
<main>
<article>
<header>
<h1>Article Title</h1>
</header>
<p>Article content goes here.</p>
<footer>
<p>Published on: date</p>
</footer>
</article>
</main>
In this example, we used <article>
, <header>
, <footer>
tags within the <main>
tag to structure the content of an article.
In this tutorial, we've covered the basics of semantic HTML, including what it is, why it's important, and how you can implement it in your web pages. We've also provided examples and best practices for you to follow.
The next step in your learning journey could be to explore more advanced HTML topics, or to learn about CSS and JavaScript to add style and interactivity to your web pages.
<!DOCTYPE html>
<html>
<head>
<title>Basic Web Page</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Contact</a>
</nav>
<main>
<p>This is where the main content of your webpage goes.</p>
</main>
<footer>
<p>Copyright © 2022</p>
</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Blog Post</title>
</head>
<body>
<header>
<h1>Blog Title</h1>
</header>
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Contact</a>
</nav>
<main>
<article>
<header>
<h2>Post Title</h2>
</header>
<p>Post content goes here.</p>
<footer>
<p>Published on: date</p>
</footer>
</article>
</main>
<footer>
<p>Copyright © 2022</p>
</footer>
</body>
</html>
Remember to practice and experiment with different semantic tags to get a better understanding of how they work.