Table of Content
The mark tag highlights text in HTML and shows that the text has relevance in the content. It adds a yellow background to words.
How to Use the <mark> Tag in HTML
You can use it to show search terms inside a paragraph. It draws attention when they scan. So, it helps users find key words fast. This tag belongs to the HTML5 group of semantic tags.
Here is the syntax:
<mark>Your text here</mark>You can place it inside inline elements.
Here is a quick example:
<p>This is <mark>highlighted</mark> text.</p>You can also nest it in tags like <span> or <a>. Avoid placing it in block-level elements in the wrong way. That breaks the page structure.
So, What are the reasons of using this tag?
- It shows readers which parts most important.
- It makes key terms easy to see. So, it helps readers scan and understand fast.
- It also works well in search result pages.
- Tutorials and technical guides use it to show focused terms.
The mark tag adds meaning for screen readers and other tools. You can also style it to match the site design.
But you have to avoid it in the following cases:
- Do not use it to stress words in a general way. Use
<strong>for importance and<em>for voice or tone. - Avoid tagging every keyword. That clutters the layout.
- Also, do not use it to boost SEO keywords.
How to Style the <mark> Element with CSS
You can change the default yellow with CSS. The syntax looks like this:
mark {
background-color: lightblue;
color: black;
}You can also adjust font or spaces. Or even borders. This keeps the design consistent. So, the highlight fits your brand.
Nest and Combine the <mark> Element with Other Tags
You can put the <mark> tag inside other HTML tags or put other tags inside the <mark> tag to mix styles or meanings.
You can put <mark> inside other tags like this:
<p>This is a <mark>very important</mark> message.</p>The <mark> is inside the paragraph tag <p>. It just highlights some of the text.
You can also put other tags inside the <mark> tag:
<mark><strong>Warning:</strong> This is serious!</mark>Here, we are highlighting the text, and also making the word “Warning:” bold using <strong>.
The Difference Between and Other Tags in HTML
Here is a table that shows you the key differences:
| Tag | What it does | Purpose (in easy words) | Looks like |
|---|---|---|---|
<mark> | Highlights text with a yellow background | To show important info for this page/view | Yellow highlight |
<strong> | Makes text bold | Means this is very important | Bold |
<em> | Makes text italic | To show emphasis (stress or emotion) | Italic |
<span> | Does nothing by itself (needs CSS) | A blank wrapper — you style it yourself | Can look like anything |
Here is a list shows you when to use each one:
- The
<mark>to highlight based on context (like search terms). - Use
<strong>for important content (meaning). - The
<em>to show emotion or stress. - Use
<span>when you want to custom-style something with CSS.
Examples of <mark> Tag in HTML
Search Term Highlight in User Input:
<p>Search results for "<mark>HTML</mark>":</p>
<ul>
<li><mark>HTML</mark> stands for HyperText Markup Language.</li>
<li>Learn how to use <mark>HTML</mark> tags properly.</li>
</ul>This example shows how to highlight a search keyword (“HTML”) within the results. It improves user experience if it shows exactly where the match appears, like in search engines or other features.
Highlighting Part of a Link or Button Label:
<a href="https://flatcoding.com"><mark>HTML</mark> Web Docs</a>
<button>View <mark>Updates</mark></button>This example shows that <mark> can be used inside links and buttons to highlight key parts of labels. This is useful in UI/UX to draw attention to important actions like “Updates” or keywords.
Styling <mark> with CSS for Custom Theme:
<style>
mark.custom-highlight {
background-color: #ffcc00;
color: black;
font-weight: bold;
padding: 2px 4px;
border-radius: 4px;
}
</style>
<p>Remember to use <mark class="custom-highlight">semantic</mark> HTML in your project.</p>Here, <mark> is given a custom style with a class. It’s useful for branding or accessibility when the default yellow isn’t suitable. You can fully control the look using CSS.
Wrapping Up
In this article, you learned what the <mark> tag does and how to use it in your HTML pages.
Here is a quick recap:
<mark>highlights text with a default yellow background.- You can use it to show search terms or key references.
- It supports screen readers and improves content clarity.
- CSS styles can adjust its look to match your site.
What is the HTML mark tag used for?
How do you add the mark tag in HTML?
<p>This is <mark>important</mark> text.</p>
What does the mark tag look like on a web page?
Is the mark tag supported in all browsers?
Can you style the mark tag with CSS?
mark {
background-color: lightgreen;
color: black;
padding: 2px;
}
Similar Reads
The HTML textarea tag gives users space to enter longer messages. This element helps build forms that accept feedback, comments,…
The <footer> tag defines a footer section in HTML. It creates a clear endpoint for a page or section. Browsers…
You use the HTML <table> tag to display structured data in rows and columns, using table elements such as <tr>…
The HTML del tag shows text that a user or author removed from a page. A browser shows this text…
The HTML blockquote tag defines a long quote from another source. It sets the quoted text apart from other content.…
HTML builds web pages. It does this with elements and tags. Many new learners confuse them, so you need to…
data-* attributes store extra values on elements without an extra DOM nodes or backend requests. What are data-* attributes in…
HTML attributes add extra detail to elements so the browser knows how to handle them. Here you will see examples…
HTML is the main content for every web page. It helps you structure text, links, and media. You can build…
A web page must follow a clear structure so browsers can read and show it correctly. This guide helps you…