All effectsPlay & loop

Typewriter Effect

打字机效果

Characters appear one at a time like live typing, often with a caret at the end.

Play the typing preview

Where to use it

Bring a short tagline, prompt example, or terminal line to life. Use a short line beside a static heading so visitors can understand the page while the characters appear.

Practical example

A command-line backup tool types “backup run ~/photos” into a sample terminal on first view. The complete line stays visible so visitors can copy the syntax after seeing it appear character by character.

Also called

  • Typing Animation

AI prompt

Add a Typewriter Effect to [target text]. Reveal whole visible characters at a comfortable pace, reserve enough layout space for the final line, and let assistive technology read the complete text once. If the sequence loops, give users a pause control. Show the full text immediately with reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Typewriter Effect</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .terminal {
      display: flex;
      align-items: center;
      gap: 9px;
      width: min(100%, 232px);
      padding: 17px;
      border: 1px solid #63557f;
      border-radius: 12px;
      background: #242034;
      color: #e9deff;
      font: 650 clamp(12px, 5vw, 17px)/1.4 ui-monospace, monospace;
    }
    .terminal-prompt { color: #adf0cb; }
    .typed-line {
      box-sizing: content-box;
      width: 12ch;
      overflow: hidden;
      white-space: nowrap;
      border-right: 2px solid #adf0cb;
      animation: type-line 4.1s steps(12, end) infinite;
    }
    @keyframes type-line {
      0%, 5%, 100% { width: 12ch; }
      6%, 14% { width: 0; }
      58% { width: 12ch; }
    }

    .loop-example {
      display: grid;
      gap: 12px;
      justify-items: center;
      width: min(100%, 290px);
    }
    .loop-example [data-motion] { animation-play-state: paused; }
    .loop-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .loop-example [data-motion] { animation: none; }
      .loop-example [data-loop-toggle] { display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="loop-example">
      <div class="terminal">
        <span class="terminal-prompt" aria-hidden="true">&gt;</span>
        <span class="typed-line" data-motion>Type it out.</span>
      </div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.loop-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "Pause demo" : "Play demo";
    });
  </script>
</body>
</html>

Original example by UI Skills