Skip to content

Copy Button

A copy-paste micro-interactions component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Micro-interactionsHTMLCSSJavaScriptany framework

Copy into your project

HTML
<button class="nuda-copy-btn" aria-label="Copy to clipboard">
  <svg class="nuda-copy-btn__clip" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <rect x="9" y="9" width="13" height="13" rx="2"/>
    <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
  </svg>
  <svg class="nuda-copy-btn__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
    <polyline points="20 6 9 17 4 12"/>
  </svg>
</button>
CSS
/* Copy Button
   Clipboard icon transitions to checkmark.
   Customize: --copy-success */

.nuda-copy-btn {
  --copy-success: #22c55e;
  position: relative;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  color: #ccc;
  transition: border-color 0.2s;
}

.nuda-copy-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.nuda-copy-btn svg {
  width: 18px;
  height: 18px;
  transition: all 0.3s ease;
  will-change: transform, opacity;
}

.nuda-copy-btn__check {
  position: absolute;
  inset: 0;
  margin: auto;
  opacity: 0;
  transform: scale(0.5);
  color: var(--copy-success);
}

.nuda-copy-btn--copied .nuda-copy-btn__clip {
  opacity: 0;
  transform: scale(0.5);
}

.nuda-copy-btn--copied .nuda-copy-btn__check {
  opacity: 1;
  transform: scale(1);
}

.nuda-copy-btn--copied {
  border-color: rgba(34, 197, 94, 0.3);
}

@media (prefers-reduced-motion: reduce) {
  .nuda-copy-btn svg { transition: none; }
}
JavaScript
/* Copy Button — vanilla JS
   Copies text and shows checkmark. */

(function () {
  document.querySelectorAll(".nuda-copy-btn").forEach(function (btn) {
    btn.addEventListener("click", function () {
      var text = btn.getAttribute("data-copy") || "";
      if (navigator.clipboard) {
        navigator.clipboard.writeText(text);
      }
      btn.classList.add("nuda-copy-btn--copied");
      setTimeout(function () {
        btn.classList.remove("nuda-copy-btn--copied");
      }, 1500);
    });
  });
})();

How to use Copy Button

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More micro-interactions components

← Browse all NudaUI components