Liquid metal
A ring of flowing metal around a button, in its text or on a badge, that lights whatever sits next to it.
Build anything…
Agent
Auto
Plan
Live mode
Move the cursor across the send button: the ring dents, and the chip beside it catches its light.
Playground
<script>
import { MetalFx, useMetalBend } from 'runeglow/metal-fx';
let ring = $state(null);
useMetalBend(() => ring); // the ring dents under the cursor
let search = $state(null); // a neighbour that catches the reflection
</script>
<label bind:this={search}>…</label>
<MetalFx
bind:ref={ring}
variant="circle"
theme="dark"
strength={0.81}
innerShadow
reflectionTargets={[search]}
>
<button aria-label="Send"><ArrowUp /></button>
</MetalFx>Install
pnpm add runeglow Or copy just this library’s source into your project, with the shadcn-svelte CLI:
npx shadcn-svelte@latest add https://runeglow.dev/r/metal-fx.json import { MetalFx, MetalText, MetalBadge } from 'runeglow/metal-fx';Usage
Wrap one element. The ring is drawn on top of it, and the element stays fully interactive. The
wrapper is inline-flex and sizes itself to the element.
<script>
import { MetalFx } from 'runeglow/metal-fx';
</script>
<MetalFx>
<button class="upgrade">Upgrade to Pro</button>
</MetalFx>
<MetalFx variant="circle" preset="gold">
<button aria-label="Send"><ArrowUp /></button>
</MetalFx>Hand it neighbouring elements and they catch a reflection of the ring. useMetalBend makes the ring dent under the cursor.
<script>
import { MetalFx, useMetalBend } from 'runeglow/metal-fx';
let ring = $state(null);
let chip = $state(null);
useMetalBend(() => ring); // the ring dents under the cursor
</script>
<button bind:this={chip}>Tools</button>
<MetalFx bind:ref={ring} variant="circle" innerShadow reflectionTargets={[chip]}>
<button aria-label="Send"><ArrowUp /></button>
</MetalFx>Metal can fill text, or dress a badge.
<script>
import { MetalText, MetalBadge, useMetalTextReflection } from 'runeglow/metal-fx';
let plan = $state(null);
useMetalTextReflection(() => plan); // "Plan" catches the metal on its letters
</script>
<span bind:this={plan}>Plan</span>
<MetalText
text="Pro"
font="500 24px/1.2 Inter, sans-serif"
color="#e2e2e2"
reflectionTargets={[{ el: plan, strength: 0.64 }]}
/>
<MetalBadge text="New" />The glow, the bend and the material are tuned for the whole page, since one renderer draws every instance.
<script>
import { setGlowConfig, setBendConfig, setSharedPresetMode, PRESETS } from 'runeglow/metal-fx';
setGlowConfig({ haloOpMul: 1.2 }); // a calmer halo
setBendConfig({ strength: 1.2, reach: 48 }); // a deeper dent
setSharedPresetMode({ ...PRESETS.silver.modes.dark, repetition: 3, distortion: 0.2 });
</script>MetalFx
Prop Type Default Description
variant 'button' | 'circle' 'button' A pill ring 1px wide, or a compact circle with a 2px ring.preset 'chromatic' | 'silver' | 'gold' 'chromatic' The palette. Shared by every instance on the page.theme 'auto' | 'dark' | 'light' 'auto' auto follows the system setting, live.strength number 1 Opacity of the metal and its glow, 0 to 1. The shader keeps animating at any value.glowGain number 1 Multiplier on the glow only, on top of strength.paused boolean false Freezes this instance on its current frame.disableGlow boolean false Leaves the wandering halo out. The ring still renders.innerShadow boolean | { offsetY?, blur?, alpha?, color? } – A hairline of light along the top inside edge of the ring.reflectionTargets Array<HTMLElement | { el, strength? }> – Neighbouring elements that catch a reflection of the ring. Dark theme only.borderRadius number auto Corner radius in px. Omit it to read the wrapped element’s.shaderScale number 1.6 / 1.3 Zoom of the metal’s pattern.ringCssPx number 1 / 2 Ring thickness in px.scale number 1 Multiplies every pixel constant, for an interface drawn larger than 1×.normalizeHostStyles boolean true Clears the wrapped element’s own border, outline and shadow so they don’t fight the ring.mask (ctx, width, height, dpr) => void – Paint your own alpha mask: the metal shows only where it paints. MetalText and MetalBadge are built on it.glowMode 'mask' | 'ring' 'mask' With a mask, whether the glow sits inside the mask or along the element’s edge.ref HTMLDivElement | null – The wrapper element. Bindable with bind:ref....rest HTMLAttributes<HTMLDivElement> – class, style and other attributes are forwarded to the wrapper.MetalText
Prop Type Default Description
text string – The text. It is drawn into the metal’s mask as well as the page.font string – CSS font shorthand, such as 500 24px/1.2 Inter, sans-serif.color string – The base text colour. The metal composites over it.metalOpacity number 0.62 How much metal shows over the base colour.shaderScale number 2.8 Zoom of the metal inside the letters.innerShadow { offsetY, blur, alpha } | null { 1, 0.5, 0.9 } Light along the top inside edge of each letter. null turns it off.glow, glowGain boolean, number false, 2.5 A halo clipped to the letters.strength, theme, paused, reflectionTargets, ref – As on MetalFx.MetalBadge
Prop Type Default Description
text string 'New' The label.scale number 1 Size multiplier on the 45 by 25 px design.metalOpacity number 0.8 How much metal shows over the white fill.core { r, blur, a, size } – The clean white core under the label: solid radius, ramp width, opacity, ellipse size.gradient, glow number 0, 0.41 A top-to-bottom white wash, and the soft inner glow.textColor string '#323232' Colour of the label.strength, theme, shaderScale, paused, reflectionTargets, ref – As on MetalFx.Functions
Function Type Default Description
useMetalBend(() => el, getConfig?) – The ring dents like liquid under the cursor. Call it while a component is set up, with a function returning the MetalFx element.useMetalTextReflection(() => el) – A text element that is a reflection target catches the light on its letters only.attachMetalBend(el), attachMetalTextReflection(el) – The same two as plain functions that return a cleanup, for use outside a component.setGlowConfig, resetGlowConfig – Tune the halo: intensity, fades, sizes.setBendConfig, resetBendConfig – Tune the cursor bend: strength, reach, the largest dent, the springs.setCursorSprite, setCursorLightConfig – Let the metal light the pointer. It needs an image of the pointer to draw in its place.setSharedPreset, setSharedPresetMode – Set the material directly: stripes, softness, dispersion, distortion, angle, speed.isMetalFxSupported() – Whether this browser has WebGL2.Notes
- It needs WebGL2. Where that is missing, the wrapped element renders as it is, and the wrapper
carries
data-metal-fx-unsupported. - One WebGL context and one animation loop are shared by every instance on the page. That is why the preset, the theme and the material are shared too: the last one set wins.
- Reflections are skipped in the light theme.
- Instances pause while offscreen.
- The material is Paper Shaders’
liquidMetalshader, used unmodified under the Apache 2.0 licence. The package’s NOTICE file carries the attribution. - The cursor reflection redraws the pointer as an image while it is lit. This site uses its own arrow for that; supply the one that matches your users’ pointer.