Kinetic Text
magicui/kinetic-textFreeComponent
A text component that animates font weight of characters on hover.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/kinetic-text.jsonSource
1import React from "react"23import { cn } from "@/lib/utils"45type As = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span"67type KineticTextProps = React.HTMLAttributes<HTMLElement> & {8 text: string9 as?: As10}1112export function KineticText({13 text,14 as: Tag = "h1",15 className = "",16 style,17 ...rest18}: KineticTextProps) {19 const mergedStyle = {20 "--hover-padding": "calc(1em / 12)",21 "--text-stroke-width": "calc(1em * 125 / 6000)",22 ...(style as React.CSSProperties | undefined),23 } as React.CSSProperties2425 return (26 <Tag27 {...rest}28 className={cn("flex flex-wrap font-[300]", className)}29 style={mergedStyle}30 >31 {text.split("").map((letter, i) => (32 <span33 key={i}34 aria-hidden="true"35 className="[will-change:font-weight,-webkit-text-stroke-width,padding] [-webkit-text-stroke-color:transparent] [-webkit-text-stroke-width:var(--text-stroke-width)] [transition:font-weight_0.4s,_-webkit-text-stroke-color_0.4s,_padding_0.4s] hover:[padding-inline:var(--hover-padding)] hover:font-[900] hover:[-webkit-text-stroke-color:currentcolor] hover:[-webkit-text-stroke-width:calc(var(--text-stroke-width)*2)] has-[+span+span:hover]:font-[400] has-[+span:hover]:[padding-inline:var(--hover-padding)] has-[+span:hover]:font-[600] [:hover+&]:[padding-inline:var(--hover-padding)] [:hover+&]:font-[600] [:hover+span+&]:font-[400]"36 >37 {letter === " " ? "\u00A0" : letter}38 </span>39 ))}40 <span className="sr-only">{text}</span>41 </Tag>42 )43}
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
