Animated buttons
A small movement can make a button feel responsive. It can also distract from the action or hide what changed. Use the example to compare movement with a quieter version, then decide which part of the interaction actually needs animation.
// glass-generate · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-more="glass-generate"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassMore["glass-generate"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}
// glass-share · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-more="glass-share"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassMore["glass-share"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}Interactive demo. No data is sent.
Give the movement a job
Start with one visible change: a pressed surface, a revealed option, or an icon confirming completion. Explain that change in a sentence before building it. A bookmark button might fill its icon when selected. A disclosure button might rotate an arrow as its content opens. The movement should help someone connect the two states.
Leave supporting details still when they add no information. A bouncing label, drifting glow, and spinning icon can compete inside one small control. Preview the button at its actual size beside surrounding text. An animation that looks impressive in an empty frame may become tiring when repeated throughout a product.
Use CSS for visual changes
CSS transitions are a useful starting point for a change between two known appearances. Keep the resting and active styles explicit, then transition only the properties that need movement. Listing those properties makes the behavior easier to review than transition: all, which can animate unrelated edits made later.
A small transform can create press feedback without changing the button’s layout box. Keep the clickable area steady, and avoid a large hover movement that makes the target seem to run away. Combine motion with a visible surface or icon change so people can still understand the state when motion is reduced.
.action {
transition: transform 160ms ease, background-color 160ms ease;
}
.action:active { transform: translateY(1px); }
@media (prefers-reduced-motion: reduce) {
.action { transition: none; }
}Let JavaScript manage the action
Use JavaScript when the state depends on an event or an operation: opening options, toggling a choice, or awaiting a response. Change a class or data attribute to describe the state and let CSS handle its appearance. Keep the application result separate from the animation’s completion event.
For example, a save animation can begin when a request starts, but its success state must wait for the real result. If the operation fails, show an error even when the visual sequence was expected to succeed. The demo here is a local illustration; its animation does not carry out a save or download.
Test the return journey
Move the pointer away halfway through a hover transition. Open a disclosure and close it immediately. Toggle a selection twice before its first animation ends. Each interaction should settle into the current state without leaving an icon, label, or invisible overlay behind. These interruptions are normal use, not unusual edge cases.
Check keyboard activation and a touch-sized viewport too. Hover can add feedback, but essential instructions and actions must be available without it. If the control changes width, watch nearby elements for jumps. Test a long label and a translated label before committing to a tightly fitted animated shell.
Keep a quieter version available
Respect prefers-reduced-motion with a version that keeps the information while removing unnecessary travel, scaling, or repeated motion. Use an immediate icon swap or a steady state label where appropriate. The setting should change presentation, while the person can still complete and understand the same action.
When choosing an animated button from SL UI Library, inspect its opening, closing, and repeat activation. Take the complete source package and keep its controller with the styles. React and Next.js entries mount the original behavior and may require adjacent files. After adapting colors, test the component inside the real page rather than relying on the library preview alone.
Reference documentation
Technical documentation behind these examples. You can use the article without opening these links.