Gravity Letters
A playful gravity field where letters, numbers, emoji, or any components you pass fall and pile up like real objects.
Interaction Type
Click or tap anywhere to drop a glyph, or press and hold to pour a steady stream. Glyphs tumble as they fall, bounce softly when they land, and pile up into rounded hills. On phones, tilt the device to spill the pile toward the low side. Honors prefers-reduced-motion.
Props
Options you can pass to customize this component.
typelettersnumbersbothWhich pool to draw from: letters, digits, or both. Ignored when items is set.
itemsReact.ReactNode[]Your own drop pool: emoji, icons, or any components. Each drop picks a random entry. Overrides type.
gravitynumberDownward acceleration in px/s². Lower is floatier, higher is heavier.
sizenumberBase glyph size in pixels. Each drop varies slightly around it.
color#1A73F2#5856D6#AF52DE#FF2D92#FF3B30#F75001#FFB800#34C759Glyph color. Defaults to currentColor so it follows your theme.
maxGlyphsnumberMax glyphs kept in the field; past the cap the oldest fade out. Unlimited by default.
deviceTiltbooleanTilting a phone spills the pile toward the low side. iOS asks for motion permission on the first tap.
classNamestringExtra classes for the root element. Use it to size the field.
Installation
npx shadcn add swamimalode07/rare-ui/gravity-lettersHow to use
import GravityLetters from "@/components/ui/gravity-letters"export function Demo() {return (<GravityLetters type="letters" className="h-96 w-full rounded-3xl border">{/* anything you render inside stays clickable-through */}<p className="absolute inset-0 grid place-items-center text-sm text-muted-foreground">Click anywhere</p></GravityLetters>)}// Digits instead:// <GravityLetters type="numbers" />// Or drop your own content: emoji, icons, any component:// <GravityLetters items={["š", "š", "š", <Sparkles key="s" className="size-7" />]} />
Source Code
Click the code icon in the top-right corner to view the source code.
Keep in mind
Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.
License & Usage
1