HTML 标记文本元素
(
<mark>
) represents text which is
marked
or
highlighted
for reference or notation purposes, due to the marked passage's relevance or importance in the enclosing context.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
| 内容类别 | 流内容 , 措词内容 ,可触及内容。 |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts 措词内容 . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles | 任何 |
| DOM 接口 |
HTMLElement
|
此元素只包括 全局属性 .
Typical use cases for
<mark>
include:
<q>
) or block quote (
<blockquote>
), 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.
<mark>
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.
<mark>
for syntax highlighting purposes; instead, use the
<span>
element with appropriate CSS applied to it.
Don't confuse
<mark>
采用
<strong>
element;
<mark>
is used to denote content which has a degree of
relevance
,而
<strong>
indicates spans of text of
importance
.
In this first example, a
<mark>
element is used to mark some text within a quote which is of particular interest to the user.
<blockquote> 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, <mark>Rebel spies managed to steal secret plans</mark> to the Empire’s ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet. </blockquote>
The resulting output looks like this:
This example demonstrates using
<mark>
to mark search results within a passage.
<p>It is a dark time for the Rebellion. Although the Death Star has been destroyed, <mark class="match">Imperial</mark> troops have driven the Rebel forces from their hidden base and pursued them across the galaxy.</p> <p>Evading the dreaded <mark class="match">Imperial</mark> Starfleet, a group of freedom fighters led by Luke Skywalker has established a new secret base on the remote ice world of Hoth.</p>
To help distinguish the use of
<mark>
for search results from other potential usage, this example applies the custom class
"match"
to each match.
The results look like this:
The presence of the
mark
element is not announced by most screen reading technology in its default configuration. It can be made to be announced by using the CSS
content
property, along with the
::before
and
::after
pseudo-elements.
mark::before,
mark::after {
clip-path: inset(100%);
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
mark::before {
content: " [highlight start] ";
}
mark::after {
content: " [highlight end] ";
}
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.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of '<mark>' in that specification. |
实时标准 | |
|
HTML5
The definition of '<mark>' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mark
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 4 | IE 完整支持 9 | Opera 完整支持 11 | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持