Skip to main content
react-md

Mark

The Mark component can is a styled version of the mark HTMLElement.

Typical use cases for <mark> include:

  • When used in a quotation (<q>) or block quote (<blockquote>), it generally indicates text which is of special interest but is not marked in the original source material, or material which needs special scrutiny even though the original author didn't think it was of particular importance. Think of this like using a highlighter pen in a book to mark passages that you find of interest.

  • Otherwise, <mark> indicates a portion of the document's content which is likely to be relevant to the user's current activity. This might be used, for example, to indicate the words that matched a search operation.

  • Don't use <mark> for syntax highlighting purposes; instead, use the <span> element with appropriate CSS applied to it.

Note: Don't confuse <mark> with the <strong> element; <mark> is used to denote content which has a degree of relevance, while <strong> indicates spans of text of importance.

Simple Example

Wrap any children with the Mark component to apply the styles.

Search results for "salamander":

Several species of salamander inhabit the temperate rainforest of the Pacific Northwest.

Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures.

import { Divider } from "@react-md/core/divider/Divider";
import { Mark } from "@react-md/core/typography/Mark";
import { Typography } from "@react-md/core/typography/Typography";
import { type ReactElement } from "react";

export default function SimpleExample(): ReactElement {
  return (
    <div>
      <Typography>{'Search results for "salamander":'}</Typography>
      <Divider />
      <Typography>
        Several species of <Mark>salamander</Mark> inhabit the temperate
        rainforest of the Pacific Northwest.
      </Typography>
      <Typography>
        Most <Mark>salamander</Mark>s are nocturnal, and hunt for insects,
        worms, and other small creatures.
      </Typography>
    </div>
  );
}

Press Enter to start editing.

Customizing Styles Example

The mark styles can be updated just like the Typography component:

Search results for "salamander":

Several species of salamander inhabit the temperate rainforest of the Pacific Northwest.

Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures.

import { Divider } from "@react-md/core/divider/Divider";
import { Mark } from "@react-md/core/typography/Mark";
import { Typography } from "@react-md/core/typography/Typography";
import { type ReactElement } from "react";

import styles from "./CustomizingStylesExample.module.scss";

export default function CustomizingStylesExample(): ReactElement {
  return (
    <div className={styles.container}>
      <Typography>{'Search results for "salamander":'}</Typography>
      <Divider />
      <Typography>
        Several species of <Mark>salamander</Mark> inhabit the temperate
        rainforest of the Pacific Northwest.
      </Typography>
      <Typography>
        Most <Mark>salamander</Mark>s are nocturnal, and hunt for insects,
        worms, and other small creatures.
      </Typography>
    </div>
  );
}

Press Enter to start editing.

@use "@react-md/core/a11y";
@use "@react-md/core/colors";
@use "@react-md/core" with (
  // like the typography styles, this would be merged with the
  // `$mark-recommended-styles` if you want to just add some changes
  $mark-custom-styles: (
      background: colors.$blue-700,
      color: a11y.contrast-color(colors.$blue-700)
    ),
  // or manually set all mark styles using this variable. this would reset
  // it back to the browser default
   // $mark-styles: (background: Mark, color: MarkText, font-weight: 700)
);

// this is only required for this demo. In your application, this should just be the normal:
// @include core.styles;
.container {
  :global {
    @include core.typography-mark-styles($disable-layer: true);
  }
}

Press Enter to start editing.