<h1 class="text">I am a&nbsp;</h1>
@import url("https://fonts.googleapis.com/css2?family=Cousine:wght@700&display=swap");

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

body {
  font-family: "Cousine", monospace;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background-color: black;
}

:root {
  --text-color: white;
}

.text {
  font-size: 4rem;
  display: inline-block;
  letter-spacing: 0.2rem;
  color: var(--text-color);
  border-right: 1rem solid var(--text-color);
  animation: blink 0.5s step-end infinite alternate;
}

.char {
  color: orange;
}

@keyframes blink {
  50% {
    border-color: transparent;
  }
}

@media (min-width: 600px) {
  .text {
    font-size: 6rem;
  }
}

@media (min-width: 900px) {
  .text {
    font-size: 8rem;
  }
}

@media (min-width: 1200px) {
  .text {
    font-size: 11rem;
  }
}

@media (min-width: 1600px) {
  .text {
    font-size: 14rem;
  }
}
const textEl = document.querySelector(".text");

const words = ["Developer", "Youtuber", "Blogger"].map((word) => word + ".");

let wordIndex = 0;
let charIndex = 0;

let addingChars = true;
let shouldWait = false;

let currentWord = words[wordIndex];

const updateCurrWord = () => {
  wordIndex++;

  if (wordIndex === words.length) wordIndex = 0;

  currentWord = words[wordIndex];
};

const addChar = () => {
  let currChar = currentWord[charIndex];

  const char = document.createElement("span");

  char.innerText = currChar;
  char.classList.add("char");

  textEl.appendChild(char);

  charIndex++;

  if (charIndex === currentWord.length) {
    charIndex--;
    addingChars = false;
    shouldWait = true;
  }
};

const removeChar = () => {
  const char = textEl.lastElementChild;

  textEl.removeChild(char);

  charIndex--;

  if (charIndex < 0) {
    charIndex++;
    addingChars = true;
    updateCurrWord();
  }
};

const runTypewriter = () => {
  const operation = addingChars ? addChar : removeChar;

  operation();

  let timeout = addingChars ? 200 : 100;

  if (shouldWait) {
    timeout = 1000;
    shouldWait = false;
  }

  setTimeout(runTypewriter, timeout);
};

setTimeout(runTypewriter, 1500);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.