HTML <mark> Element

Publish in HTML Tutorial el 24/05/2025 17:19

The <mark> element represents text that should be marked or highlighted for reference purposes, typically due to its relevance in another context. It's particularly useful when you want to draw attention to specific portions of text without changing the semantic meaning.


By default, most browsers render <mark> content with a yellow background, but you can customize this with CSS. The <mark> element is an inline element and can be used within paragraphs, lists, or other text containers.


Basic Syntax

Rendered Example

This text will be highlighted


Common Use Cases

The <mark> element is perfect for:

  • Highlighting search results in a page
  • Marking important passages in quoted text
  • Drawing attention to relevant content
  • Creating visual cues in documentation


Examples

1. Basic Highlighting

Simple example of marking important text in a paragraph.

Play Code


2. Search Results Highlighting

Simulating how search terms might be highlighted in results.

Play Code


3. Custom Styled Mark

Showing how to customize the appearance of the mark element.

Play Code


4. JavaScript Dynamic Highlighting

Using JavaScript to dynamically mark text based on user input.

Play Code


5. Mark with JavaScript Event

Using JavaScript to toggle highlighting on click.

Play Code


Tips and Tricks

  • Accessibility: The <mark> element is recognized by screen readers, which will typically announce the highlighted content appropriately.
  • Styling: Always customize the highlight color to match your site's design using CSS.
  • Semantics: Use <mark> only for highlighting, not for general styling. For purely visual effects, use CSS instead.
  • Performance: When using JavaScript to dynamically mark large amounts of text, consider performance implications.
  • Printing: The highlight will typically print as-is, but you can customize print styles with @media print in your CSS.


Browser Support

The <mark> element is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It's also supported in Internet Explorer 9 and later.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...