# Highlight Link

> A highlighter stroke that sweeps behind the link text, or a solid block that flips the text to white exactly under its edge.

Links · hover, link, highlight, text · HTML and CSS only · no dependencies · updated 2026-10-16
Demo: https://kodza.dev/components/hover-link-text-background-reveal/

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-hover-link-text-background-reveal.css`](https://kodza.dev/registry/hover-link-text-background-reveal/kodza-hover-link-text-background-reveal.css) · 4.5 KB
- [`kodza-hover-link-text-background-reveal.html`](https://kodza.dev/registry/hover-link-text-background-reveal/kodza-hover-link-text-background-reveal.html) · 0.1 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS, don't retype it.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-hover-link-text-background-reveal.css https://kodza.dev/registry/hover-link-text-background-reveal/kodza-hover-link-text-background-reveal.css
```

Then load the file from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS from the Code section only if you can't run commands, exactly as it is. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-highlight`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-highlight-text: currentColor`
  - `--kz-highlight-mark: rgba(10, 10, 10, 0.12)`
  - `--kz-highlight-height: 100%`
  - `--kz-highlight-duration: 0.55s`
  - `--kz-highlight-ease: cubic-bezier(0.76, 0, 0.24, 1)`
- Modifiers: `.kodza-highlight--invert`

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-highlight {
    --kz-highlight-mark: rgba(255, 255, 255, 0.2);
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-highlight { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-hover-link-text-background-reveal.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-hover-link-text-background-reveal.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- No JS.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>`, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-hover-link-text-background-reveal.css' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- This one is inline (it flows like a word): pasted alone, many themes leave it at the edge of the page (block themes, and classic ones like Twenty Twenty-One or Blocksy), so put the Custom HTML block inside a **Group** block to line it up with the text.
- CSS: the downloaded file goes in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-hover-link-text-background-reveal', $uri . 'kodza-hover-link-text-background-reveal.css', [], filemtime($dir . 'kodza-hover-link-text-background-reveal.css'));
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- No JS.
- Colours: it takes the colour of the text around it (or keeps its own monochrome): nothing to point at the theme.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- CSS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- No child theme: the CSS can go in the HTML widget instead, in a `<style>` before the HTML.

### Shopify

- Files: `assets/kodza-hover-link-text-background-reveal.css` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-hover-link-text-background-reveal.css' | asset_url | stylesheet_tag }}`, then the HTML.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `HighlightLink.tsx` (below), the CSS block under Code saved as `hover-link-text-background-reveal.css`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { HighlightLink } from '@/components/kodza/HighlightLink';` then `<HighlightLink>Copy-paste and chill</HighlightLink>`. Props: `variant` ("invert", or several in an array), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-highlight-text': … }}`), `children` (the text, plain), `className`, `style` and the other props of its `<a>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './hover-link-text-background-reveal.css'` line there.

```tsx
'use client';
// Kodza — Highlight Link, for React. From https://kodza.dev/components/hover-link-text-background-reveal/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: hover-link-text-background-reveal.css, the component's CSS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
import { useRef, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './hover-link-text-background-reveal.css';

type Variant = "invert";

export type HighlightLinkProps = Omit<ComponentPropsWithoutRef<'a'>, "children" | "variant" | "vars"> & {
  /** Modifier class(es): .kodza-highlight--invert */
  variant?: Variant | Variant[];
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: currentColor */
    "--kz-highlight-text"?: string | number;
    /** default: rgba(10, 10, 10, 0.12) */
    "--kz-highlight-mark"?: string | number;
    /** default: 100% */
    "--kz-highlight-height"?: string | number;
    /** default: 0.55s */
    "--kz-highlight-duration"?: string | number;
    /** default: cubic-bezier(0.76, 0, 0.24, 1) */
    "--kz-highlight-ease"?: string | number;
  };
  /** The text */
  children?: string;
  className?: string;
};

export function HighlightLink({ variant, vars, children = "Copy-paste and chill", className, style, ...rest }: HighlightLinkProps) {
  const ref = useRef<ComponentRef<'a'>>(null);
  const classes = ["kodza-highlight", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-highlight--${v}`), className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, vars, children, style, rest]);

  return (
    <a href="#" key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>{children}</a>
  );
}
```

## Code

```html
<a class="kodza-highlight" href="#">Copy-paste and chill</a>

