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++
input(type="radio" name="fan" id="zero")
input(type="radio" name="fan" id="one" checked="true")
input(type="radio" name="fan" id="two")
input(type="radio" name="fan" id="three")
.scene
.fan
.fan__base
+cuboid()(class="base")
.fan__controls
label.fan__control(for="zero")
+cuboid()(class="control")
label.fan__control(for="one")
+cuboid()(class="control")
label.fan__control(for="two")
+cuboid()(class="control")
label.fan__control(for="three")
+cuboid()(class="control")
.fan__spine
+cuboid()(class="spine")
.fan__head
.fan__rotater
+cuboid()(class="rotater")
.fan__stalk
+cuboid()(class="stalk")
//- Use this as the ring
.fan__barrel
+cuboid()(class="barrel")
.fan__housing
.fan__housing-rear
.fan__blades
.fan__blade
.fan__blade
.fan__blade
.fan__housing-front
img(src="https://assets.codepen.io/605876/avatar.png")
*
*:after
*:before
box-sizing border-box
transform-style preserve-3d
:root
--blade-speed 1
--rotation 25
--fan-speed 2
--state running
--bg hsl(210, 32%, 30%)
--shade-one hsl(0, 0%, 95%)
--shade-two hsl(0, 0%, 90%)
--shade-three hsl(0, 0%, 85%)
--shade-four hsl(0, 0%, 80%)
--shade-five hsl(0, 0%, 75%)
--shade-six hsl(0, 0%, 70%)
--shade-seven hsl(0, 0%, 65%)
--shade-eight hsl(0, 0%, 60%)
--cage-one hsla(210, 80%, 100%, 0.4)
--cage-two hsla(210, 80%, 100%, 0.2)
body
min-height 100vh
display grid
place-items center
background var(--bg)
overflow hidden
transform scale(0.75)
img
height 20%
position absolute
top 50%
left 50%
transform translate3d(-50%, -50%, 1px)
filter grayscale(1)
opacity 0.5
input[type="radio"]
position fixed
top 0
left 100%
opacity 0
#zero:checked ~ .scene
--blade-speed 0
--state paused
.fan__stalk
transform translate(-50%, 25%)
#one:checked ~ .scene
--blade-speed 1
--state running
.fan__control:nth-of-type(2)
transition transform 0.1s cubic-bezier(0, 1.4, .2, 1.4)
transform translate(0, 50%)
#two:checked ~ .scene
--blade-speed 0.5
--state running
.fan__control:nth-of-type(3)
transition transform 0.1s cubic-bezier(0, 1.4, .2, 1.4)
transform translate(0, 50%)
#three:checked ~ .scene
--blade-speed 0.25
--state running
.fan__control:nth-of-type(4)
transition transform 0.1s cubic-bezier(0, 1.4, .2, 1.4)
transform translate(0, 50%)
.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
:root
--height 70vmin
--width 40vmin
label
transition transform 0.1s
cursor pointer
label:hover
transform translate(0, 20%)
label:active
transform translate(0, 40%)
.scene
position absolute
height var(--width)
width var(--width)
top 50%
left 50%
transform translate3d(-50%, -50%, 0vmin) rotateX(-24deg) rotateY(34deg) rotateX(90deg)
.fan
height var(--height)
width var(--width)
position absolute
top 50%
left 50%
transform translate(-50%, -50%) rotateX(-90deg) rotateX(calc(var(--rotateX, 0) * 1deg)) rotateY(calc(var(--rotateY, 0) * 1deg))
&__base
position absolute
bottom 0
left 50%
transform translate(-50%, 0)
height 8%
width 80%
&__controls
height 6%
width 50%
position absolute
bottom 6%
left 50%
transform translate3d(-50%, 0, calc(var(--width) * 0.3))
display grid
grid-template-columns repeat(4, 1fr)
grid-gap 6%
&__housing
height 150%
width 150%
border-radius 50%
top 50%
left 50%
position absolute
border 1vmin solid var(--shade-one)
background var(--cage-one)
transform translate3d(-50%, -50%, calc(var(--width) * 0.45))
&__housing-rear
&__housing-front
position absolute
top 50%
left 50%
height 80%
width 80%
background var(--cage-two)
border-radius 50%
border 1vmin solid var(--shade-one)
&__housing-front
transform translate3d(-50%, -50%, calc(var(--width) * 0.11))
&:after
content ''
position absolute
top 50%
left 50%
height 35%
width 35%
transform translate(-50%, -50%)
border-radius 50%
background var(--shade-one)
&__housing-rear
transform translate3d(-50%, -50%, calc(var(--width) * -0.1))
border 1vmin solid var(--shade-two)
&__head
height var(--width)
width var(--width)
position absolute
top 0
left 0
transform translate3d(0, 0, calc(var(--width) * -0.25))
animation fan calc(var(--fan-speed, 1) * 1s) infinite alternate ease-in-out var(--state)
&__rotater
top 50%
width calc(var(--width) * 0.2)
height calc(var(--width) * 0.2)
position absolute
left 50%
transform translate(-50%, -50%)
&__spine
height 57.5%
bottom 8%
width 20%
position absolute
left 50%
transform translate3d(-50%, 0%, calc(var(--width) * -0.25))
&__stalk
height 150%
left 50%
bottom 0
transform translate(-50%, 0)
transition transform 0.2s cubic-bezier(0, 1.4, .2, 1.4)
width 25%
position absolute
&__blades
position absolute
top 50%
left 50%
height 16%
width 16%
transform translate3d(-50%, -50%, -1px) rotate(0deg)
animation rotate calc(var(--blade-speed, 0) * 1s) infinite linear
&__blade
height 300%
width 100%
background var(--shade-one)
position absolute
top 50%
left 50%
transform-origin 50% 0
transform translate(-50%, 0) rotate(calc(var(--rotate, 0) * 1deg))
&:nth-of-type(1)
--rotate 0
&:nth-of-type(2)
--rotate calc(360 / 3 * 1)
&:nth-of-type(3)
--rotate calc(360 / 3 * 2)
&__barrel
height 22.5%
width 22.5%
position absolute
top 50%
left 50%
transform translate3d(-50%, -50%, calc(var(--width) * 0.3))
.base
--thickness calc(40 * 0.8)
div
background var(--shade-two)
&:nth-of-type(1)
background var(--shade-one)
&:nth-of-type(5)
background var(--shade-three)
&:nth-of-type(4)
background va(--shade-six)
.control
--thickness calc(((40 * 0.5) - ((40 * 0.5) * 0.18)) / 3)
div
background var(--shade-five)
&:nth-of-type(1)
background var(--shade-three)
&:nth-of-type(5)
background var(--shade-six)
&:nth-of-type(4)
background va(--shade-eight)
.fan__control:nth-of-type(1) .control
--shade-three hsl(25, 80%, 85%)
--shade-five hsl(25, 80%, 75%)
--shade-six hsl(25, 80%, 70%)
--shade-eight hsl(25, 80%, 60%)
.spine
--thickness calc(40 * 0.2)
div
background var(--shade-three)
&:nth-of-type(1)
background var(--shade-two)
&:nth-of-type(5)
background var(--shade-four)
&:nth-of-type(4)
background va(--shade-seven)
.rotater
--thickness calc(40 * 0.2)
div
background var(--shade-two)
&:nth-of-type(1)
background var(--shade-one)
&:nth-of-type(5)
background var(--shade-three)
&:nth-of-type(4)
background va(--shade-six)
.barrel
--thickness calc(40 * 0.5)
div
background var(--shade-three)
&:nth-of-type(1)
background var(--shade-two)
&:nth-of-type(5)
background var(--shade-four)
&:nth-of-type(4)
background va(--shade-seven)
.stalk
--thickness calc(40 * 0.05)
div
background var(--shade-four)
&:nth-of-type(1)
background var(--shade-three)
&:nth-of-type(5)
background var(--shade-five)
&:nth-of-type(4)
background va(--shade-eight)
@keyframes fan
0%, 5%
transform translate3d(0, 0, calc(var(--width) * -0.25)) rotateY(calc(var(--rotation, 0) * 1deg))
95%, 100%
transform translate3d(0, 0, calc(var(--width) * -0.25)) rotateY(calc(var(--rotation, 0) * -1deg))
@keyframes rotate
from
transform translate3d(-50%, -50%, -1px) rotate(0deg)
to
transform translate3d(-50%, -50%, -1px) rotate(360deg)
Also see: Tab Triggers