How-to Create Split Text

Learn how-to create Strikethrough, Fractured, Split Text using HTML, CSS and JavaScript.

HTML, CSS, JavaScript, Web Development, Technology

How-to Create Split Text

HTML

<h1 contenteditable data-heading="Split">Split</h1>

CSS

h1 {
  color: black;
}
h1::before, h1::after {
  content: attr(data-heading);
  position: absolute;
  left: 0;
  overflow: hidden;
}
h1::before {
  height: 50%;
  color: white;
  text-shadow: 3px -2px 5px white, -3px 3px 4px white;
}
h1::after {
  -webkit-transform: translateX(-10px);
          transform: translateX(-10px);
  height: 49%;
  color: black;
}

html {
  height: 100vh;
}

body {
  font-family: 'Roboto', sans-serif;
  height: 100vh;
}

h1 {
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  position: absolute;
  margin: 0;
  font-size: 10vw;
  font-weight: 900;
  text-transform: uppercase;
}

JavaScript

var h1 = document.querySelector("h1");

h1.addEventListener("input", function() {
    this.setAttribute("data-heading", this.innerText);
});
Download Snippet