strikethrough

An animated strikethrough icon for React that draws a horizontal line through the letter-like glyph on hover or on demand. It is built with motion/react and exposes an imperative ref with startAnimation and stopAnimation methods.

strikethrough
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @heroicons-animated/strikethrough

Requires @heroicons-animated in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { StrikethroughIcon } from "@/components/ui/strikethrough"export function Example() {  return <StrikethroughIcon size={28} className="text-foreground" />}
  • Text formatting toolbars where a strikethrough action needs a clear, animated icon button
  • Task lists or to-do UIs that visually cross out completed or deprecated items
  • Marketing or feature sections that want a subtle hover micro-interaction on a text-related icon
  • Controlled animations where a parent triggers the strike-through draw via a ref, such as after a form submission

Examples

Hover to animate (uncontrolled)

The default behavior: the line draws on mouse enter and resets on mouse leave, with no ref needed.

hover-to-animate-(uncontrolled).tsx
import { StrikethroughIcon } from "@/components/ui/strikethrough"export function HoverExample() {  return (    <div className="inline-flex cursor-pointer items-center justify-center p-2">      <StrikethroughIcon size={24} className="text-zinc-900 dark:text-zinc-100" />    </div>  )}

Imperative control via ref

Use the ref handle to start or stop the animation programmatically, for example when a task is marked as done.

imperative-control-via-ref.tsx
"use client"import { useRef } from "react"import { Button } from "@/components/ui/button"import { StrikethroughIcon, type StrikethroughIconHandle } from "@/components/ui/strikethrough"export function MarkDoneButton() {  const iconRef = useRef<StrikethroughIconHandle>(null)  return (    <Button      variant="outline"      onMouseEnter={() => iconRef.current?.startAnimation()}      onMouseLeave={() => iconRef.current?.stopAnimation()}    >      <StrikethroughIcon ref={iconRef} size={18} />      Strike through    </Button>  )}

Toolbar button with accessible label

Wrap the icon in a labelled button in a formatting toolbar so the action is announced to screen readers.

toolbar-button-with-accessible-label.tsx
import { StrikethroughIcon } from "@/components/ui/strikethrough"export function FormatToolbar() {  return (    <div role="toolbar" aria-label="Text formatting" className="flex gap-1">      <button type="button" aria-label="Strikethrough" className="rounded-md p-2 hover:bg-zinc-100 dark:hover:bg-zinc-800">        <StrikethroughIcon size={20} />      </button>    </div>  )}

Completed list item

A list row whose strikethrough animates when the item is completed, controlled by a parent state change.

completed-list-item.tsx
"use client"import { useEffect, useRef } from "react"import { StrikethroughIcon, type StrikethroughIconHandle } from "@/components/ui/strikethrough"export function TodoRow({ done, label }: { done: boolean; label: string }) {  const iconRef = useRef<StrikethroughIconHandle>(null)  useEffect(() => {    if (done) iconRef.current?.startAnimation()    else iconRef.current?.stopAnimation()  }, [done])  return (    <li className="flex items-center gap-2">      <StrikethroughIcon ref={iconRef} size={16} className="text-muted-foreground" />      <span className={done ? "line-through text-muted-foreground" : ""}>{label}</span>    </li>  )}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes.
classNamestring—Class name applied to the outer div wrapper, passed through cn(). Use it for color (text-*), sizing wrappers, or spacing.
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse enter only when the ref handle is attached (controlled mode). In uncontrolled mode the internal hover animation runs instead and this handler is not called.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse leave only when the ref handle is attached (controlled mode). In uncontrolled mode the internal reset animation runs instead and this handler is not called.
refReact.Ref<StrikethroughIconHandle>—Forwarded ref exposing startAnimation() to play the draw-in animation and stopAnimation() to reset the line to its hidden state.
...propsHTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, data-*, etc.) are spread onto the outer wrapper div.

Accessibility

  • The SVG has no role, title, or aria-label, so it is treated as decorative. Provide an accessible name on the nearest interactive parent (for example aria-label on a button) when the icon is the only content.
  • Add aria-hidden="true" to the icon when a visible text label already describes the action, to avoid redundant announcements.
  • The animation only changes opacity and stroke draw progress of the line; no content is hidden or moved, so meaning is preserved without motion.
  • The component does not check prefers-reduced-motion. If motion sensitivity matters in your product, pass a condition from your app to skip calling startAnimation.
  • Hover-only triggering is not keyboard accessible. When the icon is part of a button, use the parent's focus or press state and call startAnimation from onFocus or onClick as well.
  • Ensure sufficient color contrast by setting className to a text color that meets WCAG contrast against the background, since the icon uses currentColor.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "strikethrough" component (heroicons-animated/strikethrough) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/strikethrough2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: size, className, onMouseEnter, onMouseLeave, ref, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { StrikethroughIcon } from "@/components/ui/strikethrough"export function Example() {  return <StrikethroughIcon size={28} className="text-foreground" />}```

Files & dependencies

  • strikethrough.tsx
dependenciesmotion

Looks similar, elsewhere