Highlighting Relevant Text With HTML mark
The HTML <mark> element highlights text because it is relevant to the current context. A search-results page is a good example: the matching words matter because of what the person searched for.
<p>
Results for <mark>semantic HTML</mark>
</p>
Browsers normally give marked text a yellow background. That default is useful, but you can change it with ordinary CSS:
mark {
background: navy;
color: white;
}
Use <mark> for contextual relevance, not just because you want yellow text. If the text is important regardless of context, <strong> may be the better element. The visual result can look similar; the meaning is not the same.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- The HTML Details That Make Forms More Accessible
Build clearer forms with visible labels, autocomplete, connected help and errors, fieldsets, and visible focus.
- When a Control Needs aria-label
Use aria-label for genuinely unlabelled controls while keeping visible text and native elements as the first choice.
- When CSS Layout Order Stops Matching the HTML
Keep Grid and Flexbox layouts aligned with the HTML order so keyboard focus and screen reader reading do not jump around the page.