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.
- const horses = 10
- const segments = 20
- const core = 10
.carousel
.carousel__lightring
.carousel__horses(style=`--horses: ${horses}`)
- for(let h = 0; h < horses * 2; h++)
.carousel__horse(style=`--horse: ${h}; --delay: ${h > 9 ? -0.5 : 0}; --depth-coefficient: ${h > 9 ? 0.75 : 1}`) 🎠
.carousel__base(style=`--sides: ${segments}`)
- for (let s = 0; s < segments; s++)
.carousel__base-side(style=`--side: ${s}; --delay: ${s > 9 ? -0.5 : 0};`)
.carousel__side.carousel__side--top
.carousel__side.carousel__side--inner
.carousel__side.carousel__side--outer
.carousel__light
.carousel__core(style=`--sides: ${core}`)
- for(let o = 0; o < core; o++)
div(style=`--side: ${o}`)
.carousel__hat(style=`--sides: ${segments};`)
- for(let c = 0; c < segments; c++)
.carousel__hat-segment(style=`--side: ${c}; --delay: ${c > 9 ? -0.5 : 0};`)
.carousel__segment.carousel__segment--main
.carousel__segment.carousel__segment--dress
.carousel__light
*
*:after
*:before
box-sizing border-box
transform-style preserve-3d
@property --jump
initial-value 0%
syntax '<percentage>'
inherits false
@property --spin
initial-value 0deg
syntax '<angle>'
inherits false
@property --hue
initial-value 0
syntax '<number>'
inherits false
body
display grid
place-items center
min-height 100vh
background var(--bg)
overflow hidden
:root
--bg hsl(210, 30%, 10%)
--height 16
--width 20
--speed 5
--horseSpeed 2
--horseSize 5
--base-depth 10
--pillar-depth 4
--pillar hsl(0, 0%, 55%)
--window hsl(45, 80%, 95%)
--sill hsl(45, 80%, 50%)
--lights hsl(0, 0%, 100%)
--primary hsl(280, 80%, 60%)
--secondary hsl(0, 0%, 98%)
--base-coefficient 0.75vmin
--base-height 20
--base-hole 0.6vmin
--base-stripe 3.9
.carousel
height calc(var(--height) * 1vmin)
width calc(var(--width) * 1vmin)
transform translate(-50%, -50%) rotateX(-15deg) rotateY(40deg)
position absolute
top 50%
left 50%
&__core
bottom -10%
height 110%
left 50%
position absolute
transform translate(-50%, 0)
width calc(var(--width) * 0.2vmin)
div
background var(--pillar)
height 100%
left 50%
position absolute
top 50%
transform translate(-50%, -50%) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) translate3d(0, 0, calc((var(--width) * 0.4) * 0.75vmin)) rotateY(180deg)
width 100%
filter brightness(0.9)
&:nth-of-type(even)
filter brightness(1)
&:after
background var(--window)
border 2px solid var(--sill)
border-radius 35% 35% 0 0
content ''
height 20%
left 50%
position absolute
top 50%
transform translate(-50%, 0%)
width 60%
&__light
width 15%
height 15%
position absolute
background 'hsl(%s, 90%, 80%)' % var(--hue, 0)
filter blur(10px), brightness(1.1)
top 50%
left 50%
border-radius 50%
transform translate(-50%, -50%)
animation party calc(var(--party-speed, 1) * 1s) calc(var(--delay, 1) * -1s) infinite linear
&__lightring
position absolute
top 100%
left 50%
background hsl(45, 90%, 90%)
border-radius 50%
filter blur(4vmin)
height calc(var(--width) * 2.3vmin)
width calc(var(--width) * 2.3vmin)
transform translate(-50%, -50%) rotateX(90deg) translate3d(0, 0, calc(var(--height) * -0.1vmin))
&__horses
animation spin calc(var(--speed) * 1s) infinite linear
height 100%
left 50%
position absolute
top 50%
transform translate(-50%, -50%) rotateY(var(--spin))
width 100%
z-index 5
&__horse
--depth calc(var(--width) * var(--depth-coefficient))
animation jump calc(var(--horseSpeed) * 1s) calc((var(--horseSpeed) * var(--delay)) * 1s) infinite linear both
font-size calc(var(--horseSize) * 1vmin)
left 50%
position absolute
top 50%
transform translate(-50%, var(--jump)) rotateY(calc(((-360 / var(--horses)) * var(--horse)) * 1deg)) translate3d(0, 0, calc(var(--depth) * 1vmin)) rotateY(180deg)
&:nth-of-type(even)
--depth calc(var(--width) * var(--depth-coefficient))
&__base
animation spin calc(var(--speed) * 1s) infinite linear
left 50%
position absolute
top 100%
transform translate(-50%, -50%) rotateY(var(--spin))
height 20%
&-side
--bg var(--primary)
height calc(var(--base-depth) * 1vmin)
left 50%
position absolute
top 0
transform translate(-50%, 0) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) rotateX(90deg) translate3d(0, calc(var(--width) * var(--base-hole)), 0)
transform-origin 50% 0%
width calc(var(--width) * 0.35vmin)
&:nth-of-type(even)
--bg var(--secondary)
&__side
height 100%
width 100%
background var(--bg)
position absolute
&--top
$clip = polygon(23% 0, 77% 0, 100% 100%, 0 100%)
-webkit-clip-path $clip
clip-path $clip
filter brightness(1.2)
&--inner
display block
height calc(var(--height) * 0.2vmin)
background var(--bg)
filter brightness(0.8)
top 0
left 50%
transform-origin 50% 0
transform translate(-50%, 0) rotateX(-90deg)
&--outer
display block
height calc(var(--height) * 0.2vmin)
background var(--bg)
filter brightness(1)
top 100%
left 50%
transform-origin 50% 0
transform translate(-50%, 0) rotateX(-90deg)
&__hat
animation spin calc(var(--speed) * 1s) infinite linear
bottom 100%
height 150%
left 50%
position absolute
transform translate(-50%, 40%) rotateY(var(--spin))
width 500%
&-segment
--bg var(--primary)
height 110%
width calc(var(--width) * 0.43vmin)
left 50%
position absolute
top 0
transform translate(-50%, 0) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) rotateX(65deg)
transform-origin top center
&:nth-of-type(even)
--bg var(--secondary)
&__segment
&--main
$clip = polygon(50% 0, 100% 100%, 0 100%)
background var(--bg)
filter brightness(1.2)
-webkit-clip-path $clip
clip-path $clip
height 100%
width 100%
&--dress
$clip = inset(50% 0 0 0)
filter brightness(0.75)
background var(--bg)
height 30%
position absolute
top 100%
left 50%
border-radius 50%
width 100%
transform translate(-50%, -50%) rotateX(-65deg)
-webkit-clip-path $clip
clip-path $clip
@keyframes spin
to
--spin 360deg
@keyframes jump
50%
--jump -50%
@keyframes party
to
--hue 359
// 404
Also see: Tab Triggers