Course contentsShow
← Web Development
Lesson 58 of 2,9822. HTML FundamentalsFree lesson

The <mark> Element

Highlighting relevant text in a specific context with <mark>, like search results.

The <mark> Element

You'll learn how to highlight text that's relevant in a specific context, like a search term someone just looked for.

What Is <mark>?

The <mark> element highlights text that has current relevance to the user. Think of it like using a yellow highlighter on a printout — you're drawing attention to specific words because they matter right now, in this particular situation.

The key word here is "context." You don't mark text that's permanently important (that's what <strong> or <em> are for, though we haven't covered those yet). You mark text that's relevant because of something the user just did.

The Classic Use Case: Search Results

Imagine you search for "banana bread recipe" on a cooking website. When the results appear, seeing "banana" and "bread" highlighted in yellow on each result helps you quickly scan and find what you're looking for.

Here's how you'd mark those search terms:

<article>
  <h2>Easy <mark>Banana</mark> <mark>Bread</mark> Recipe</h2>
  <p>This <mark>banana</mark> <mark>bread</mark> is moist and delicious...</p>
</article>

By default, browsers render <mark> with a yellow background, just like a real highlighter.

Why Not Just Style Text Yellow?

Because <mark> is semantic — it tells browsers, screen readers, and search engines why the text is highlighted. It's not just decoration; it's meaningful highlighting based on context.

Key Takeaway: Use <mark> to highlight text that's relevant in the current context, especially for showing search matches or referenced content on a page.