summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fheader.html
blob: 70bbebcef90885cf014bc8e11df61bb10287a6ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<header><h1>&lt;header&gt;</h1></header><div class="section-content"><p>The <code>&lt;header&gt;</code> <a href="../index">HTML</a> element represents introductory content, typically a group of introductory or navigational aids. It may contain some heading elements but also a logo, a search form, an author name, and other elements.</p></div>
<h2 id="try_it">Try it</h2>
<div class="section-content"><iframe class="interactive is-tabbed-standard-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/header.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe></div>
<h2 id="usage_notes">Usage notes</h2>
<div class="section-content">
<p>The <code>&lt;header&gt;</code> element has an identical meaning to the site-wide <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/banner_role"><code>banner</code></a> landmark role, unless nested within sectioning content. Then, the <code>&lt;header&gt;</code> element is not a landmark.</p> <p>The <code>&lt;header&gt;</code> element can define a global site header, described as a <code>banner</code> in the accessibility tree. It usually includes a logo, company name, search feature, and possibly the global navigation or a slogan. It is generally located at the top of the page.</p> <p>Otherwise, it is a <code>section</code> in the accessibility tree, and usually contains the surrounding section's heading (an <code>h1</code> – <code>h6</code> element) and optional subheading, but this is <strong>not</strong> required.</p>
</div>
<h3 id="historical_usage">Historical Usage</h3>
<div class="section-content"><p>The <code>&lt;header&gt;</code> element originally existed at the very beginning of HTML for headings. It is seen in <a href="http://info.cern.ch/" target="_blank">the very first website</a>. At some point, headings became <a href="heading_elements"><code>&lt;h1&gt;</code> through <code>&lt;h6&gt;</code></a>, allowing <code>&lt;header&gt;</code> to be free to fill a different role.</p></div>
<h2 id="attributes">Attributes</h2>
<div class="section-content"><p>This element only includes the <a href="../global_attributes">global attributes</a>.</p></div>
<h2 id="examples">Examples</h2>

<h3 id="page_header">Page Header</h3>
<div class="section-content">
<div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="L7G//UQoT92KxgsueTIW6FV6GliHEvXaRlvwzGdZISw=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>header</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">&gt;</span></span>Main Page Title<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>mdn-logo-sm.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MDN logo<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>header</span><span class="token punctuation">&gt;</span></span>
</pre>
</div> <h4 id="result">Result</h4>
<div class="code-example" id="sect1">

<iframe class="sample-code-frame" title="Page Header sample" id="frame_page_header" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/header/runner.html?id=page_header" loading="lazy"></iframe>
</div>
</div>
<h3 id="article_header">Article Header</h3>
<div class="section-content">
<div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="8qwCAfsFt1eZe7t6xqKtQ2bLcTo97qCPxkqbd0pjmU4=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>article</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>header</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">&gt;</span></span>The Planet Earth<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
      Posted on Wednesday, <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>time</span> <span class="token attr-name">datetime</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2017-10-04<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>4 October 2017<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>time</span><span class="token punctuation">&gt;</span></span> by
      Jane Smith
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>header</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
    We live on a planet that's blue and green, with so many things still unseen.
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://example.com/the-planet-earth/<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Continue reading…<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>article</span><span class="token punctuation">&gt;</span></span>
</pre>
</div> <h4 id="result_2">Result</h4>
<div class="code-example" id="sect2">

<iframe class="sample-code-frame" title="Article Header sample" id="frame_article_header" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/header/runner.html?id=article_header" loading="lazy"></iframe>
</div>
</div>
<h2 id="accessibility">Accessibility</h2>
<div class="section-content"><p>The <code>&lt;header&gt;</code> element defines a <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/banner_role"><code>banner</code></a> landmark when its context is the <a href="body"><code>&lt;body&gt;</code></a> element. The HTML header element is not considered a banner landmark when it is descendant of an <a href="article"><code>&lt;article&gt;</code></a>, <a href="aside"><code>&lt;aside&gt;</code></a>, <a href="main"><code>&lt;main&gt;</code></a>, <a href="nav"><code>&lt;nav&gt;</code></a>, or <a href="section"><code>&lt;section&gt;</code></a> element.</p></div>
<h2 id="technical_summary">Technical summary</h2>
<div class="section-content"><figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td> <a href="../content_categories#flow_content">Flow content</a>, <a href="../content_categories#palpable_content">palpable content</a>. </td> </tr> <tr> <th scope="row">Permitted content</th> <td> <a href="../content_categories#flow_content">Flow content</a>, but with no <code>&lt;header&gt;</code> or <a href="footer"><code>&lt;footer&gt;</code></a> descendant. </td> </tr> <tr> <th scope="row">Tag omission</th> <td>None, both the starting and ending tag are mandatory.</td> </tr> <tr> <th scope="row">Permitted parents</th> <td> Any element that accepts <a href="../content_categories#flow_content">flow content</a>. Note that a <code>&lt;header&gt;</code> element must not be a descendant of an <a href="address"><code>&lt;address&gt;</code></a>, <a href="footer"><code>&lt;footer&gt;</code></a> or another <a href="header" aria-current="page"><code>&lt;header&gt;</code></a> element. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td> <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/banner_role">banner</a>, or <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/generic_role">generic</a> if a descendant of an <code><a href="article">article</a></code>, <code><a href="aside">aside</a></code>, <code><a href="main">main</a></code>, <code><a href="nav">nav</a></code> or <code><a href="section">section</a></code> element, or an element with <code>role=<a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/article_role">article</a></code>, <code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/complementary_role">complementary</a></code>, <code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/main_role">main</a></code>, <code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/navigation_role">navigation</a></code> or <code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/region_role">region</a></code> </td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td> <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/group_role"><code>group</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/presentation_role"><code>presentation</code></a> or <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/none_role"><code>none</code></a> </td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement"><code>HTMLElement</code></a></td> </tr> </tbody> </table></div></figure></div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/sections.html#the-header-element">HTML Standard <br><small># the-header-element</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody><tr>
<th><code>header</code></th>
<td class="bc-supports-yes">5</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">9</td>
<td class="bc-supports-yes">11.1</td>
<td class="bc-supports-yes">5</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">11.1</td>
<td class="bc-supports-yes">4.2</td>
<td class="bc-supports-yes">1.0</td>
</tr></tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li>Other section-related elements: <a href="body"><code>&lt;body&gt;</code></a>, <a href="nav"><code>&lt;nav&gt;</code></a>, <a href="article"><code>&lt;article&gt;</code></a>, <a href="aside"><code>&lt;aside&gt;</code></a>, <a href="heading_elements">h1</a>, <a href="heading_elements">h2</a>, <a href="heading_elements">h3</a>, <a href="heading_elements">h4</a>, <a href="heading_elements">h5</a>, <a href="heading_elements">h6</a>, <a href="footer"><code>&lt;footer&gt;</code></a>, <a href="section"><code>&lt;section&gt;</code></a>, <a href="address"><code>&lt;address&gt;</code></a>.</li> </ul></div><div class="_attribution">
  <p class="_attribution-p">
    &copy; 2005&ndash;2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
    <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header</a>
  </p>
</div>