<a class="kodza-highlight kodza-highlight--invert" href="#">Skip the setup</a>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Highlight Link
   A highlighter stroke sweeps in behind the text from the left and leaves through the
   right. Drawn as a background, it follows the text across several lines.
   The --invert variant passes a solid block instead: the text turns white exactly under
   its edge (single line, made for light or dark monochrome backgrounds).
   Everything is tuned with the --kz-highlight-* variables. */
.kodza-highlight {
  --kz-highlight-text: currentColor;
  --kz-highlight-mark: rgba(10, 10, 10, 0.12);
  --kz-highlight-height: 100%;
  --kz-highlight-duration: 0.55s;
  --kz-highlight-ease: cubic-bezier(0.76, 0, 0.24, 1);

  color: var(--kz-highlight-text);
  text-decoration: none;
  background-image: linear-gradient(var(--kz-highlight-mark), var(--kz-highlight-mark));
  background-repeat: no-repeat;
  background-position: 100% 100%;
  background-size: 0% var(--kz-highlight-height);
  padding: 0.02em 0.14em;
  margin: 0 -0.14em;
  border-radius: 0.12em;
  /* Only the width moves: the anchor flips instantly, while it changes nothing on screen */
  transition: background-size var(--kz-highlight-duration) var(--kz-highlight-ease);
}

.kodza-highlight:hover,
.kodza-highlight:focus-visible {
  background-position: 0 100%;
  background-size: 100% var(--kz-highlight-height);
}

/* Invert: a white block in "difference" mode shows as ink over a light page,
   and flips the text it covers to white, pixel by pixel */
.kodza-highlight--invert {
  position: relative;
  display: inline-block;
  background-image: none;
  margin: 0;
}

.kodza-highlight--invert::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #ffffff;
  mix-blend-mode: difference;
  transform: scaleX(0);
  transform-origin: 100% 50%;
  transition: transform var(--kz-highlight-duration) var(--kz-highlight-ease);
  pointer-events: none;
}

.kodza-highlight--invert:hover::after,
.kodza-highlight--invert:focus-visible::after {
  transform: scaleX(1);
  transform-origin: 0 50%;
}

.kodza-highlight:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-highlight,
  .kodza-highlight--invert::after {
    transition-duration: 0.01ms;
  }
}

/* Theming example — a warmer marker:
.kodza-highlight {
  --kz-highlight-mark: #f3e3a3;
  --kz-highlight-height: 45%;
}
*/

/* kodza-guard a42e4f4deea1 — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-highlight):not(#_) {
  outline: revert;
  position: revert;
  outline-offset: revert;
}

:where(.kodza-highlight):not(#_):where(:not([hidden])) {
  display: revert;
}

:where(.kodza-highlight):not(#_):where([hidden]) {
  display: none;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-highlight:not(#_) {
  border: revert;
  list-style: revert;
  box-sizing: revert;
  background-color: revert;
  box-shadow: revert;
  appearance: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-highlight:not(#_) {
  color: var(--kz-highlight-text);
  text-decoration: none;
  background-image: linear-gradient(var(--kz-highlight-mark), var(--kz-highlight-mark));
  padding: 0.02em 0.14em;
  border-radius: 0.12em;
  transition: background-size var(--kz-highlight-duration) var(--kz-highlight-ease);
}

.kodza-highlight--invert:not(#_) {
  position: relative;
  display: inline-block;
  background-image: none;
}

.kodza-highlight:focus-visible:not(#_) {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-highlight:not(#_) {
    transition-duration: 0.01ms;
  }
}
```

Free to use, from Kodza (https://kodza.dev).
