Live preview · fully interactive
The prompt
Build a button that swaps its label after click. ## Look Button #7c6cff, white text, radius 12px, padding 14px 22px, min-width 120px. Success state background #34d399. Page #08080d. ## Behavior On click, set the label to Copied and add the success color. After 1400ms restore Copy and the violet background. ## Design tokens - Rest #7c6cff; success #34d399; text #fff; page #08080d. ## Motion - Color transition 0.2s ease. Hold the success label 1400ms. ## Constraints - Single self-contained HTML file. No libraries. - Honor prefers-reduced-motion: reduce by skipping the loop and leaving a readable static frame - Readable at 390px width with no horizontal page scroll
The code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
background: #08080d; color: #f2f2f7; font-family: Inter, system-ui, sans-serif;
min-height: 100vh; overflow: hidden;
}
.hint { position: absolute; left: 16px; top: 16px; z-index: 5; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #8a8a99; }
main { min-height: 100vh; display: grid; place-items: center; } button { border: 0; background: #7c6cff; color: #fff; border-radius: 12px; padding: 14px 22px; font-weight: 700; min-width: 120px; cursor: pointer; transition: background 0.2s ease; } button.done { background: #34d399; }
@media (max-width: 420px) {
.hint { font-size: 10px; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
</style>
</head>
<body>
<main><button id="b">Copy</button></main>
<script>
var b = document.getElementById("b");
b.addEventListener("click", function () {
b.textContent = "Copied";
b.classList.add("done");
setTimeout(function () { b.textContent = "Copy"; b.classList.remove("done"); }, 1400);
});
</script>
</body>
</html>About this effect
Click changes the label to “Copied” for 1.4s and tints the button. It returns to “Copy” without a second click.