Copied successfully!
Introduction to <header>
tag
The <header>tag in HTML is a semantic element that defines a container for introductory content or a set of navigational links. It's commonly used to represent the header of a webpage or a section, containing elements like headings, logos, navigation menus, and other introductory content. The <header>element helps improve the structure and readability of a webpage by clearly indicating the beginning of a page or a section.
Key Features of the <header>
Tag
Semantic Meaning: The <header>tag provides semantic meaning to your HTML document. It indicates that the content enclosed within it is introductory or represents the start of a webpage or a specific section.
Multiple Uses: You can use multiple <header>tags on a single webpage. For example, a main <header>at the top of the page and separate <header>elements for different sections or articles within the page.
Content Flexibility: The <header>element can contain various types of content, including:
- Headings (<h1>to <h6>): To introduce the page or section.
- Logos or Branding: To visually represent the site or company.
- Navigation Elements (<nav>): To provide a navigational menu or links to other parts of the site.
- Search Forms: To include search functionality.
Accessibility: Using the <header>tag improves accessibility for screen readers and assistive technologies. It allows these tools to better understand the structure and purpose of the content, enhancing user experience for individuals with disabilities.
SEO Benefits: The <header>tag can positively impact SEO (Search Engine Optimization) by making the structure of the webpage clearer to search engines. It helps search engines understand which content is introductory or navigational, potentially improving the page's ranking.
Best Practices for Using the <header>Tag
- Use It Wisely: While you can use multiple <header>elements on a page, avoid overusing them. Only use the <header>tag for content that serves as an introduction or provides navigational context.
- Combine with Other Semantic Tags: The <header>element works well with other semantic tags like <nav>, <main>, <article>, and <footer>. Using these tags together creates a well-structured and semantically rich HTML document.
- Avoid Redundant Content: Do not use the <header>tag to wrap content that is not introductory or navigational, such as large blocks of text or unrelated media elements.
Copy to clipboard
<!-- Header Example -->
<header class="custom-header">
<h1>Site Logo</h1>
<nav class="main-nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
Copy to clipboard
/* CSS for Header */
.custom-header {
background-color: #f8f8f8;
padding: 20px;
text-align: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.main-nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.main-nav li {
display: inline;
margin: 0 15px;
}
.main-nav a {
text-decoration: none;
color: #333;
font-weight: bold;
}
.main-nav a:hover {
color: #5cb85c;
}
Global Attributes
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<header> | 5.0 | 9.0 | 4.0 | 5.0 | 11.1 |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on by our contributors.
View this page on GitHub• Report an issue with this content