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.
<!-- fake body -->
<body class="overflow-x-hidden font-semibold text-white text-5xl" style="font-family:'Open Sans';">
<!-- fake body -->
<!-- section a: blank -->
<section class="bg-red-600 min-h-screen flex items-center justify-center">A</section>
<!-- section b: animate b simple -->
<section class="bg-blue-600 min-h-screen flex items-center justify-center relative st--section-b">
<div class="absolute left-0 top-0 h-[30px] w-[30px] bg-white flex items-center justify-center st--block-b text-xl text-black">B</div>
</section>
<!-- horizontal scolling -->
<section class="bg-yellow-600 min-h-screen w-[500%] flex flex-no-wrap st--horizontal">
<!-- section c1: yeah up + down -->
<div class="w-screen bg-purple-900 min-h-screen relative flex justify-center st--section-c1">
<div class="h-1/2 w-1/4 flex items-center justify-center bg-black st--piston-odd">Y</div>
<div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-white text-black st--piston-even">E</div>
<div class="h-1/2 w-1/4 flex items-center justify-center bg-black st--piston-odd">A</div>
<div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-white text-black st--piston-even">H</div>
</div>
<!-- section c2: pattern down -->
<div class="w-screen bg-purple-800 min-h-screen flex items-center justify-center relative st--section-c2">
<img src="https://kubikdesign.com.au/codepen/pattern.svg" class="st--pattern w-full absolute z-1 bottom-0 left-0">
<div class="leading-none text-8xl">HELL<br>YEAH</div>
</div>
<!-- section c3: moving block around corners -->
<div class="w-screen bg-purple-700 min-h-screen relative st--section-c3">
<div class="absolute left-0 bottom-0 z-10 h-[150px] w-[150px] rounded-full bg-red-600 flex items-center justify-center text-xl text-white st--block-c3">3</div>
</div>
<!-- section c4: bg color change -->
<div class="w-screen bg-black min-h-screen flex items-center justify-center relative st--section-c4">
<img src="https://kubikdesign.com.au/codepen/bg-letters.svg" class="absolute inset-0 z-0 w-full h-full object-contain st--block-c4">
</div>
<!-- blank -->
<div class="w-screen bg-purple-500 min-h-screen flex items-center justify-center">5</div>
<!-- end -->
</section>
<!-- end: horizontal scolling -->
<!-- blank sections -->
<section class="bg-pink-600 min-h-screen flex items-center justify-center">D</section>
<section class="bg-green-600 min-h-screen flex items-center justify-center">E</section>
<!-- fake body -->
</body>
// function: generate random color
function randomColor() {
var m = new Array()
for (var i = 0; i < 80; i++) {
m.push(
'#' +
Math.floor(Math.random() * 10) +
Math.floor(Math.random() * 10) +
Math.floor(Math.random() * 10)
) // to construct a color arrary.
}
return m
}
// function: generate random linear gradient
function createHex() {
var hexCode1 = ''
var hexValues1 = '0123456789abcdef'
for (var i = 0; i < 6; i++) {
hexCode1 += hexValues1.charAt(
Math.floor(Math.random() * hexValues1.length)
)
}
return hexCode1
}
function generate() {
var deg = Math.floor(Math.random() * 360)
var gradient =
'linear-gradient(' +
deg +
'deg, ' +
'#' +
createHex() +
', ' +
'#' +
createHex() +
')'
return gradient
}
// register scrollTrigger
gsap.registerPlugin(ScrollTrigger)
// horizontal scrolling
let sections = gsap.utils.toArray('.st--horizontal > div')
let scrollTween = gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: 'none',
scrollTrigger: {
trigger: '.st--horizontal',
pin: true,
scrub: 1,
// snap: 1 / (sections.length - 1),
// base vertical scrolling on how wide the container is so it feels more natural
end: () => '+=' + document.querySelector('.st--horizontal').offsetWidth,
},
})
// animate block b simple
gsap.to('.st--block-b', {
// x: document.querySelector('.st--section-b').offsetWidth,
y: () => document.querySelector('.st--section-b').offsetHeight,
rotation: 360,
ease: 'none',
scrollTrigger: {
trigger: '.st--section-b',
start: 'top top', // when the top of the trigger hits the top of the viewport
end: 'bottom top',
scrub: true, // use value for a delayed effect
},
})
// https://greensock.com/forums/topic/35004-gsap3-scrolltrigger-scrub-enabled-move-element-up-and-then-down/
gsap.to('.st--piston-even, .st--piston-odd', {
// odd goes -100%, even goes 100%
y: i => (i % 2 ? '-100%' : '100%'),
ease: 'none',
yoyo: true,
repeat: 2,
scrollTrigger: {
trigger: '.st--section-c1',
containerAnimation: scrollTween,
start: 'left left',
scrub: true,
},
})
// section c2: pattern overlay down
gsap.to('.st--pattern', {
// v1
yPercent: 50,
ease: 'none',
scrollTrigger: {
trigger: '.st--section-c2',
containerAnimation: scrollTween,
// start: 'left left',
start: () =>
'-=' +
document.querySelector('.st--section-c2').offsetWidth +
' left',
end: () =>
'+=' + document.querySelector('.st--section-c2').offsetWidth * 2,
scrub: true,
},
})
// section c3: moving colour changing block
var tl = gsap.timeline({
scrollTrigger: {
trigger: '.st--section-c3',
containerAnimation: scrollTween,
scrub: true,
start: () =>
'-=' +
document.querySelector('.st--section-c3').offsetWidth / 2 +
' left',
end: () => '+=' + document.querySelector('.st--section-c3').offsetWidth,
},
})
// section c3: moving block
tl.to('.st--block-c3', {
ease: 'none',
y: () =>
-document.querySelector('.st--section-c3').offsetHeight +
document.querySelector('.st--block-c3').offsetHeight,
})
.to('.st--block-c3', {
ease: 'none',
x: () =>
document.querySelector('.st--section-c3').offsetWidth -
document.querySelector('.st--block-c3').offsetWidth,
})
.to('.st--block-c3', {
ease: 'none',
y: () => 0,
})
.to('.st--block-c3', {
ease: 'none',
x: () =>
document.querySelector('.st--section-c3').offsetWidth * 0.5 -
document.querySelector('.st--block-c3').offsetWidth,
})
// section c3: changing block colour
var tlColor = gsap.timeline({
scrollTrigger: {
trigger: '.st--section-c3',
containerAnimation: scrollTween,
scrub: true,
start: () =>
'-=' +
document.querySelector('.st--section-c3').offsetWidth / 2 +
' left',
end: () => '+=' + document.querySelector('.st--section-c3').offsetWidth,
},
})
tlColor
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
.to('.st--block-c3', {
ease: 'none',
backgroundColor: randomColor,
})
// section c4: background image colour change
var tlBackgroundColor = gsap.timeline({
scrollTrigger: {
trigger: '.st--section-c4',
containerAnimation: scrollTween,
scrub: true,
// markers: true,
// start: 'left left',
start: () =>
'-=' +
document.querySelector('.st--section-c4').offsetWidth +
' left',
end: () =>
'+=' + document.querySelector('.st--section-c4').offsetWidth * 2,
},
})
tlBackgroundColor
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
.to('.st--block-c4', {
ease: 'none',
backgroundImage: generate,
})
Also see: Tab Triggers