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.
mixin cuboid()
.cuboid(class!=attributes.class)
- let s = 0
while s < 6
.cuboid__side
- s++
.scene
.printer
.printer__side.printer__side--left
+cuboid()(class="cuboid--side")
.printer__side.printer__side--right
.cuboid.cuboid--side
.cuboid__side
.cuboid__side
.cuboid__side
.cuboid__side
.light.progress-light
.light.standby-light
button.print-button
.button
+cuboid()(class="cuboid--button")
.cuboid__side
.cuboid__side
.printer__tray.printer__tray--bottom
+cuboid()(class="cuboid--tray")
.printer__tray.printer__tray--top
+cuboid()(class="cuboid--tray")
.printer__top
.cuboid.cuboid--top
.cuboid__side
.cuboid__side
.cuboid__side
.cuboid__side
.screen
.screen__preview
.screen__previews
img(src="https://assets.codepen.io/605876/css-tricks-icon.svg")
img(src="https://assets.codepen.io/605876/sitepoint-icon.svg")
img(src="https://assets.codepen.io/605876/smashing-icon.svg")
img(src="https://assets.codepen.io/605876/egghead-icon.svg")
img(src="https://assets.codepen.io/605876/codepen-icon.svg")
.cuboid__side
.cuboid__side
.printer__back
+cuboid()(class="cuboid--back")
.printed
.printed__spinner
.printed__paper
.printed__papiere
.paper-preview
.paper-preview__previews
img(src="https://assets.codepen.io/605876/css-tricks-icon.svg")
img(src="https://assets.codepen.io/605876/sitepoint-icon.svg")
img(src="https://assets.codepen.io/605876/smashing-icon.svg")
img(src="https://assets.codepen.io/605876/egghead-icon.svg")
img(src="https://assets.codepen.io/605876/codepen-icon.svg")
.printed__paper-back
.paper-stack.paper-stack--bottom
+cuboid()(class="cuboid--paper")
.paper-stack.paper-stack--top
.cuboid.cuboid--paper
.cuboid__side
.paper
.paper__flyer
.cuboid__side
.cuboid__side
.cuboid__side
.cuboid__side
.cuboid__side
.cuboid
width 100%
height 100%
position relative
// 1 is the top and go t, r, b, l, f, b
&__side:nth-of-type(1)
height calc(var(--thickness) * 1vmin)
width 100%
position absolute
top 0
transform translate(0, -50%) rotateX(90deg)
&__side:nth-of-type(2)
height 100%
width calc(var(--thickness) * 1vmin)
position absolute
top 50%
right 0
transform translate(50%, -50%) rotateY(90deg)
&__side:nth-of-type(3)
width 100%
height calc(var(--thickness) * 1vmin)
position absolute
bottom 0
transform translate(0%, 50%) rotateX(90deg)
&__side:nth-of-type(4)
height 100%
width calc(var(--thickness) * 1vmin)
position absolute
left 0
top 50%
transform translate(-50%, -50%) rotateY(90deg)
&__side:nth-of-type(5)
height 100%
width 100%
transform translate3d(0, 0, calc(var(--thickness) * 0.5vmin))
position absolute
top 0
left 0
&__side:nth-of-type(6)
height 100%
width 100%
transform translate3d(0, 0, calc(var(--thickness) * -0.5vmin)) rotateY(180deg)
position absolute
top 0
left 0
*
*:after
*:before
box-sizing border-box
transform-style preserve-3d
touch-action none
:root
--base-size 10
--depth calc(var(--base-size) * 2.25)
--height calc(var(--base-size) * 1vmin)
--width calc(var(--base-size) * 1.4vmin)
--base-hue 200
--accent-hue 35
--bg 'hsl(%s 20% 58%)' % 190
--shoot-speed 1.5
--load-speed 2
--print-speed 1
// Colors
--p-1 'hsl(%s, 50%, 94%)' % var(--base-hue)
--p-2 'hsl(%s, 50%, 90%)' % var(--base-hue)
--p-3 'hsl(%s, 50%, 84%)' % var(--base-hue)
--p-4 'hsl(%s, 50%, 80%)' % var(--base-hue)
--p-5 'hsl(%s, 50%, 76%)' % var(--base-hue)
--p-6 'hsl(%s, 50%, 72%)' % var(--base-hue)
--p-7 'hsl(%s, 50%, 68%)' % var(--base-hue)
--p-8 'hsl(%s, 50%, 20%)' % var(--base-hue)
--t-1 hsl(0, 0%, 40%)
--t-2 hsl(0, 0%, 36%)
--t-3 hsl(0, 0%, 32%)
--t-4 hsl(0, 0%, 28%)
--t-5 hsl(0, 0%, 24%)
--g-1 'hsl(%s, 40%, 94%)' % var(--base-hue)
--g-2 'hsl(%s, 40%, 90%)' % var(--base-hue)
--g-3 'hsl(%s, 40%, 86%)' % var(--base-hue)
--g-4 'hsl(%s, 40%, 80%)' % var(--base-hue)
--g-5 'hsl(%s, 40%, 96%)' % var(--base-hue)
--a-1 'hsl(%s, 70%, 65%)' % var(--accent-hue)
--a-2 'hsl(%s, 70%, 60%)' % var(--accent-hue)
--a-3 'hsl(%s, 70%, 55%)' % var(--accent-hue)
--a-4 'hsl(%s, 70%, 50%)' % var(--accent-hue)
--a-5 'hsl(%s, 70%, 45%)' % var(--accent-hue)
body
min-height 100vh
display grid
place-items center
background var(--bg)
overflow hidden
touch-action none
.light
height calc(var(--height) * 0.1)
width calc(var(--height) * 0.1)
position absolute
left 50%
top 20%
border-radius 0%
border calc(var(--height) * 0.01) solid var(--p-8)
.standby-light
background hsla(210, 80%, 80%, 1)
transform translate(-50%, 0) translate(100%, 0)
.progress-light
transform translate(-50%, 0) translate(-100%, 0)
background 'hsla(%s, 80%, 70%)' % var(--progress-hue, 103)
.scene
position fixed
top 50%
left 50%
height var(--height)
width var(--width)
// background hsla(10 80% 70% 0.25)
transform translate3d(-50%, -50%, 100vmin)
transform translate3d(-50%, -50%, 100vmin) rotateX(-24deg) rotateY(44deg) rotateX(calc(var(--rotate-x, 0) * 1deg)) rotateY(calc(var(--rotate-y, 0) * 1deg))
.printing
--progress-hue 14
.printer
height 100%
width 100%
& > *
position absolute
&__top
height 40%
width 100%
&__back
height 60%
width 50%
bottom 0
right 0
&__side
height 60%
width 100%
bottom 0
&--right
transform translate3d(0, 0, calc(var(--depth) * 0.375vmin))
&--left
transform translate3d(0, 0, calc(var(--depth) * -0.375vmin))
&__tray
height 10%
width 100%
&--bottom
bottom 0
right 50%
&--top
top 0
right 0
transform translate(52%, 0) rotate(-75deg)
.paper-stack
width 90%
bottom 0
left -10%
transform translate3d(0, 0, calc(var(--depth) * 1vmin))
&--bottom
height 10%
&--top
height 5%
bottom 10%
transform translate3d(0, 0, calc(var(--depth) * 1vmin)) rotateY(22deg)
.printed
right 55%
width calc(var(--width) * 0.9)
height calc(var(--depth) * 0.4vmin)
bottom 10%
transform translate3d(0, -1px, 0)
&__spinner
width calc(var(--width) * 0.9)
height calc(var(--depth) * 0.4vmin)
transform-origin 50% 0
&__paper
width calc(var(--width) * 0.9)
height calc(var(--depth) * 0.4vmin)
bottom 0
transform translate(0, 50%) rotateX(90deg)
clip-path inset(0 -20% 0 0)
backface-visibility hidden
&__paper-back
width calc(var(--width) * 0.9)
height calc(var(--depth) * 0.4vmin)
bottom 0
position absolute
top 0
left 0
transform translate(0, 50%) rotateX(90deg) rotateY(180deg)
backface-visibility hidden
background var(--g-2)
&__papiere
background var(--g-1)
position absolute
height 100%
width 100%
transform translate(120%, 0)
.paper-preview
height calc(var(--height) * 0.5)
width calc(var(--height) * 0.5)
position absolute
top 50%
left 50%
transform translate(-50%, -50%) rotate(90deg)
overflow hidden
&__previews
height 100%
width 100%
opacity 0
display flex
flex-direction column
animation choose 0.1s infinite steps(5)
img
height 100%
width 100%
object-fit cover
.paper-stack--top .cuboid--paper > div
&:nth-of-type(1)
background var(--g-1)
&:nth-of-type(2)
background var(--g-1)
&:nth-of-type(3)
background var(--g-4)
&:nth-of-type(4)
background var(--g-2)
&:nth-of-type(5)
background var(--g-3)
&:nth-of-type(6)
background var(--g-3)
.paper-stack--top .cuboid--paper .paper
height 100%
width 100%
background transparent
&__flyer
position absolute
height 100%
width 100%
top 0
left 0
background transparent
overflow hidden
&:after
content ''
position absolute
height 100%
width 100%
background var(--g-1)
.printing .paper-stack--top .cuboid--paper .paper
animation transfer calc(var(--load-speed) * 0.5s) ease-in-out forwards
.printing .paper-stack--top .cuboid--paper .paper__flyer
animation fly calc(var(--load-speed) * 0.5s) ease-in-out forwards
.printing .paper-stack--top .cuboid--paper .paper__flyer:after
animation feed calc(var(--load-speed) * 0.5s) calc(var(--load-speed) * 0.5s) forwards
.printing .printed
animation shoot calc(var(--shoot-speed) * 1s) calc(((var(--load-speed) * 0.75) + var(--print-speed)) * 1s) ease-out
.printing .printed__spinner
animation eject calc(var(--shoot-speed) * 1s) calc(((var(--load-speed) * 0.75) + var(--print-speed)) * 1s) ease-out
.printing .printed__papiere
animation print calc(var(--print-speed) * 1s) calc(var(--load-speed) * 0.75s) both steps(5, start), fade calc(var(--shoot-speed) * 1s) calc(((var(--load-speed) * 0.75) + var(--print-speed)) * 1s) both
.cuboid--paper
--thickness calc(var(--depth) * 0.4)
div
&:nth-of-type(1)
background var(--g-2)
&:nth-of-type(2)
background var(--g-2)
&:nth-of-type(3)
background var(--g-5)
&:nth-of-type(4)
background var(--g-3)
&:nth-of-type(5)
background var(--g-4)
&:nth-of-type(6)
background var(--g-4)
.print-button
position absolute
top 60%
left 50%
transform translate(-50%, -50%)
height 44px
width 44px
appearance none
border 0
background 0
padding 0
margin 0
outline transparent
cursor pointer
.button
height calc(var(--height) * 0.14)
width calc(var(--height) * 0.14)
position absolute
top 50%
left 50%
transform translate3d(-50%, -50%, 0)
.print-button:active .button
transform translate3d(-50%, -50%, calc(var(--height) * 0.05))
.cuboid--button
--thickness calc(var(--base-size) * 0.12)
div
&:nth-of-type(1)
background var(--a-1)
&:nth-of-type(2)
background var(--a-1)
&:nth-of-type(3)
background var(--a-4)
&:nth-of-type(4)
background var(--a-5)
&:nth-of-type(5)
background var(--a-3)
&:nth-of-type(6)
background var(--a-3)
.printing .screen__previews
.printing .paper-preview__previews
animation-play-state paused
opacity 1
.screen
height calc(var(--height) * 0.25)
width calc(var(--height) * 0.35)
left 0
top 50%
background hsl(200, 80%, 84%)
position absolute
transform translate3d(28%, -50%, -1px)
outline calc(var(--height) * 0.01) solid var(--p-8)
&__preview
height 100%
width calc(var(--height) * 0.25)
position absolute
left 50%
top 50%
transform translate(-50%, -50%) scale(0.8) rotateY(180deg) translate3d(0, 0, 1px)
overflow hidden
.screen__previews
height 100%
width 100%
opacity 0
display flex
flex-direction column
animation choose 0.1s infinite steps(5, end)
img
height 100%
width 100%
@keyframes choose
to
transform translate(0, -500%)
.cuboid--top
--thickness var(--depth)
& > div
&:nth-of-type(1)
background linear-gradient(hsl(0, 0%, 0%), hsl(0, 0%, 0%)) 100% 50% / 14% 54% no-repeat,
linear-gradient(var(--p-7), var(--p-7)) 40% 50% / 12% 32% no-repeat,
linear-gradient(var(--p-7), var(--p-7)) 30% 50% / 2% 12% no-repeat,
linear-gradient(var(--p-3), var(--p-3)) 0% 50% / 66% 50% no-repeat
background-color var(--p-1)
&:after
content ''
position absolute
top 7%
left 10%
height calc(var(--depth) * 0.12vmin)
width calc(var(--depth) * 0.12vmin)
background url(https://assets.codepen.io/605876/avatar.png)
background-size cover
transform rotate(90deg)
filter grayscale(0.5)
&:nth-of-type(2)
background var(--p-1)
&:nth-of-type(3)
background var(--p-8)
&:nth-of-type(4)
background linear-gradient(var(--p-4), var(--p-4)) 50% 0% / 50% 100% no-repeat
background-color var(--p-2)
&:after
content ''
position absolute
top 25%
left 50%
height 15%
width 10%
border-radius 25%
background var(--p-6)
transform translate3d(-50%, -50%, -1px)
&:nth-of-type(5)
background var(--p-3)
&:nth-of-type(6)
background var(--p-3)
.cuboid--back
--thickness calc(var(--depth) * 0.5)
div
&:nth-of-type(1)
background var(--p-1)
&:nth-of-type(2)
background var(--t-1)
&:nth-of-type(3)
background var(--p-2)
&:nth-of-type(4)
background var(--t-5)
&:nth-of-type(5)
background var(--p-3)
&:nth-of-type(6)
background var(--p-3)
.printer__tray--top .cuboid--tray div:nth-of-type(1)
background linear-gradient(var(--t-2), var(--t-2)) 90% 50% / 5% 50% no-repeat
background-color var(--t-1)
.cuboid--tray
--thickness calc(var(--depth) * 0.5)
div
&:nth-of-type(1)
background linear-gradient(var(--t-2), var(--t-2)) 10% 50% / 5% 50% no-repeat
background-color var(--t-1)
&:nth-of-type(2)
background var(--t-1)
&:nth-of-type(3)
background var(--t-2)
&:nth-of-type(4)
background var(--t-2)
&:nth-of-type(5)
background var(--t-3)
&:nth-of-type(6)
background var(--t-3)
.cuboid--side
--thickness calc(var(--depth) * 0.25)
& > div
&:nth-of-type(1)
background var(--p-1)
&:nth-of-type(2)
background var(--p-1)
&:nth-of-type(3)
background var(--p-2)
&:nth-of-type(4)
background var(--p-2)
&:nth-of-type(5)
background repeating-linear-gradient(var(--t-4) 0 25%, transparent 25% 50%) 90% 70% / 30% 20% no-repeat
background-color var(--p-3)
&:nth-of-type(6)
background repeating-linear-gradient(var(--t-4) 0 25%, transparent 25% 50%) 90% 70% / 30% 25% no-repeat
background-color var(--p-3)
.printer__side--left > .cuboid > div:nth-of-type(5)
.printer__side--right > .cuboid > div:nth-of-type(6)
background var(--p-8)
@keyframes fade
0%, 80%
opacity 1
100%
opacity 0
@keyframes shoot
0%
transform translate3d(0%, -1px, 0)
100%
transform translate3d(-300%, -1px, 0)
@keyframes eject
15%
transform rotate(0deg)
65%, 100%
transform rotate(360deg)
@keyframes transfer
to
transform translate(0, -270%) rotate(22deg)
@keyframes feed
to
transform translate(100%, 0)
@keyframes fly
0%
transform translate3d(0, 0, 0) rotateY(0deg) translate(0, 0)
50%
transform translate3d(140%, 0, calc(var(--height) * 1.2)) rotateY(-75deg) translate(180%, 0)
100%
transform translate3d(140%, 0, var(--height)) rotateY(-75deg) translate(0%, 0) rotate(-180deg)
@keyframes print
to
transform translate(0, 0)
import gsap from 'https://cdn.skypack.dev/gsap'
const PRINTER = document.querySelector('.printer')
const AUDIO = new Audio('https://assets.codepen.io/605876/print.mp3')
const BOUNDS = 30
const UPDATE = ({ x, y }) => {
const newX = gsap.utils.mapRange(0, window.innerWidth, -BOUNDS, BOUNDS, x)
const newY = gsap.utils.mapRange(0, window.innerHeight, BOUNDS, -BOUNDS, y)
gsap.set(document.documentElement, {
'--rotate-x': newY,
'--rotate-y': newX,
})
}
document.addEventListener('pointermove', UPDATE)
let printing = false
const BUTTON = document.querySelector('.print-button')
BUTTON.addEventListener('click', e => {
if (printing) return
printing = true
setTimeout(() => AUDIO.play(), 1000)
PRINTER.classList.add('printing')
setTimeout(() => {
printing = false
PRINTER.classList.remove('printing')
}, 4500)
})
// // Purely for debugging purposes
// import { GUI } from 'https://cdn.skypack.dev/dat.gui'
// const CONTROLLER = new GUI()
// const CONFIG = {
// 'rotate-x': -360,
// 'rotate-y': -360,
// }
// const UPDATE = () => {
// Object.entries(CONFIG).forEach(([key, value]) => {
// document.documentElement.style.setProperty(`--${key}`, value)
// })
// }
// const PLANE_FOLDER = CONTROLLER.addFolder('Plane')
// PLANE_FOLDER.add(CONFIG, 'rotate-x', -360, 360, 1)
// .name('Rotate X (deg)')
// .onChange(UPDATE)
// PLANE_FOLDER.add(CONFIG, 'rotate-y', -360, 360, 1)
// .name('Rotate Y (deg)')
// .onChange(UPDATE)
// UPDATE()
Also see: Tab Triggers