# Terminal copy button

> A terminal command with a blinking cursor: on press it gets selected character by character, copied and confirmed.

- Category: [Buttons](https://library.aimran.es/components/buttons)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-btn-copy-cli
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Install commands are often the first thing developers copy from a landing page, and this button makes that moment clear. The command sits on a dark slate pill with an amber prompt and a blinking block cursor. On click the text is highlighted in steps as if selected by hand, copied to the clipboard, the icon turns into a check and a small Copied tag is shown and announced.

Replace the label with your own command; it is copied exactly as written. The main color sets the prompt, cursor and confirmation, and the secondary color sets the background, so a light theme or a brand green are a quick change.

## Code

### HTML

```html
<div class="uvq01-cli"><button class="b" type="button"><span class="ps" aria-hidden="true">$</span><code class="cm">npx aimran add hero</code><span class="cr" aria-hidden="true"></span><span class="ic" aria-hidden="true"><svg class="cp" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="8" width="12" height="12" rx="2.5"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"/></svg><span class="ck"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></span><span class="sr">Copy</span></button><span class="ok" role="status"></span><span class="msg" hidden>Copied</span></div>
```

### CSS

```css
.uvq01-cli {
  --c1: #ffb454;
  --c2: #1d2026;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq01-cli {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  justify-items: center;
  padding-top: 2.6em;
}

.uvq01-cli .b {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  gap: .6em;
  padding: .6em .6em .6em 1.1em;
  border-radius: .75em;
  font: 500 .95em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  color: #e8e6e3;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.65);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ps {
  color: var(--c1);
  font-weight: 700;
}

.uvq01-cli .cm {
  padding: .2em .1em;
  border-radius: .2em;
  font: inherit;
  color: inherit;
  background: linear-gradient(color-mix(in srgb,var(--c1) 32%,transparent),color-mix(in srgb,var(--c1) 32%,transparent)) 0 0/0% 100% no-repeat;
}

.uvq01-cli .cr {
  width: .55em;
  height: 1.15em;
  margin-left: -.35em;
  background: var(--c1);
  animation: uvq01-cli-bl calc(1.05s / var(--k)) steps(1) infinite;
}

.uvq01-cli .ic {
  display: grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  margin-left: .4em;
  border-radius: .5em;
  background: rgba(255,255,255,.07);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ic>* {
  grid-area: 1/1;
  display: grid;
  width: 1.05em;
  height: 1.05em;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-cli .ic svg {
  width: 100%;
  height: 100%;
}

.uvq01-cli .ck {
  opacity: 0;
  scale: .4;
  color: var(--c1);
}

.uvq01-cli .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.uvq01-cli .ok {
  position: absolute;
  top: 0;
  padding: .45em .8em;
  border-radius: .5em;
  font-size: .8em;
  font-weight: 700;
  line-height: 1;
  color: #1b1b1b;
  background: var(--c1);
  opacity: 0;
  translate: 0 .4em;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}

.uvq01-cli .ok:empty {
  padding: 0;
}

.uvq01-cli .b:hover .ic {
  background: rgba(255,255,255,.15);
}

.uvq01-cli .b:active {
  transform: scale(.97);
}

.uvq01-cli .b:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq01-cli.is-copied .cm {
  background-size: 100% 100%;
  transition: background-size calc(0.4s / var(--k)) steps(10,end);
}

.uvq01-cli.is-copied .cr {
  animation: none;
  opacity: 0;
}

.uvq01-cli.is-copied .cp {
  opacity: 0;
  scale: .4;
}

.uvq01-cli.is-copied .ck {
  opacity: 1;
  scale: 1;
}

.uvq01-cli.is-copied .ok {
  opacity: 1;
  translate: 0 0;
}

@keyframes uvq01-cli-bl {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-cli,.uvq01-cli *,.uvq01-cli *::before,.uvq01-cli *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq01-cli").forEach(el => {
  const b=el.querySelector(".b"),cm=el.querySelector(".cm"),ok=el.querySelector(".ok"),msg=el.querySelector(".msg");let tm=0,raf=0;
b.addEventListener("click",()=>{try{navigator.clipboard&&navigator.clipboard.writeText(cm.textContent).catch(()=>{})}catch(_){}el.classList.remove("is-copied");void el.offsetWidth;el.classList.add("is-copied");ok.textContent="";cancelAnimationFrame(raf);raf=requestAnimationFrame(()=>{ok.textContent=msg.textContent});clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-copied"),1900)});
return()=>{clearTimeout(tm);cancelAnimationFrame(raf)}
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq01-cli {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  justify-items: center;
  padding-top: 2.6em;
}

.uvq01-cli .b {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  gap: .6em;
  padding: .6em .6em .6em 1.1em;
  border-radius: .75em;
  font: 500 .95em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  color: #e8e6e3;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.65);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ps {
  color: var(--c1);
  font-weight: 700;
}

.uvq01-cli .cm {
  padding: .2em .1em;
  border-radius: .2em;
  font: inherit;
  color: inherit;
  background: linear-gradient(color-mix(in srgb,var(--c1) 32%,transparent),color-mix(in srgb,var(--c1) 32%,transparent)) 0 0/0% 100% no-repeat;
}

.uvq01-cli .cr {
  width: .55em;
  height: 1.15em;
  margin-left: -.35em;
  background: var(--c1);
  animation: uvq01-cli-bl calc(1.05s / var(--k)) steps(1) infinite;
}

.uvq01-cli .ic {
  display: grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  margin-left: .4em;
  border-radius: .5em;
  background: rgba(255,255,255,.07);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ic>* {
  grid-area: 1/1;
  display: grid;
  width: 1.05em;
  height: 1.05em;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-cli .ic svg {
  width: 100%;
  height: 100%;
}

.uvq01-cli .ck {
  opacity: 0;
  scale: .4;
  color: var(--c1);
}

.uvq01-cli .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.uvq01-cli .ok {
  position: absolute;
  top: 0;
  padding: .45em .8em;
  border-radius: .5em;
  font-size: .8em;
  font-weight: 700;
  line-height: 1;
  color: #1b1b1b;
  background: var(--c1);
  opacity: 0;
  translate: 0 .4em;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}

.uvq01-cli .ok:empty {
  padding: 0;
}

.uvq01-cli .b:hover .ic {
  background: rgba(255,255,255,.15);
}

.uvq01-cli .b:active {
  transform: scale(.97);
}

.uvq01-cli .b:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq01-cli.is-copied .cm {
  background-size: 100% 100%;
  transition: background-size calc(0.4s / var(--k)) steps(10,end);
}

.uvq01-cli.is-copied .cr {
  animation: none;
  opacity: 0;
}

.uvq01-cli.is-copied .cp {
  opacity: 0;
  scale: .4;
}

.uvq01-cli.is-copied .ck {
  opacity: 1;
  scale: 1;
}

.uvq01-cli.is-copied .ok {
  opacity: 1;
  translate: 0 0;
}

@keyframes uvq01-cli-bl {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-cli,.uvq01-cli *,.uvq01-cli *::before,.uvq01-cli *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const b=el.querySelector(".b"),cm=el.querySelector(".cm"),ok=el.querySelector(".ok"),msg=el.querySelector(".msg");let tm=0,raf=0;
b.addEventListener("click",()=>{try{navigator.clipboard&&navigator.clipboard.writeText(cm.textContent).catch(()=>{})}catch(_){}el.classList.remove("is-copied");void el.offsetWidth;el.classList.add("is-copied");ok.textContent="";cancelAnimationFrame(raf);raf=requestAnimationFrame(()=>{ok.textContent=msg.textContent});clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-copied"),1900)});
return()=>{clearTimeout(tm);cancelAnimationFrame(raf)}
}

export default function BtnCopyCli() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ffb454",
          "--c2": "#1d2026",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq01-cli"><button className="b" type="button"><span className="ps" aria-hidden="true">$</span><code className="cm">npx aimran add hero</code><span className="cr" aria-hidden="true"></span><span className="ic" aria-hidden="true"><svg className="cp" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="8" y="8" width="12" height="12" rx="2.5" /><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" /></svg><span className="ck"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg></span></span><span className="sr">Copy</span></button><span className="ok" role="status"></span><span className="msg" hidden={true}>Copied</span></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Terminal copy button” block (Buttons) from AIMRAN Library to my project.

## What it is
A terminal command with a blinking cursor: on press it gets selected character by character, copied and confirmed.

## Chosen settings
- Main color: #ffb454
- Secondary color: #1d2026
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "npx aimran add hero"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq01-cli {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  justify-items: center;
  padding-top: 2.6em;
}

.uvq01-cli .b {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  gap: .6em;
  padding: .6em .6em .6em 1.1em;
  border-radius: .75em;
  font: 500 .95em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  color: #e8e6e3;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.65);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ps {
  color: var(--c1);
  font-weight: 700;
}

.uvq01-cli .cm {
  padding: .2em .1em;
  border-radius: .2em;
  font: inherit;
  color: inherit;
  background: linear-gradient(color-mix(in srgb,var(--c1) 32%,transparent),color-mix(in srgb,var(--c1) 32%,transparent)) 0 0/0% 100% no-repeat;
}

.uvq01-cli .cr {
  width: .55em;
  height: 1.15em;
  margin-left: -.35em;
  background: var(--c1);
  animation: uvq01-cli-bl calc(1.05s / var(--k)) steps(1) infinite;
}

.uvq01-cli .ic {
  display: grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  margin-left: .4em;
  border-radius: .5em;
  background: rgba(255,255,255,.07);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-cli .ic>* {
  grid-area: 1/1;
  display: grid;
  width: 1.05em;
  height: 1.05em;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-cli .ic svg {
  width: 100%;
  height: 100%;
}

.uvq01-cli .ck {
  opacity: 0;
  scale: .4;
  color: var(--c1);
}

.uvq01-cli .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.uvq01-cli .ok {
  position: absolute;
  top: 0;
  padding: .45em .8em;
  border-radius: .5em;
  font-size: .8em;
  font-weight: 700;
  line-height: 1;
  color: #1b1b1b;
  background: var(--c1);
  opacity: 0;
  translate: 0 .4em;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}

.uvq01-cli .ok:empty {
  padding: 0;
}

.uvq01-cli .b:hover .ic {
  background: rgba(255,255,255,.15);
}

.uvq01-cli .b:active {
  transform: scale(.97);
}

.uvq01-cli .b:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq01-cli.is-copied .cm {
  background-size: 100% 100%;
  transition: background-size calc(0.4s / var(--k)) steps(10,end);
}

.uvq01-cli.is-copied .cr {
  animation: none;
  opacity: 0;
}

.uvq01-cli.is-copied .cp {
  opacity: 0;
  scale: .4;
}

.uvq01-cli.is-copied .ck {
  opacity: 1;
  scale: 1;
}

.uvq01-cli.is-copied .ok {
  opacity: 1;
  translate: 0 0;
}

@keyframes uvq01-cli-bl {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-cli,.uvq01-cli *,.uvq01-cli *::before,.uvq01-cli *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const b=el.querySelector(".b"),cm=el.querySelector(".cm"),ok=el.querySelector(".ok"),msg=el.querySelector(".msg");let tm=0,raf=0;
b.addEventListener("click",()=>{try{navigator.clipboard&&navigator.clipboard.writeText(cm.textContent).catch(()=>{})}catch(_){}el.classList.remove("is-copied");void el.offsetWidth;el.classList.add("is-copied");ok.textContent="";cancelAnimationFrame(raf);raf=requestAnimationFrame(()=>{ok.textContent=msg.textContent});clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-copied"),1900)});
return()=>{clearTimeout(tm);cancelAnimationFrame(raf)}
}

export default function BtnCopyCli() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ffb454",
          "--c2": "#1d2026",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq01-cli"><button className="b" type="button"><span className="ps" aria-hidden="true">$</span><code className="cm">npx aimran add hero</code><span className="cr" aria-hidden="true"></span><span className="ic" aria-hidden="true"><svg className="cp" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="8" y="8" width="12" height="12" rx="2.5" /><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" /></svg><span className="ck"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg></span></span><span className="sr">Copy</span></button><span className="ok" role="status"></span><span className="msg" hidden={true}>Copied</span></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
