Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="text-container"> Awesome</div>
              
            
!

CSS

              
                $prime: #ff6e48;
$ciBlue: #00fff1;
$ciRed: #ff00aa;
$ciWhite: #ffffff;
$ciGreen: #46fcb4;
$ciSecond: #0c1016;

$roboto: "Roboto";

@font-face {
	font-family: $roboto;
	src: url("https://assets.codepen.io/907368/Roboto-Bold.ttf");
	font-weight: 700;
}

@font-face {
	font-family: $roboto;
	src: url("https://assets.codepen.io/907368/Roboto-Regular.ttf");
	font-weight: 500;
}

@font-face {
	font-family: $roboto;
	src: url("https://assets.codepen.io/907368/Roboto-Light.ttf");
	font-weight: 300;
}

body,
html {
	width: 100%;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	background-color: $ciSecond;
	font-size: 20px;
	margin: 0;
	padding: 0;
	color: $ciWhite;
	font-family: $roboto;
	overflow-x: hidden;
}

* {
	box-sizing: border-box;
}

.text-container {
	font-size: 5rem;
	font-weight: 700;
	display: flex;
	flex-direction: row;
	.letter {
		position: relative;
		display: flex;
		text-transform: uppercase;
		cursor: default;
		min-width: 2rem;
		.letter-front {
			position: relative;
			z-index: 2;
			color: rgba($prime, 1);
			transition: all 350ms ease-in-out;
			transform: rotateY(0deg) skew(0, 0);
		}
		.letter-background {
			position: absolute;
			top: 0;
			z-index: 1;
			left: 0;
			color: rgba($prime, 0.1);
		}
		&.active {
			.letter-front {
				transform: translate(0, -1.2rem);
				text-shadow: 0rem 0.2rem 2rem black;
			}
		}
		&.active-after {
			.letter-front {
				transform-origin: right bottom;
				transform: rotateY(-25deg) skew(0, 20deg);
				text-shadow: 0rem 0.2rem 2rem black;
			}
		}
		&.active-before {
			.letter-front {
				transform-origin: left bottom;
				transform: rotateY(25deg) skew(0, -20deg);
				text-shadow: 0rem 0.2rem 2rem black;
			}
		}
	}
}

              
            
!

JS

              
                const textContainers = document.querySelectorAll(".text-container");

// Loop through all text containers
textContainers.forEach((container) => {
	// Get a array of letters from the text
	const textArray = getLetterArray(container);

	// Clear the text from the container
	container.textContent = "";

	// Loop through the array of letters
	textArray.forEach((letter) => {
		// Create a div for each letter
		const letterBox = document.createElement("div");
		letterBox.classList.add("letter");

		// Add mouse events to the letter div
		addMouseEvents(letterBox);

		// Create a span for the letter and add it to the letter div
		letterBox.appendChild(createSpan(letter, "letter-front"));
		letterBox.appendChild(createSpan(letter, "letter-background"));

		// Add the letter div to the text container
		container.appendChild(letterBox);
	});
});

/**
 * Get an array of letters from the text
 * @param {HTMLElement} element
 */
function getLetterArray(element) {
	const text = element.textContent.trim();
	return text.split("");
}

/**
 * Add mouse events to the letter div
 * @param {HTMLElement} element
 * @param {string} className
 */
function addMouseEvents(element) {
	element.addEventListener("mouseenter", ($event) => animateLetters($event));
	element.addEventListener("mouseleave", ($event) => animateLetters($event));
}

/**
 * Create a span for the letter
 * @param {string} letter
 * @param {string} className
 */
function createSpan(letter, className) {
	const span = document.createElement("span");
	span.classList.add(className);
	span.textContent = letter;
	return span;
}

/**
 * Animate the letters when hovering over them
 * @param {MouseEvent} $event
 */
function animateLetters($event) {
	if ($event.target.previousSibling) {
		$event.target.previousSibling.classList.toggle("active-before");
	}
	$event.target.classList.toggle("active");
	if ($event.target.nextSibling) {
		$event.target.nextSibling.classList.toggle("active-after");
	}
}

              
            
!
999px

Console