What are Semantic Elements?
Semantic elements in HTML are tags that carry meaning about the structure and content of a web page. Unlike non-semantic elements, which are mainly used for presentation purposes and do not convey specific meaning, semantic elements provide information about the role and importance of the enclosed content. This helps browsers, search engines, and developers understand the document's structure and improve accessibility.
Here are some common semantic elements in HTML:
Semantic Elements in HTML
- <header>
- <nav>
- <article>
- <section>
- <aside>
- <footer>
<header>:
Represents the header of a document or section and can contain headings, logos, navigation, etc.
<nav>: Defines a navigation menu, typically containing links to other pages or sections within the website.
<article>: Represents a self-contained piece of content that could be distributed and reused independently, such as a news article, blog post, or forum post.
<section>: Defines a section of content with a related theme or purpose. It is a generic container and does not imply a specific meaning.
<aside>: Represents content that is tangentially related to the content around it, such as a sidebar, pull quote, or related links.
<footer>: Represents the footer of a document or section, often containing copyright information, links to terms of service, or contact information.
Example
<footer> <p>© 2024 Your Website<</p> </footer>You can click on above box to edit the code and run again.
Output
Using semantic elements not only improves the structure and readability of your HTML but also helps assistive technologies, search engines, and other tools understand the content and context of your web pages. It's a good practice to use semantic elements where appropriate to create well-organized and accessible web documents.