타이프라이터

Typewriter

글자가 타자기처럼 한 자씩 나타나고, 깜빡이는 커서가 끝에 따라붙는 텍스트 등장 효과.

다른 이름: Type-on effectText typing animation
···
html
<div class="type"><span id="txt"></span><i class="cursor"></i></div>
css
.type{display:flex;align-items:center;max-width:88%;font:700 clamp(15px,5.2vmin,28px)/1.2 ui-monospace,monospace;color:var(--fg)}
.cursor{width:2px;height:1em;background:var(--accent);margin-left:2px;animation:blink 1s step-end infinite}
@keyframes blink{50%{opacity:0}}
js
const words = ['이징을 이해하면', '모션이 보인다', 'Design Atlas'];
const el = document.getElementById('txt');
let wi = 0, ci = 0, deleting = false;
function tick() {
  const word = words[wi];
  el.textContent = word.slice(0, ci);
  if (!deleting) {
    ci++;
    if (ci > word.length) { deleting = true; setTimeout(tick, 900); return; }
  } else {
    ci--;
    if (ci < 0) { deleting = false; wi = (wi + 1) % words.length; ci = 0; }
  }
  setTimeout(tick, deleting ? 40 : 80);
}
tick();

CSS만으로는 width를 0에서 100%로 늘리고 overflow:hidden으로 가리는 steps() 애니메이션이 고전적인 구현입니다 — 글자 수만큼 steps(n)을 줘야 한 프레임에 한 글자씩 나타납니다. 가변 폭 폰트에서는 정확히 맞추기 까다로워서, 실무에서는 JS로 substring을 늘려가며 텍스트 노드를 직접 갱신하는 방식을 더 많이 씁니다.

여러 문장을 이어 칠 때는 다 쓴 뒤 지우고 다음 문장을 타이핑하는 식으로 루프를 만듭니다. 커서는 별도 요소에 step-end 깜빡임을 줍니다.

언제 쓰나

히어로 헤드라인 하나 정도로 아껴 쓰세요. 본문 문단에 쓰면 읽는 속도를 강제로 늦춰 오히려 불편합니다.