Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Copy Button

    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 button
    pnpm dlx markasui add button
    pnpm 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>
    import { CopyButton } from "@/components/markas/CopyButton";
    
    export default function CopyButtonExample() {
      return (
        <div className="flex items-center justify-between gap-3 rounded-lg border border-line bg-surface py-2 pr-2 pl-4">
          <code className="font-mono text-sm text-ink">
            pnpm dlx markasui add button
          </code>
          <CopyButton
            text="pnpm dlx markasui add button"
            variant="ghost"
            size="sm"
            copyLabel="Copy command"
          />
        </div>
      );
    }
    <script setup lang="ts">
    import CopyButton from "@/components/markas/CopyButton.vue";
    </script>
    
    <template>
      <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>
        <CopyButton
          text="pnpm dlx markasui add button"
          variant="ghost"
          size="sm"
          copy-label="Copy command"
        />
      </div>
    </template>
    <script lang="ts">
      import CopyButton from "$lib/components/markas/CopyButton.svelte";
    </script>
    
    <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>
      <CopyButton
        text="pnpm dlx markasui add button"
        variant="ghost"
        size="sm"
        copyLabel="Copy command"
      />
    </div>
    ---
    import CopyButton from "@/components/markas/CopyButton.astro";
    ---
    
    <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>
      <CopyButton
        text="pnpm dlx markasui add button"
        variant="ghost"
        size="sm"
        copyLabel="Copy command"
      />
    </div>
    import { Component } from "@angular/core";
    import { CopyButton } from "./markas/copy-button.component";
    
    @Component({
      selector: "markas-example",
      imports: [CopyButton],
      template: `
        <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>
          <markas-copy-button
            text="pnpm dlx markasui add button"
            variant="ghost"
            size="sm"
            copyLabel="Copy command"
          />
        </div>
      `,
    })
    export default class CopyButtonExample {}

    Examples

    Variants

    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.

    Share link

    Share this board

    Anyone with the link can view. Only members can edit.

    https://markasui.com/b/roadmap-q3

    Share this board

    Anyone with the link can view. Only members can edit.

    https://markasui.com/b/roadmap-q3

    Share this board

    Anyone with the link can view. Only members can edit.

    https://markasui.com/b/roadmap-q3

    Share this board

    Anyone with the link can view. Only members can edit.

    https://markasui.com/b/roadmap-q3

    Share this board

    Anyone with the link can view. Only members can edit.

    https://markasui.com/b/roadmap-q3

    Installation

    npx markasui@latest add copy-button

    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.clipboard.writeText, which needs a secure context (https or localhost). If the browser blocks the clipboard, the button stays idle.
    • 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

    NameTypeDefaultDescription
    textstring-Text written to the clipboard.
    variant'primary' | 'secondary' | 'ghost' | 'danger'primaryVisual style, the same set as Button.
    size'sm' | 'md' | 'lg'mdHeight 32, 40, or 48px. Without a label the button is square.
    copyLabelstringCopyHidden name of an icon-only button.
    copiedLabelstringCopiedAnnounced 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.