✨ The <mark>
Tag in HTML: Highlighting with Meaning
In modern HTML, semantics matter. The <mark>
tag is a semantic inline element that is used to highlight or mark textas relevant or noteworthy. Unlike styling with CSS alone, <mark>
also gives the content meaning, which can be useful for search, accessibility, and user context.
📌 What Is the <mark>
Tag?
The <mark>
tag is used to highlight portions of text that are relevant in the context of the page — for example, highlighting search terms or important information in an article.
By default, browsers render <mark>
text with a yellow background, but this can be styled using CSS.
🧪 Basic Example
<p>Search result: The <mark>climate change</mark> report was updated.</p>
🔍 Output:
Search result: The <mark>climate change</mark> report was updated.
🧩 Structure Diagram
<p>
└── Text
└── <mark>Highlighted phrase</mark>
✅ The <mark>
tag is an inline element, meaning it flows with the surrounding text.
🎯 When to Use <mark>
Use Case | Example |
---|---|
🔍 Highlighting search keywords | <mark>keyword</mark> in search results |
📝 Marking key phrases in articles | Important notes, dates, or warnings |
📚 Study tools or reading aids | Highlighted quotes or vocabulary |
⚙️ Styling the <mark>
Tag
While the default style is yellow with black text, you can customize it:
<style>
mark {
background-color: #ffeb3b;
color: black;
padding: 0 4px;
border-radius: 3px;
}
</style>
✅ This makes the highlight more visually appealing and consistent with your site design.
📷 Example with Custom Style
htmlCopyEdit<p>Don't forget to <mark>submit your assignment</mark> before Friday.</p>
Styled with CSS:
mark {
background-color: #00e676;
color: white;
}
💡 Result: the phrase is now highlighted in bright green instead of yellow.
🛑 Don’t Confuse With <strong>
or <em>
Tag | Purpose | Visual |
---|---|---|
<mark> | Highlights relevant text | Yellow background (default) |
<strong> | Emphasizes importance | Bold |
<em> | Emphasizes stress/voice | Italic |
Each tag has a semantic purpose, not just visual styling.
✅ Accessibility Tip
The <mark>
tag is natively recognized by screen readers as “marked” text, helping visually impaired users understand emphasis or relevance.
✅ Conclusion
The <mark>
tag is a powerful way to highlight important text while maintaining semantic structure. It improves both readability and accessibility, and it’s easy to style for a custom look. While often overlooked, it’s a great tool for content-driven websites, blogs, documentation, or search features.