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__horses(style=`--horses: ${horses}`)
- for(let h = 0; h < horses * 2; h++)
.carousel__horse(style=`--horse: ${h % horses}; --delay: ${h > 9 ? -0.5 : 0}; --depth: ${h > 9 ? 80 : 100}`) ðŸŽ
.carousel__base(style=`--sides: ${segments}`)
- for (let s = 0; s < segments; s++)
div(style=`--side: ${s}`)
.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++)
div(style=`--side: ${c}`)
*
box-sizing border-box
body
align-items center
display flex
justify-content center
min-height 100vh
transform-style preserve-3d
perspective 1500px
background #86e2d5
$primary = #ff9478
$secondary = #f2f1ef
$darken = 5%
$darker = 10%
$core = #abb7b7
:root
--carouselDur 4
--horseDur 2
--baseInnerEven darken($primary, $darken)
--baseInnerOdd darken($secondary, $darker)
--baseEven darken($primary, $darker)
--baseOdd darken($secondary, $darken)
--core $core
--coreWindow #ffffff
--coreWindowSill darken($core, 25%)
--baseLight #ffffff
--baseSkirt $primary
--hatOdd $primary
--hatEven $secondary
.carousel
height 100px
width 100px
transform translate(-50%, -50%) rotateX(-15deg) rotateY(40deg)
transform-style preserve-3d
position absolute
top 50%
left 50%
&__core
bottom -10%
height 150%
left 50%
position absolute
transform translate(-50%, 0)
transform-style preserve-3d
width 20%
div
background var(--core)
height 100%
left 50%
position absolute
top 50%
transform translate(-50%, -50%) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) translate3d(0, 0, 30px) rotateY(180deg)
width 100%
&:nth-of-type(even)
&:after
background var(--coreWindow)
border 2px solid var(--coreWindowSill)
border-radius 35% 35% 0 0
content ''
height 15%
left 50%
position absolute
top 50%
transform translate(-50%, 0%)
width 50%
&__horses
animation carousel calc(var(--carouselDur) * 1s) infinite linear
height 50px
left 50%
position absolute
top 50%
transform translate(-50%, -50%)
transform-style preserve-3d
width 50px
z-index 5
&__horse
animation horse calc(var(--horseDur) * 1s) calc((var(--horseDur) * var(--delay)) * 1s) infinite linear
font-size 2rem
left 50%
position absolute
top 50%
&__base
animation carousel calc(var(--carouselDur) * 1s) infinite linear
left 50%
position absolute
top 100%
transform translate(-50%, -50%)
transform-style preserve-3d
div
background var(--baseOdd)
height 20px
left 50%
position absolute
top 0
transform translate(-50%, 0) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) translate3d(0, 0, 50px)
transform-origin top center
transform-style preserve-3d
width 20px
&:before
$clip = inset(40% 0 0 0)
-webkit-clip-path $clip
content ''
position absolute
border-bottom 120px solid var(--baseInnerOdd)
border-left 20px solid transparent
border-right 20px solid transparent
clip-path $clip
left 50%
transform translate(-50%, 0) rotateX(90deg) translate(0, -50px)
transform-origin top center
transform-style preserve-3d
&:nth-of-type(even)
background var(--baseEven)
&:before
border-bottom 120px solid var(--baseInnerEven)
&:after
content ''
background radial-gradient(circle at 50% 50%, var(--baseLight) 20%, var(--baseSkirt) 20%), var(--baseSkirt)
height 20px
left 50%
position absolute
top 0
transform translate3d(-50%, 0, 70px)
transform-origin top center
width 40px
&__hat
animation carousel calc(var(--carouselDur) * 1s) infinite linear
bottom 100%
height 50px
left 50%
position absolute
transform translate(-50%, -50%)
transform-style preserve-3d
width 50px
div
$height = 140px
border-bottom $height solid var(--hatOdd)
border-top 0
border-left 20px solid transparent
border-right 20px solid transparent
left 50%
position absolute
top 0
transform translate(-50%, 0) rotateY(calc(((-360 / var(--sides)) * var(--side)) * 1deg)) rotateX(65deg)
transform-origin top center
transform-style preserve-3d
&:nth-of-type(even)
border-bottom $height solid var(--hatEven)
&:after
background var(--hatEven)
&:after
background var(--hatOdd)
border-radius 0 0 40px 40px
content ''
height 20px
position absolute
top 140px
transform translate(-50%, 0) rotateX(-65deg)
transform-origin top center
width 40px
@keyframes carousel
from
transform translate(-50%, -50%) rotateY(0deg)
to
transform translate(-50%, -50%) rotateY(360deg)
@keyframes horse
0%, 100%
transform translate(-50%, -50%) rotateY(calc(((-360 / var(--horses)) * var(--horse)) * 1deg)) translate3d(0, 0, calc(var(--depth) * 1px)) rotateY(180deg)
50%
transform translate(-50%, 0) rotateY(calc(((-360 / var(--horses)) * var(--horse)) * 1deg)) translate3d(0, 0, calc(var(--depth) * 1px)) rotateY(180deg)
// NOPE
Also see: Tab Triggers