DEV Community

Discussion on: Highlight text with HTML

Collapse
 
gorango profile image
Goran Spasojevic

The <mark> tags can be useful but only for content that you control. If you want to let users make their own highlights, using <mark> can potentially break the markup.

Consider the following markup:

<p>
  The <em>lazy dog</em> jumped <b>over the sleeping fox</b>.
</p>
Enter fullscreen mode Exit fullscreen mode

How would you highlight:

"dog jumped over"

You would need three separate <mark> elements to wrap the content. And to change or remove that highlight would require some heavy lifting to preserve the structure of the markup.

While the <mark> tag can be useful - it is very limited for any interactive UIs.