Copies a string to the clipboard. The copy icon turns into an animated check mark and a live region says Copied.
pnpm dlx markasui add button
pnpm dlx markasui add buttonpnpm dlx markasui add buttonpnpm dlx markasui add button pnpm dlx markasui add button<div class="flex items-center justify-between gap-3 rounded-lg border border-line bg-surface py-2 pr-2 pl-4">
<code class="font-mono text-sm text-ink">pnpm dlx markasui add button</code>
<x-markas.copy-button text="pnpm dlx markasui add button" variant="ghost" size="sm" copy-label="Copy command" />
</div>Examples
Variants
<div class="flex flex-wrap items-center justify-center gap-3">
<x-markas.copy-button text="INV-2048">Copy</x-markas.copy-button>
<x-markas.copy-button text="INV-2048" variant="secondary">Copy ID</x-markas.copy-button>
<x-markas.copy-button text="INV-2048" variant="ghost">Copy</x-markas.copy-button>
<x-markas.copy-button text="INV-2048" variant="secondary" copy-label="Copy ID" />
</div><script setup lang="ts">
import CopyButton from "@/components/markas/CopyButton.vue";
</script>
<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<CopyButton text="INV-2048">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary">Copy ID</CopyButton>
<CopyButton text="INV-2048" variant="ghost">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary" copy-label="Copy ID" />
</div>
</template><script lang="ts">
import CopyButton from "$lib/components/markas/CopyButton.svelte";
</script>
<div class="flex flex-wrap items-center justify-center gap-3">
<CopyButton text="INV-2048">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary">Copy ID</CopyButton>
<CopyButton text="INV-2048" variant="ghost">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary" copyLabel="Copy ID" />
</div>---
import CopyButton from "@/components/markas/CopyButton.astro";
---
<div class="flex flex-wrap items-center justify-center gap-3">
<CopyButton text="INV-2048">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary">Copy ID</CopyButton>
<CopyButton text="INV-2048" variant="ghost">Copy</CopyButton>
<CopyButton text="INV-2048" variant="secondary" copyLabel="Copy ID" />
</div>API key field
Secret key
Keep this key private. It grants full access to your account.
Secret key
Keep this key private. It grants full access to your account.
Secret key
Keep this key private. It grants full access to your account.
Secret key
Keep this key private. It grants full access to your account.
Secret key
Keep this key private. It grants full access to your account.
<div class="grid grid-cols-1 gap-2">
<p class="text-sm font-medium text-ink">Secret key</p>
<div class="flex gap-2">
<input aria-label="Secret key" readonly value="sk_live_51Hx9aT2eZvKYlo2C" class="h-10 min-w-0 flex-1 rounded-lg border border-line bg-surface px-3 font-mono text-sm text-ink" />
<x-markas.copy-button text="sk_live_51Hx9aT2eZvKYlo2C" variant="secondary">Copy key</x-markas.copy-button>
</div>
<p class="text-sm text-muted">Keep this key private. It grants full access to your account.</p>
</div>Share link
Share this board
Anyone with the link can view. Only members can edit.
Share this board
Anyone with the link can view. Only members can edit.
Share this board
Anyone with the link can view. Only members can edit.
Share this board
Anyone with the link can view. Only members can edit.
Share this board
Anyone with the link can view. Only members can edit.
<div class="grid grid-cols-1 gap-4 rounded-xl border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Share this board</p>
<p class="text-sm text-muted">Anyone with the link can view. Only members can edit.</p>
</div>
<div class="flex items-center gap-3 rounded-lg bg-subtle py-1.5 pr-1.5 pl-3">
<span class="min-w-0 flex-1 truncate text-sm text-ink">https://markasui.com/b/roadmap-q3</span>
<x-markas.copy-button text="https://markasui.com/b/roadmap-q3" size="sm">Copy link</x-markas.copy-button>
</div>
</div>Installation
npx markasui@latest add copy-buttonpnpm dlx markasui@latest add copy-buttonyarn dlx markasui@latest add copy-buttonbunx --bun markasui@latest add copy-button- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/copy-button.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CopyButton.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CopyButton.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/CopyButton.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/CopyButton.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/copy-button.component.ts.
Usage
<x-markas.copy-button text="pnpm dlx markasui add button" variant="ghost" size="sm" copy-label="Copy command" />
<x-markas.copy-button text="sk_live_51Hx9aT2" variant="secondary">Copy key</x-markas.copy-button>import { CopyButton } from "@/components/markas/CopyButton";
<CopyButton text="pnpm dlx markasui add button" variant="ghost" size="sm" copyLabel="Copy command" />
<CopyButton text="sk_live_51Hx9aT2" variant="secondary">Copy key</CopyButton><script setup lang="ts">
import CopyButton from "@/components/markas/CopyButton.vue";
</script>
<template>
<CopyButton
text="pnpm dlx markasui add button"
variant="ghost"
size="sm"
copy-label="Copy command"
/>
<CopyButton text="sk_live_51Hx9aT2" variant="secondary">Copy key</CopyButton>
</template><script lang="ts">
import CopyButton from "$lib/components/markas/CopyButton.svelte";
</script>
<CopyButton
text="pnpm dlx markasui add button"
variant="ghost"
size="sm"
copyLabel="Copy command"
/>
<CopyButton text="sk_live_51Hx9aT2" variant="secondary">Copy key</CopyButton>---
import CopyButton from "@/components/markas/CopyButton.astro";
---
<CopyButton text="pnpm dlx markasui add button" variant="ghost" size="sm" copyLabel="Copy command" />
<CopyButton text="sk_live_51Hx9aT2" variant="secondary">Copy key</CopyButton>import { Component } from "@angular/core";
import { CopyButton } from "./markas/copy-button.component";
@Component({
selector: "app-install",
imports: [CopyButton],
template: `
<markas-copy-button
text="pnpm dlx markasui add button"
variant="ghost"
size="sm"
copyLabel="Copy command"
/>
<markas-copy-button text="sk_live_51Hx9aT2" variant="secondary">
Copy key
</markas-copy-button>
`,
})
export class Install {}Angular moves id, aria-label, title, and class from markas-copy-button to the inner button.
- Uses
navigator, which needs a secure context (https or localhost). If the browser blocks the clipboard, the button stays idle..clipboard .writeText - The check mark shows for 2 seconds, then the button returns to idle.
- Without a label the button is square and named by
copyLabel. Blade needs Alpine.js.
Props
| Name | Type | Default | Description |
|---|---|---|---|
text | string | - | Text written to the clipboard. |
variant | 'primary' | 'secondary' | 'ghost' | 'danger' | primary | Visual style, the same set as Button. |
size | 'sm' | 'md' | 'lg' | md | Height 32, 40, or 48px. Without a label the button is square. |
copyLabel | string | Copy | Hidden name of an icon-only button. |
copiedLabel | string | Copied | Announced by the live region after a successful copy. |
Accessibility
- A native button element, so Enter and Space work and focus shows a 2px primary outline.
- A visually hidden role=status region announces copiedLabel after the copy succeeds.
- Without a label the button is named by copyLabel, and both icons are aria-hidden.
- With prefers-reduced-motion the icon swaps without scaling or drawing.
Related components
More buttons components with the same classes in every framework.
- Flip ButtonButton that flips like a card on hover and keyboard focus to reveal a second line on the back.
- GitHub Stars ButtonLink to a GitHub repository with the GitHub mark and a star count that counts up when it scrolls into view. No fetch.
- Hold ButtonPress-and-hold button for risky actions. A fill tracks progress, releasing early cancels, and a complete event fires.
- Ripple ButtonButton that sends a ripple out from the click point, or from the center when pressed with the keyboard.
- Shimmer ButtonButton with a soft sheen that sweeps across it on a loop. The loop pauses off screen and stops with reduced motion.