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.
//- BUILDING BLOX -----------------------------
mixin box(className, attr)
.box(class=className data-name=className)&attributes(attributes)= attr
- const faces = ['front','back','left','right','top','bottom']
each face in faces
div(class='face face__' + face)
block
mixin scene(className)
.scene(class=className data-name=className)
block
//- SCENE ELEMENTS ----------------------------
mixin floor(className)
.box.floor(class=className)
block
.face__front
.face__right
.face__top
mixin window(className)
+scene("window")
+box("main-frame")(class="transparent")
+box("frame__top")
+box("frame__right")
+box("frame__left")
+box("frame__bottom")
+box("frame__cross--x")
+box("frame__cross--y")
.box.glass
.face__front
mixin building
+scene("building")
.box(class="walls")
//- just the two facing walls
.face__top
.face__front
//- 15 windows on the front side
- for(let i = 0; i<15; i++)
.cell
+window(i)
.face__right
//- 10 windows on the right side
- for(let i = 0; i<10; i++)
.cell
+window(i)
+scene("floors")
//- 5 floors
- for(let i = 0; i<5; i++)
+floor("floor-" + i)
//- 1 roof
+floor("roof")
.box.crow
.face__front
.stage-wrapper
.stage
+building()
:root
--factor 0.5vmin
--sky #190034
--wall-base cornflowerblue
--wall-light cornflowerblue
--wall-dark #87c5ad
--wall-darker #161a42
--light-source #ffcd00
body
background-color var(--sky)
background-image radial-gradient(circle, rgba(255,255,255,1) 0vmin, rgba(255,255,255,1) 15vmin, rgba(255,255,255,0.2) 15vmin, rgba(255,255,255,0) 20vmin), radial-gradient(circle, rgba(255,255,255,1) 0vmin, rgba(255,255,255,1) 15vmin, rgba(255,255,255,0.2) 15vmin, rgba(255,255,255,0) 100vmin)
background-repeat no-repeat
background-position 100% 100%
background-size 200% 200%
.stage-wrapper
min-height 100%
display flex
align-items center
justify-content center
//overflow hidden
//===============================================
.building.scene
--z -5
--walls-height 250
--walls-width 150
--walls-depth 100
--height var(--walls-height)
--width var(--walls-width)
--depth var(--walls-depth)
--color-light var(--wall-dark)
--color-base var(--wall-light)
--color-dark var(--wall-light)
--color-darker var(--wall-darker)
.walls
& > .face__front
display grid
grid-template-columns repeat(3, 1fr)
grid-template-rows repeat(5, 1fr)
&::before
content ""
position absolute
width 100%
height 100%
top 0
left 0
// background-image radial-gradient(circle, rgba(255,200,0,1) 0%, rgba(255,200,0,0) 100%)
background-position 60% 0
background-size 200% 200%
background-repeat no-repeat
& > .face__right
display grid
grid-template-columns repeat(2, 1fr)
grid-template-rows repeat(5, 1fr)
background-color var(--wall-darker)
--color-base var(--wall-darker)
--color-top var(--wall-dark)
.cell
display flex
justify-content center
align-items center
.window
--rotate-x 90
--z 2
.floors
--z calc(var(--walls-height) / -2)
--color-base var(--wall-darker)
--roof-width calc(var(--walls-width) + 3)
--roof-height 5
--roof-depth calc(var(--walls-depth) + 3)
--width var(--roof-width)
--height var(--roof-height)
--depth var(--roof-depth)
.floor
--z calc(var(--height) / -2)
.face__top
// background-image linear-gradient(40deg, var(--wall-light) 50%, var(--wall-dark) 50%)
&:nth-child(2)
--z 45
&:nth-child(3)
--z 95
&:nth-child(4)
--z 145
&:nth-child(5)
--z 195
.roof
--z var(--walls-height)
.crow
--width 10
--height 10
--depth 0
--x calc(var(--roof-width) - var(--width))
--y var(--roof-depth)
--z 8
.face__front
background-color transparent
background-repeat no-repeat
background-size 100%
background-position 100% 100%
background-image embedurl(spider='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M544 32L527.6 32C513 12.63 490.1 0 464 0C419.9 0 384 35.88 384 80v21L12.12 393.6c-7.625 5.625-12.12 14.62-12.12 24.12c0 22.5 23.62 37 43.75 27l121.5-60.76l96.5 .0054l44.38 120.1c2.375 6.25 9.25 9.375 15.38 7.125l22.62-8.25c6.25-2.25 9.375-9.125 7.125-15.38L313 384L352 384c1.875 0 3.75-.2513 5.625-.2513l44.5 120.4c2.375 6.25 9.25 9.375 15.38 7.125l22.62-8.25c6.25-2.25 9.375-9.125 7.125-15.38l-41.24-111.5C485.8 352.8 544 279.3 544 192V112l96-16C640 60.63 597 32 544 32zM464 104c-13.25 0-24-10.75-24-24s10.75-24 24-24s24 10.75 24 24S477.2 104 464 104z"></path></svg>')
.window.scene
--box-height 25
--box-width 20
--box-depth 8
--width var(--box-width)
--depth var(--box-depth)
.face__bottom
background none // not visible ...
.main-frame
--height var(--box-height)
--width var(--box-width)
--depth var(--box-depth)
--y calc(var(--box-depth)/2 - var(--depth) / 2)
--x calc(var(--box-width)/2 - var(--width) / 2)
.frame__top
--height 2
--depth 4
--z calc(var(--box-height) / 2 + var(--height) / 2)
.frame__left
--width 2
--depth 4
--z calc(var(--box-height) / -2 + var(--height) / 2)
.frame__right
--width 2
--depth 4
--x calc(var(--box-width) - var(--width))
.frame__bottom
--height 1
--z calc(var(--box-height) / -2 - var(--height) / 2)
.frame__cross--x
--height 1
--width 16
--depth 2
--x calc(var(--box-width)/2 - var(--width) / 2)
--y 1
--z 3
.frame__cross--y
--width 1
--depth 2
--x calc(var(--box-width)/2 - var(--width) / 2)
--y 1
.glass
--width 16
--depth 1
--x 2
--y 1.1
--color-front var(--sky)
.face__front
background-repeat no-repeat
background-position bottom
background-size calc(10*var(--unit))
&:hover .glass
--color-front var(--light-source)
.cell:nth-child(1) .glass .face__front
background-size calc(6*var(--unit))
background-position 85% 65%
background-image embedurl(spider='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M563.3 401.6c2.608 8.443-2.149 17.4-10.62 19.1l-15.35 4.709c-8.48 2.6-17.47-2.139-20.08-10.59L493.2 338l-79.79-31.8l53.47 62.15c5.08 5.904 6.972 13.89 5.08 21.44l-28.23 110.1c-2.151 8.57-10.87 13.78-19.47 11.64l-15.58-3.873c-8.609-2.141-13.84-10.83-11.69-19.4l25.2-98.02l-38.51-44.77c.1529 2.205 .6627 4.307 .6627 6.549c0 53.02-43.15 96-96.37 96S191.6 405 191.6 352c0-2.242 .5117-4.34 .6627-6.543l-38.51 44.76l25.2 98.02c2.151 8.574-3.084 17.26-11.69 19.4l-15.58 3.873c-8.603 2.141-17.32-3.072-19.47-11.64l-28.23-110.1c-1.894-7.543 0-15.53 5.08-21.44l53.47-62.15l-79.79 31.8l-24.01 77.74c-2.608 8.447-11.6 13.19-20.08 10.59l-15.35-4.709c-8.478-2.6-13.23-11.55-10.63-19.1l27.4-88.69c2.143-6.939 7.323-12.54 14.09-15.24L158.9 256l-104.7-41.73C47.43 211.6 42.26 205.1 40.11 199.1L12.72 110.4c-2.608-8.443 2.149-17.4 10.62-19.1l15.35-4.709c8.48-2.6 17.47 2.139 20.08 10.59l24.01 77.74l79.79 31.8L109.1 143.6C104 137.7 102.1 129.7 104 122.2l28.23-110.1c2.151-8.57 10.87-13.78 19.47-11.64l15.58 3.873C175.9 6.494 181.1 15.18 178.1 23.76L153.8 121.8L207.7 184.4l.1542-24.44C206.1 123.4 228.9 91.77 261.4 80.43c5.141-1.793 10.5 2.215 10.5 7.641V112h32.12V88.09c0-5.443 5.394-9.443 10.55-7.641C345.9 91.39 368.3 121 368.3 155.9c0 1.393-.1786 2.689-.2492 4.064L368.3 184.4l53.91-62.66l-25.2-98.02c-2.151-8.574 3.084-17.26 11.69-19.4l15.58-3.873c8.603-2.141 17.32 3.072 19.47 11.64l28.23 110.1c1.894 7.543 0 15.53-5.08 21.44l-53.47 62.15l79.79-31.8l24.01-77.74c2.608-8.447 11.6-13.19 20.08-10.59l15.35 4.709c8.478 2.6 13.23 11.55 10.63 19.1l-27.4 88.69c-2.143 6.939-7.323 12.54-14.09 15.24L417.1 256l104.7 41.73c6.754 2.691 11.92 8.283 14.07 15.21L563.3 401.6z"></path></svg>')
.cell:nth-child(5) .glass .face__front
background-position 61% 100%
background-image embedurl(cat='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" viewBox="0 0 576 512"><path fill="currentColor" d="M322.6 192C302.4 192 215.8 194 160 278V192c0-53-43-96-96-96C46.38 96 32 110.4 32 128s14.38 32 32 32s32 14.38 32 32v256c0 35.25 28.75 64 64 64h176c8.875 0 16-7.125 16-15.1V480c0-17.62-14.38-32-32-32h-32l128-96v144c0 8.875 7.125 16 16 16h32c8.875 0 16-7.125 16-16V289.9c-10.25 2.625-20.88 4.5-32 4.5C386.2 294.4 334.5 250.4 322.6 192zM480 96h-64l-64-64v134.4c0 53 43 95.1 96 95.1s96-42.1 96-95.1V32L480 96zM408 176c-8.875 0-16-7.125-16-16s7.125-16 16-16s16 7.125 16 16S416.9 176 408 176zM488 176c-8.875 0-16-7.125-16-16s7.125-16 16-16s16 7.125 16 16S496.9 176 488 176z" /></svg>')
.cell:nth-child(8) .glass .face__front
// background-position 61% 100%
background-size calc(12*var(--unit))
background-image embedurl(astronaut='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M176 448C167.3 448 160 455.3 160 464V512h32v-48C192 455.3 184.8 448 176 448zM272 448c-8.75 0-16 7.25-16 16s7.25 16 16 16s16-7.25 16-16S280.8 448 272 448zM164 172l8.205 24.62c1.215 3.645 6.375 3.645 7.59 0L188 172l24.62-8.203c3.646-1.219 3.646-6.375 0-7.594L188 148L179.8 123.4c-1.215-3.648-6.375-3.648-7.59 0L164 148L139.4 156.2c-3.646 1.219-3.646 6.375 0 7.594L164 172zM336.1 315.4C304 338.6 265.1 352 224 352s-80.03-13.43-112.1-36.59C46.55 340.2 0 403.3 0 477.3C0 496.5 15.52 512 34.66 512H128v-64c0-17.75 14.25-32 32-32h128c17.75 0 32 14.25 32 32v64h93.34C432.5 512 448 496.5 448 477.3C448 403.3 401.5 340.2 336.1 315.4zM64 224h13.5C102.3 280.5 158.4 320 224 320s121.8-39.5 146.5-96H384c8.75 0 16-7.25 16-16v-96C400 103.3 392.8 96 384 96h-13.5C345.8 39.5 289.6 0 224 0S102.3 39.5 77.5 96H64C55.25 96 48 103.3 48 112v96C48 216.8 55.25 224 64 224zM104 136C104 113.9 125.5 96 152 96h144c26.5 0 48 17.88 48 40V160c0 53-43 96-96 96h-48c-53 0-96-43-96-96V136z"></path></svg>')
.cell:nth-child(7) .glass .face__front
background-position 15% 100%
background-size calc(5*var(--unit))
background-image embedurl(plant='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M568.3 192c-29 .125-135 6.124-213.9 82.1C321.2 304.7 301 338.3 288 369.9c-13-31.63-33.25-65.25-66.38-94.87C142.8 198.2 36.75 192.2 7.75 192C3.375 192 0 195.4 0 199.9c.25 27.88 7.125 126.2 88.75 199.3C172.8 481 256 479.1 288 479.1s115.2 1.025 199.3-80.85C568.9 326 575.8 227.7 576 199.9C576 195.4 572.6 192 568.3 192zM288 302.6c12.75-18.87 27.62-35.75 44.13-50.5c19-18.62 39.5-33.37 60.25-45.25c-16.5-70.5-51.75-133-96.75-172.3c-4.125-3.5-11-3.5-15.12 0c-45 39.25-80.25 101.6-96.75 172.1c20.37 11.75 40.5 26.12 59.25 44.37C260 266.4 275.1 283.7 288 302.6z"></path></svg>')
.cell:nth-child(3) .glass .face__front
background-position 95% 0%
background-size calc(8*var(--unit))
background-image embedurl(crack='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M511.4 37.87l-87.54 467.6c-1.625 8.623-14.04 8.634-15.67 .0104L341.4 141.7L295.7 314.2c-2.375 7.624-12.98 7.624-15.36 0L246.3 180.9l-46.49 196.9c-1.875 8.373-13.64 8.373-15.51 0L139.1 190.5L103.6 314.5c-2.375 7.124-12.64 7.198-15.14 .0744L1.357 41.24C-4.768 20.75 10.61 0 31.98 0h448C500 0 515.2 18.25 511.4 37.87z"></path></svg>')
.cell:nth-child(10) .glass .face__front
background-position -8% 100%
background-size calc(10*var(--unit))
background-image embedurl(crack='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M377.7 338.8l37.15-92.87C419 235.4 411.3 224 399.1 224h-57.48C348.5 209.2 352 193 352 176c0-4.117-.8359-8.057-1.217-12.08C390.7 155.1 416 142.3 416 128c0-16.08-31.75-30.28-80.31-38.99C323.8 45.15 304.9 0 277.4 0c-10.38 0-19.62 4.5-27.38 10.5c-15.25 11.88-36.75 11.88-52 0C190.3 4.5 181.1 0 170.7 0C143.2 0 124.4 45.16 112.5 88.98C63.83 97.68 32 111.9 32 128c0 14.34 25.31 27.13 65.22 35.92C96.84 167.9 96 171.9 96 176C96 193 99.47 209.2 105.5 224H48.02C36.7 224 28.96 235.4 33.16 245.9l37.15 92.87C27.87 370.4 0 420.4 0 477.3C0 496.5 15.52 512 34.66 512H413.3C432.5 512 448 496.5 448 477.3C448 420.4 420.1 370.4 377.7 338.8zM176 479.1L128 288l64 32l16 32L176 479.1zM271.1 479.1L240 352l16-32l64-32L271.1 479.1zM320 186C320 207 302.8 224 281.6 224h-12.33c-16.46 0-30.29-10.39-35.63-24.99C232.1 194.9 228.4 192 224 192S215.9 194.9 214.4 199C209 213.6 195.2 224 178.8 224h-12.33C145.2 224 128 207 128 186V169.5C156.3 173.6 188.1 176 224 176s67.74-2.383 96-6.473V186z"></path></svg>')
.cell:nth-child(2) .glass .face__front
background-position -8% 100%
background-size calc(10*var(--unit))
background-image embedurl(crack='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M186.1 .1032c-105.1 3.126-186.1 94.75-186.1 199.9v264c0 14.25 17.3 21.38 27.3 11.25l24.95-18.5c6.625-5.001 16-4.001 21.5 2.25l43 48.31c6.25 6.251 16.37 6.251 22.62 0l40.62-45.81c6.375-7.251 17.62-7.251 24 0l40.63 45.81c6.25 6.251 16.38 6.251 22.62 0l43-48.31c5.5-6.251 14.88-7.251 21.5-2.25l24.95 18.5c10 10.13 27.3 3.002 27.3-11.25V192C384 83.98 294.9-3.147 186.1 .1032zM128 224c-17.62 0-31.1-14.38-31.1-32.01s14.38-32.01 31.1-32.01s32 14.38 32 32.01S145.6 224 128 224zM256 224c-17.62 0-32-14.38-32-32.01s14.38-32.01 32-32.01c17.62 0 32 14.38 32 32.01S273.6 224 256 224z"></path></svg>')
const win = window
const root = document.documentElement
/*
* throttle events
*/
function throttle(fn, delay) {
let allowSample = true;
return function (e) {
if (allowSample) {
allowSample = false;
setTimeout(() => { allowSample = true; }, delay);
fn(e);
}
}
}
/*
* mouse move
*/
window.onmousemove = throttle(mouseMoveHandler, 100)
function mouseMoveHandler(e) {
const clientX = Math.round(e.clientX / (root.clientWidth / 100))/100
const clientY = Math.round(e.clientY / (root.clientHeight / 100))/100
root.style.setProperty("--client-x", clientX)
root.style.setProperty("--client-y", clientY)
}
/*
* Purely for debugging
*/
const {
dat: { GUI },
} = window
const CONTROLLER = new GUI()
const CONFIG = { 'parallax-x': 0, 'parallax-z': 0, 'zoom': 1, 'global-x': 70, 'global-y': 0, 'global-z': 30, 'labels': false, 'checker': false, 'wireframe': false, 'face-opacity': 1, }
const UPDATE = () => {
Object.entries(CONFIG).forEach(([key, value]) => {
document.documentElement.style.setProperty(`--${key}`, value)
})
document.documentElement.setAttribute('checker', CONFIG.checker ? true : false)
document.documentElement.setAttribute('labels', CONFIG.labels ? true : false)
document.documentElement.setAttribute('wireframe', CONFIG.wireframe ? true : false)
}
const STAGE_FOLDER = CONTROLLER.addFolder('Stage')
STAGE_FOLDER.add(CONFIG, 'zoom', 0, 5, 0.1)
.name('Zoom')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'global-x', 0, 180, 1)
.name('Global X (deg)')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'global-y', 0, 180, 1)
.name('Global Y (deg)')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'global-z', 0, 180, 1)
.name('Global Z (deg)')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'parallax-x', 0, 180, 1)
.name('Parallax X')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'parallax-z', 0, 180, 1)
.name('Parallax Z')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'face-opacity', 0, 1, 0.1)
.name('Face Opacity')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'checker')
.name('Checker Texture')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'labels')
.name('Labels')
.onChange(UPDATE)
STAGE_FOLDER.add(CONFIG, 'wireframe')
.name('Wireframe')
.onChange(UPDATE)
UPDATE()
STAGE_FOLDER.open()
CONTROLLER.close()
Also see: Tab Triggers