HTML Mark Tag: How to Highlight Text

html mark tag

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:

TagWhat it doesPurpose (in easy words)Looks like
<mark>Highlights text with a yellow backgroundTo show important info for this page/viewYellow highlight
<strong>Makes text boldMeans this is very importantBold
<em>Makes text italicTo show emphasis (stress or emotion)Italic
<span>Does nothing by itself (needs CSS)A blank wrapper — you style it yourselfCan 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?

The HTML mark tag highlights text to show relevance or importance. It makes words stand out, often used for search matches or notes.

How do you add the mark tag in HTML?

You place the text you want to highlight inside the mark tag.
<p>This is <mark>important</mark> text.</p>

What does the mark tag look like on a web page?

The marked text shows up with a yellow background by default. It looks like a highlighter over the words.

Is the mark tag supported in all browsers?

Yes, most modern browsers support the mark tag. Older browsers may not show the highlight, but they still display the text.

Can you style the mark tag with CSS?

Yes, you can change how it looks with CSS.
mark {
  background-color: lightgreen;
  color: black;
  padding: 2px;
}

Similar Reads

HTML Footer Tag for Document Footers

The <footer> tag defines a footer section in HTML. It creates a clear endpoint for a page or section. Browsers…

HTML output Tag: How to Display Calculation Results

The <output> tag in HTML shows results inside a form. It helps display values from user actions or scripts. You…

HTML object Tag: How to Embed External Objects with Examples

Use the HTML object tag to embed different types of external files into your webpage. It works for videos and…

HTML main Tag: How to Create a Primary Content Area

The <main> tag in HTML marks the central content of a webpage. It tells browsers and assistive technologies where the…

HTML title Tag: How to Set Web Page Titles

The title tag in HTML shows the page name in the browser tab and helps search engines know the topic.…

HTML link Tag: Linking Stylesheets

The link tag in HTML connects a web page to external resources like stylesheets or icons. It's placed in the…

HTML Legend Tag: How it Works in Fieldset Tag with Examples

In this article, you will learn how HTML legend works in the fieldset tag with examples. HTML fieldset and legend…

HTML br Tag: Line Breaks

The br tag adds a single line break in HTML. It is an empty tag that does not need a…

HTML embed Tag: How to Embed External Media in Web Pages

The HTML embed tag is used to display media content, such as videos or audio. It can also display PDFs…

HTML del Tag: How to Mark Deleted Text in Pages

The HTML del tag shows text that a user or author removed from a page. A browser shows this text…

Previous Article

HTML <cite> Tag: How to Reference Sources

Next Article

HTML Small Tag: How to Make Text Small

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.