Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Text Highlighter

    A highlight that draws behind inline text from four directions: in view, on hover or focus, on mount, or on command. Solid, marker, underline, or gradient.

    Set the measure first

    Long lines tire the eye, so readers lose their place on the way back. Keep body text at 45 to 75 characters per line, give it a line height near 1.5, and let headings sit closer to the text they introduce than to the one above.

    Set the measure first

    Long lines tire the eye, so readers lose their place on the way back. Keep body text at 45 to 75 characters per line, give it a line height near 1.5, and let headings sit closer to the text they introduce than to the one above.

    Set the measure first

    Long lines tire the eye, so readers lose their place on the way back. Keep body text at 45 to 75 characters per line, give it a line height near 1.5, and let headings sit closer to the text they introduce than to the one above.

    Set the measure first

    Long lines tire the eye, so readers lose their place on the way back. Keep body text at 45 to 75 characters per line, give it a line height near 1.5, and let headings sit closer to the text they introduce than to the one above.

    Set the measure first

    Long lines tire the eye, so readers lose their place on the way back. Keep body text at 45 to 75 characters per line, give it a line height near 1.5, and let headings sit closer to the text they introduce than to the one above.

    <article class="text-base leading-7 text-muted">
        <h3 class="text-lg font-semibold text-ink">Set the measure first</h3>
        <p class="mt-2">Long lines tire the eye, so readers lose their place on the way back. Keep body text at <x-markas.text-highlighter>45 to 75 characters</x-markas.text-highlighter> per line, give it a <x-markas.text-highlighter :delay="400">line height near 1.5</x-markas.text-highlighter>, and let headings sit <x-markas.text-highlighter :delay="800">closer to the text they introduce</x-markas.text-highlighter> than to the one above.</p>
    </article>
    import { TextHighlighter } from "@/components/markas/TextHighlighter";
    
    export default function TextHighlighterExample() {
      return (
        <article className="text-base leading-7 text-muted">
          <h3 className="text-lg font-semibold text-ink">Set the measure first</h3>
          <p className="mt-2">
            Long lines tire the eye, so readers lose their place on the way back.
            Keep body text at <TextHighlighter>45 to 75 characters</TextHighlighter>{" "}
            per line, give it a{" "}
            <TextHighlighter delay={400}>line height near 1.5</TextHighlighter>, and
            let headings sit{" "}
            <TextHighlighter delay={800}>
              closer to the text they introduce
            </TextHighlighter>{" "}
            than to the one above.
          </p>
        </article>
      );
    }
    <script setup lang="ts">
    import TextHighlighter from "@/components/markas/TextHighlighter.vue";
    </script>
    
    <template>
      <article class="text-base leading-7 text-muted">
        <h3 class="text-lg font-semibold text-ink">Set the measure first</h3>
        <p class="mt-2">
          Long lines tire the eye, so readers lose their place on the way back. Keep
          body text at
          <TextHighlighter>45 to 75 characters</TextHighlighter> per line, give it a
          <TextHighlighter :delay="400">line height near 1.5</TextHighlighter>, and
          let headings sit
          <TextHighlighter :delay="800"
            >closer to the text they introduce</TextHighlighter
          >
          than to the one above.
        </p>
      </article>
    </template>
    <script lang="ts">
      import TextHighlighter from "$lib/components/markas/TextHighlighter.svelte";
    </script>
    
    <article class="text-base leading-7 text-muted">
      <h3 class="text-lg font-semibold text-ink">Set the measure first</h3>
      <p class="mt-2">
        Long lines tire the eye, so readers lose their place on the way back. Keep
        body text at
        <TextHighlighter>45 to 75 characters</TextHighlighter> per line, give it a
        <TextHighlighter delay={400}>line height near 1.5</TextHighlighter>, and let
        headings sit
        <TextHighlighter delay={800}
          >closer to the text they introduce</TextHighlighter
        >
        than to the one above.
      </p>
    </article>
    ---
    import TextHighlighter from "@/components/markas/TextHighlighter.astro";
    ---
    
    <article class="text-base leading-7 text-muted">
      <h3 class="text-lg font-semibold text-ink">Set the measure first</h3>
      <p class="mt-2">
        Long lines tire the eye, so readers lose their place on the way back. Keep
        body text at{" "}
        <TextHighlighter>45 to 75 characters</TextHighlighter>{" "}
        per line, give it a{" "}
        <TextHighlighter delay={400}>line height near 1.5</TextHighlighter>, and
        let headings sit{" "}
        <TextHighlighter delay={800}>closer to the text they introduce</TextHighlighter>{" "}
        than to the one above.
      </p>
    </article>
    import { Component } from "@angular/core";
    import { TextHighlighter } from "./markas/text-highlighter.component";
    
    @Component({
      selector: "markas-example",
      imports: [TextHighlighter],
      template: `
        <article class="text-base leading-7 text-muted">
          <h3 class="text-lg font-semibold text-ink">Set the measure first</h3>
          <p class="mt-2">
            Long lines tire the eye, so readers lose their place on the way back.
            Keep body text at
            <span markas-text-highlighter>45 to 75 characters</span> per line, give
            it a
            <span markas-text-highlighter delay="400">line height near 1.5</span>,
            and let headings sit
            <span markas-text-highlighter delay="800"
              >closer to the text they introduce</span
            >
            than to the one above.
          </p>
        </article>
      `,
    })
    export default class TextHighlighterExample {}

    Examples

    Four directions on hover

    Controlled by buttons

    Before you publish, check that the title fits in 60 characters, every image has alt text, and the summary answers one clear question.

    Before you publish, check that the title fits in 60 characters, every image has alt text, and the summary answers one clear question.

    Before you publish, check that the title fits in 60 characters, every image has alt text, and the summary answers one clear question.

    Before you publish, check that the title fits in 60 characters, every image has alt text, and the summary answers one clear question.

    Before you publish, check that the title fits in 60 characters, every image has alt text, and the summary answers one clear question.

    Marker in a hero heading

    Ship your design system before the next sprint

    One set of components for Blade, React, and Vue, with tokens your team already knows.

    Ship your design system before the next sprint

    One set of components for Blade, React, and Vue, with tokens your team already knows.

    Ship your design system before the next sprint

    One set of components for Blade, React, and Vue, with tokens your team already knows.

    Ship your design system before the next sprint

    One set of components for Blade, React, and Vue, with tokens your team already knows.

    Ship your design system before the next sprint

    One set of components for Blade, React, and Vue, with tokens your team already knows.

    Solid, marker, underline, gradient

    • A solid block for quotes worth saving.
    • A marker stroke for notes in the margin.
    • A thick underline for terms to remember.
    • A two tone gradient for the headline idea.
    • A solid block for quotes worth saving.
    • A marker stroke for notes in the margin.
    • A thick underline for terms to remember.
    • A two tone gradient for the headline idea.
    • A solid block for quotes worth saving.
    • A marker stroke for notes in the margin.
    • A thick underline for terms to remember.
    • A two tone gradient for the headline idea.
    • A solid block for quotes worth saving.
    • A marker stroke for notes in the margin.
    • A thick underline for terms to remember.
    • A two tone gradient for the headline idea.
    • A solid block for quotes worth saving.
    • A marker stroke for notes in the margin.
    • A thick underline for terms to remember.
    • A two tone gradient for the headline idea.

    Installation

    npx markasui@latest add text-highlighter

    Usage

    <p>Keep body text at <x-markas.text-highlighter>45 to 75 characters</x-markas.text-highlighter> per line, with a <x-markas.text-highlighter variant="marker" :delay="400">line height near 1.5</x-markas.text-highlighter>.</p>
    
    <a href="/docs"><x-markas.text-highlighter trigger="hover" direction="rtl" color="success">Read the docs</x-markas.text-highlighter></a>
    
    <div x-data>
        <x-markas.text-highlighter trigger="manual">Ready to publish</x-markas.text-highlighter>
        <button type="button" x-on:click="$dispatch('markas-highlight', { direction: 'ltr' })">Highlight</button>
        <button type="button" x-on:click="$dispatch('markas-highlight-reset')">Reset</button>
    </div>
    import { useRef } from "react";
    import {
      TextHighlighter,
      type TextHighlighterHandle,
    } from "@/components/markas/TextHighlighter";
    
    const highlight = useRef<TextHighlighterHandle>(null);
    
    <p>
      Keep body text at <TextHighlighter>45 to 75 characters</TextHighlighter> per
      line, with a{" "}
      <TextHighlighter variant="marker" delay={400}>
        line height near 1.5
      </TextHighlighter>
      .
    </p>
    
    <TextHighlighter ref={highlight} trigger="manual">Ready to publish</TextHighlighter>
    <button type="button" onClick={() => highlight.current?.animate("rtl")}>Highlight</button>
    <button type="button" onClick={() => highlight.current?.reset()}>Reset</button>
    <script setup lang="ts">
    import { ref } from "vue";
    import TextHighlighter from "@/components/markas/TextHighlighter.vue";
    
    const active = ref(false);
    </script>
    
    <template>
      <p>
        Keep body text at <TextHighlighter>45 to 75 characters</TextHighlighter> per
        line, with a
        <TextHighlighter variant="marker" :delay="400"
          >line height near 1.5</TextHighlighter
        >.
      </p>
      <TextHighlighter trigger="manual" :active="active"
        >Ready to publish</TextHighlighter
      >
      <button type="button" @click="active = !active">Toggle</button>
    </template>
    <script lang="ts">
      import TextHighlighter from "$lib/components/markas/TextHighlighter.svelte";
    
      let active = $state(false);
    </script>
    
    <p>
      Keep body text at <TextHighlighter>45 to 75 characters</TextHighlighter> per line,
      with a
      <TextHighlighter variant="marker" delay={400}
        >line height near 1.5</TextHighlighter
      >.
    </p>
    <TextHighlighter trigger="manual" {active}>Ready to publish</TextHighlighter>
    <button type="button" onclick={() => (active = !active)}>Toggle</button>
    ---
    import TextHighlighter from "@/components/markas/TextHighlighter.astro";
    ---
    
    <p>
      Keep body text at <TextHighlighter>45 to 75 characters</TextHighlighter> per
      line, with a{" "}
      <TextHighlighter variant="marker" delay={400}>line height near 1.5</TextHighlighter>.
    </p>
    <TextHighlighter trigger="manual">Ready to publish</TextHighlighter>
    <button
      type="button"
      onclick="window.dispatchEvent(new CustomEvent('markas-highlight'))"
    >
      Highlight
    </button>
    import { Component, signal } from "@angular/core";
    import { TextHighlighter } from "./markas/text-highlighter.component";
    
    @Component({
      selector: "app-checklist",
      imports: [TextHighlighter],
      template: `
        <p>
          Keep body text at
          <span markas-text-highlighter>45 to 75 characters</span> per line, with a
          <mark markas-text-highlighter variant="marker" delay="400"
            >line height near 1.5</mark
          >.
        </p>
        <span markas-text-highlighter trigger="manual" [active]="active()"
          >Ready to publish</span
        >
        <button type="button" (click)="active.set(!active())">Toggle</button>
      `,
    })
    export class Checklist {
      active = signal(false);
    }
    • The highlight is a background gradient that grows with a CSS transition of background-size, so it follows the text across line breaks (box-decoration-break: clone).
    • trigger="view" uses IntersectionObserver with once and threshold; hover listens on the closest link, button, label, or element with tabindex, so keyboard focus draws it too.
    • For trigger="manual", React and Vue expose animate(direction?) and reset() through a ref. Blade listens for the markas-highlight (with an optional direction in the detail) and markas-highlight-reset window events, and Alpine.$data(el) exposes the same two methods. Svelte exposes them through bind:this, Astro listens for the same window events as Blade and exposes highlight(direction?) and reset() on the markas-text-highlighter element, and Angular exposes them through #mark="markasTextHighlighter".
    • Angular has no as input: put the markas-text-highlighter attribute on the element you want, such as span, strong, or mark.
    • duration and delay set transition-duration and transition-delay on the element. Give each phrase a higher delay to highlight a paragraph in reading order.
    • With reduced motion, view and auto highlights are shown at once, and every change happens without a transition.

    Props

    NameTypeDefaultDescription
    asstring"span"The element to render. Keep it inline, such as span, strong, or mark. Angular: put the markas-text-highlighter attribute on that element.
    trigger"view" | "hover" | "auto" | "manual""view"view draws when the text scrolls into view, hover follows hover and keyboard focus of the closest link or button, auto draws on mount, manual follows active.
    direction"ltr" | "rtl" | "ttb" | "btt""ltr"Where the highlight grows from: left to right, right to left, top to bottom, or bottom to top.
    variant"solid" | "marker" | "underline" | "gradient""solid"solid fills the line, marker covers the lower 60% like a highlighter pen, underline draws a thick bar under the text, gradient blends two tokens.
    color"warning" | "primary" | "primary-soft" | "success" | "danger""warning"Token used for the highlight, mixed with transparency so the text stays readable.
    activebooleanfalseHighlight state for trigger manual.
    oncebooleantruetrigger view: draw once, or clear again when the text leaves the viewport.
    thresholdnumber0.5trigger view: how much of the text must be visible, from 0 to 1.
    durationnumber700Milliseconds the highlight takes to draw.
    delaynumber0Milliseconds to wait before drawing. Use rising delays to highlight a paragraph in order.

    Accessibility

    • The text stays plain text; the highlight is a background image and is not announced.
    • Text on the highlight uses the ink token, which keeps AA contrast in light and dark themes.
    • trigger hover also responds to keyboard focus on the closest link, button, or focusable element.
    • With reduced motion, view and auto highlights are shown at once and every change happens without a transition.

    Related components

    More animations components with the same classes in every framework.