How-to Create Split Text

Create split, fractured text using CSS and JavaScript.

CSS | JavaScript

How-to Create Split Text

Learn how-to create split, fractured text using CSS and JavaScript.

HTML

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

CSS

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

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);
});