HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
- var word = 'pendeveloper'
- var colorSplit = 3
each val in ['random', 'enter', 'swap', 'fade', 'flip', 'slide', 'scale', 'turn', 'fold', 'bulge', 'far', 'teeth']
.cascading-text(data-animated, class=`cascading-text--${val}`)
.cascading-text__replay replay?
each val, index in word.split('')
if index < colorSplit
.cascading-text__letter.tx--white= val
else
.cascading-text__letter.tx--red= val
$travel = 50px
$fontSize = 25px
$wordLength = 13
$animationDuration = .5s
$animationInterval = .1s
.cascading-text
position relative
&__replay
line-height $fontSize
font-size 12px
color #ffffff
cursor pointer
position absolute
top 50%
left 50%
transform translateX(-50%)
animation fadeIn .75s
padding 5px
opacity 0.5
transition transform .25s
&:hover
opacity 1 !important
transform translateX(-50%) translateY(-10%)
&[data-animated] .cascading-text__replay
display none
/**
* [data-animated] is merely used as a trigger
* attribute for replay purposes. If you were going
* to use cascading text effects on a site, just let
* them play once on entry
*/
&--enter[data-animated]
.cascading-text__letter
opacity 0
transform translateY($travel * -1)
animation-name enter
&--fade[data-animated]
.cascading-text__letter
opacity 0
animation-name fade
&--flip[data-animated]
.cascading-text__letter
transform rotateY(180deg)
animation-name flip
&--scale[data-animated]
.cascading-text__letter
transform scale(0)
animation-name scale
&--turn[data-animated]
.cascading-text__letter
transform-origin bottom
transform rotateY(90deg)
animation-name turn
&--fold[data-animated]
.cascading-text__letter
transform-origin bottom
transform rotateX(90deg)
animation-name fold
&--bulge[data-animated]
.cascading-text__letter
animation-name bulge
&--swap[data-animated]
.cascading-text__letter
for $i in (1..$wordLength)
&:nth-of-type({$i})
if ($i % 2 eq 0)
transform translateX(-15px)
animation-name swap-right
else
transform translateX(15px)
animation-name swap-left
&--slide[data-animated]
.cascading-text__letter
animation-name slide
opacity 0
transform translateX($travel * -1px)
for $i in (1..$wordLength)
&:nth-of-type({$i})
animation-delay $animationInterval * ($wordLength - $i)
&--far[data-animated]
perspective 1000px
.cascading-text__letter
opacity 0
transform translateX(-25px) translateY(-20px) translateZ(-800px)
animation-name far
&--teeth[data-animated]
.cascading-text__letter
opacity 0
for $i in (1..$wordLength)
&:nth-of-type({$i})
if ($i % 2 eq 0)
transform translateY(-100%)
animation-name enter
else
transform translateY(100%)
animation-name enter-bottom
&--random[data-animated]
random()
return floor(math(0, 'random')*(250 - 25 + 1) + 25)
.cascading-text__letter
for $i in (1..$wordLength)
animation-name random
&:nth-of-type({$i})
$x = random()
$y = random()
if ($x % 2 eq 1)
$x = $x * -1
if ($y % 2 eq 1)
$y = $y * -1
transform translateX($x * 1%) translateY($y * 1%)
&__letter
font-size $fontSize
line-height $fontSize
display inline-block
transform-style preserve-3d
for $i in (1..$wordLength)
&:nth-of-type({$i})
animation-delay $animationInterval * $i
animation-duration $animationDuration
animation-fill-mode forwards
@keyframes enter
0%
opacity 0
transform translateY($travel * -1)
25%
opacity 1
100%
opacity 1
transform translateY(0px)
@keyframes enter-bottom
0%
opacity 0
transform translateY($travel)
25%
opacity 1
100%
opacity 1
transform translateY(0px)
@keyframes fade
from
opacity 0
to
opacity 1
@keyframes flip
from
transform rotateY(180deg)
to
transform rotateY(0deg)
@keyframes slide
0%
opacity 0
transform translateX($travel * -1px)
25%
opacity 1
100%
opacity 1
transform translateX(0)
@keyframes scale
from
transform scale(0)
to
transform scale(1)
@keyframes fadeIn
from
opacity 0
to
opacity .5
@keyframes turn
to
transform rotateY(0)
@keyframes fold
to
transform rotateX(0)
@keyframes bulge
25%
transform scale(1.5)
@keyframes swap-right
25%
transform translateX(-15px) translateY(-100%)
75%
transform translateX(0) translateY(-100%)
100%
transform translateX(0) translateY(0)
@keyframes swap-left
25%
transform translateX(15px) translateY(100%)
75%
transform translateX(0) translateY(100%)
100%
transform translateX(0) translateY(0)
@keyframes far
25%
opacity 1
100%
opacity 1
transform translateY(0) translateZ(0) translateX(0)
@keyframes random
25%
opacity 1
100%
opacity 1
transform translateX(0) translateY(0)
/**
* Theme
*/
*
box-sizing border-box
body
background #111111
width 100vw
.cascading-text
line-height 150px
text-align center
@media(min-width 768px)
width 50%
display inline-block
float left
@media(min-width 992px)
width 25%
.tx--red
color #e74c3c
.tx--white
color #ffffff
/**
* JS purely used for implementing replay feature
*/
const PROPS = {
CONTAINER: 'cascading-text',
LETTER : 'cascading-text__letter',
ANIMATED : 'data-animated',
REPLAY : 'cascading-text__replay',
}
const texts = document.querySelectorAll(`.${PROPS.CONTAINER}`)
const replays = document.querySelectorAll(`.${PROPS.REPLAY}`)
for (const replay of replays) {
replay.addEventListener('click', () => {
const text = replay.parentElement
const letters = text.querySelectorAll(`.${PROPS.LETTER}`)
const listeners = []
for (const letter of letters) {
const listener = new Promise((resolve, reject) => {
letter.addEventListener('animationend', () => resolve())
})
listeners.push(listener)
}
Promise.all(listeners)
.then(() => {
text.removeAttribute(PROPS.ANIMATED)
})
text.setAttribute(PROPS.ANIMATED, true)
})
}
const textListeners = []
for (const text of texts) {
const letters = text.querySelectorAll(`.${PROPS.LETTER}`)
const listeners = []
for (const letter of letters) {
const listener = new Promise((resolve, reject) => {
letter.addEventListener('animationend', () => {
resolve()
})
})
listeners.push(listener)
}
const textListener = Promise.all(listeners)
.then(() => {
Promise.resolve()
})
textListeners.push(textListener)
}
Promise.all(textListeners)
.then(() => {
for (const text of texts) {
text.removeAttribute(PROPS.ANIMATED)
}
})
Also see: Tab Triggers