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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<header><h1><mark>: The Mark Text element</h1></header><div class="section-content"><p>The <code><mark></code> <a href="../index">HTML</a> element represents text which is <strong>marked</strong> or <strong>highlighted</strong> for reference or notation purposes due to the marked passage's relevance in the enclosing context.</p></div>
<h2 id="try_it">Try it</h2>
<div class="section-content"><iframe class="interactive is-tabbed-shorter-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/mark.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe></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="usage_notes">Usage notes</h2>
<div class="section-content">
<p>Typical use cases for <code><mark></code> include:</p> <ul> <li>When used in a quotation (<a href="q"><code><q></code></a>) or block quote (<a href="blockquote"><code><blockquote></code></a>), it generally indicates text which is of special interest but is not marked in the original source material, or material which needs special scrutiny even though the original author didn't think it was of particular importance. Think of this like using a highlighter pen in a book to mark passages that you find of interest.</li> <li>Otherwise, <code><mark></code> indicates a portion of the document's content which is likely to be relevant to the user's current activity. This might be used, for example, to indicate the words that matched a search operation.</li> <li>Don't use <code><mark></code> for syntax highlighting purposes; instead, use the <a href="span"><code><span></code></a> element with appropriate CSS applied to it.</li> </ul> <div class="notecard note" id="sect1"> <p><strong>Note:</strong> Don't confuse <code><mark></code> with the <a href="strong"><code><strong></code></a> element; <code><mark></code> is used to denote content which has a degree of <em>relevance</em>, while <code><strong></code> indicates spans of text of <em>importance</em>.</p> </div>
</div>
<h2 id="examples">Examples</h2>
<h3 id="marking_text_of_interest">Marking text of interest</h3>
<div class="section-content">
<p>In this first example, a <code><mark></code> element is used to mark some text within a quote which is of particular interest to the user.</p> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="4nFU68jtDIfxzlLzp6KADHDnHc7VTZNPH7sKC4csKps=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>blockquote</span><span class="token punctuation">></span></span>
It is a period of civil war. Rebel spaceships, striking from a hidden base,
have won their first victory against the evil Galactic Empire. During the
battle, <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>mark</span><span class="token punctuation">></span></span>Rebel spies managed to steal secret plans<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>mark</span><span class="token punctuation">></span></span> to the Empire's
ultimate weapon, the DEATH STAR, an armored space station with enough power to
destroy an entire planet.
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>blockquote</span><span class="token punctuation">></span></span>
</pre>
</div> <h4 id="result">Result</h4>
<div class="code-example" id="sect2">
<iframe class="sample-code-frame" title="Marking text of interest sample" id="frame_marking_text_of_interest" width="650" height="130" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/mark/runner.html?id=marking_text_of_interest" loading="lazy"></iframe>
</div>
</div>
<h3 id="identifying_context-sensitive_passages">Identifying context-sensitive passages</h3>
<div class="section-content">
<p>This example demonstrates using <code><mark></code> to mark search results within a passage.</p> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="D6SMpiFU+fIknROdjuudwKfwL3OW6lKXKb1b4sfKCo4=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span>
It is a dark time for the Rebellion. Although the Death Star has been
destroyed, <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>mark</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>match<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Imperial<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>mark</span><span class="token punctuation">></span></span> troops have driven the Rebel
forces from their hidden base and pursued them across the galaxy.
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span>
Evading the dreaded <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>mark</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>match<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Imperial<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>mark</span><span class="token punctuation">></span></span> Starfleet, a group of
freedom fighters led by Luke Skywalker has established a new secret base on
the remote ice world of Hoth.
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>
</pre>
</div> <p>To help distinguish the use of <code><mark></code> for search results from other potential usage, this example applies the custom class <code>"match"</code> to each match.</p> <h4 id="result_2">Result</h4>
<div class="code-example" id="sect3">
<iframe class="sample-code-frame" title="Identifying context-sensitive passages sample" id="frame_identifying_context-sensitive_passages" width="650" height="130" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/mark/runner.html?id=identifying_context-sensitive_passages" loading="lazy"></iframe>
</div>
</div>
<h2 id="accessibility_concerns">Accessibility concerns</h2>
<div class="section-content">
<p>The presence of the <code>mark</code> element is not announced by most screen reading technology in its default configuration. It can be made to be announced by using the CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/content"><code>content</code></a> property, along with the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::before"><code>::before</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::after"><code>::after</code></a> pseudo-elements.</p> <div class="code-example">
<p class="example-header"><span class="language-name">css</span></p>
<pre data-signature="/z/NMcR/fBwUXyOBykZwJXigNSm/zDFjJ3jFTaJYz4E=" data-language="css"><span class="token selector">mark::before,
mark::after</span> <span class="token punctuation">{</span>
<span class="token property">clip-path</span><span class="token punctuation">:</span> <span class="token function">inset</span><span class="token punctuation">(</span>100%<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">clip</span><span class="token punctuation">:</span> <span class="token function">rect</span><span class="token punctuation">(</span>1px<span class="token punctuation">,</span> 1px<span class="token punctuation">,</span> 1px<span class="token punctuation">,</span> 1px<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">height</span><span class="token punctuation">:</span> 1px<span class="token punctuation">;</span>
<span class="token property">overflow</span><span class="token punctuation">:</span> hidden<span class="token punctuation">;</span>
<span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
<span class="token property">white-space</span><span class="token punctuation">:</span> nowrap<span class="token punctuation">;</span>
<span class="token property">width</span><span class="token punctuation">:</span> 1px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">mark::before</span> <span class="token punctuation">{</span>
<span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">" [highlight start] "</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">mark::after</span> <span class="token punctuation">{</span>
<span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">" [highlight end] "</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre>
</div> <p>Some people who use screen readers deliberately disable announcing content that creates extra verbosity. Because of this, it is important to not abuse this technique and only apply it in situations where not knowing content has been highlighted would adversely affect understanding.</p> <ul> <li><a href="https://www.tpgi.com/short-note-on-making-your-mark-more-accessible/" target="_blank">Short note on making your mark (more accessible) | The Paciello Group</a></li> <li><a href="https://adrianroselli.com/2017/12/tweaking-text-level-styles.html" target="_blank">Tweaking Text Level Styles | Adrian Roselli</a></li> </ul>
</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#phrasing_content">phrasing content</a>, palpable content. </td> </tr> <tr> <th scope="row">Permitted content</th> <td>
<a href="../content_categories#phrasing_content">Phrasing content</a>.</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#phrasing_content">phrasing content</a>. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role" target="_blank">No corresponding role</a></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>Any</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/text-level-semantics.html#the-mark-element">HTML Standard <br><small># the-mark-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>mark</code></th>
<td class="bc-supports-yes">7</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</td>
<td class="bc-supports-yes">5.1</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">14</td>
<td class="bc-supports-yes">5</td>
<td class="bc-supports-yes">1.0</td>
</tr></tbody>
</table></div><div class="_attribution">
<p class="_attribution-p">
© 2005–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/mark" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark</a>
</p>
</div>
|