About this snippet

Engage visitors with this dynamic text effect for your headlines. It types out a word, pauses, deletes it, and types the next one, which allows you to showcase multiple value propositions in a single spot.

Size
1.4 KB
Uses
HTML, CSS, JavaScript
Loads
Nothing external
Views
568
<div class="typing-wrapper">
  <h1>I am a <span class="type-text"></span><span class="cursor">|</span></h1>
</div>
.typing-wrapper {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
h1 {
  font-size: 2.5rem;
  color: #1f2937;
}
.type-text {
  color: #3b82f6;
  font-weight: 700;
}
.cursor {
  animation: blink 1s step-end infinite;
  color: #374151;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
const textElement = document.querySelector(".type-text");
const words = ["Developer", "Designer", "Creator", "Freelancer"];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;

const typeEffect = () => {
  const currentWord = words[wordIndex];
  
  if (isDeleting) {
    charIndex--;
    textElement.textContent = currentWord.substring(0, charIndex);
  } else {
    charIndex++;
    textElement.textContent = currentWord.substring(0, charIndex);
  }

  if (!isDeleting && charIndex === currentWord.length) {
    isDeleting = true;
    setTimeout(typeEffect, 2000); // Pause at end
  } else if (isDeleting && charIndex === 0) {
    isDeleting = false;
    wordIndex = (wordIndex + 1) % words.length;
    setTimeout(typeEffect, 500); // Pause before typing new word
  } else {
    setTimeout(typeEffect, isDeleting ? 100 : 200); // Speed
  }
};

typeEffect();
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save