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.
.container
label(for='let-the-dogs-out') Let the dogs out?
input.let-the-dogs-out(type='checkbox', id='let-the-dogs-out')
label.no-firefox Unfortunately, not in this browser 😭<br/> Maybe try Firefox to set them free!
.dogmoji 🐶
.yard
.kennel
.kennel__front
.kennel__frame
.kennel__door
.dogs
.dog 🐶
.dog 🐶
.dog 🐶
.kennel__roof.kennel__roof--left
.kennel__roof.kennel__roof--right
- for(let i = 0; i < 15; i++)
- let doge = Math.random() > 0.5 ? '🐕' : '🐩'
.dog= doge
@import url('https://fonts.googleapis.com/css?family=Lato')
*
box-sizing border-box
body
background-color #2eec71
color #fafafa
text-align center
font-size 16px
font-family 'Lato', sans-serif
padding 2rem
random(ceiling)
return floor(math(1, 'random')*ceiling)
limit = 40
@keyframes move
0%, 100%
transform translate(0, 0)
25%
transform translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
50%
transform translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
75%
transform translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
@keyframes move-flipped
0%, 100%
transform rotateY(180deg) translate(0, 0)
25%
transform rotateY(180deg) translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
50%
transform rotateY(180deg) translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
75%
transform rotateY(180deg) translate((random(limit) - (limit / 2)) * 1%, (random(limit) - (limit / 2)) * 1%)
@keyframes nod
0, 100%
transform translateY(0)
50%
transform translateY(25%)
@keyframes get-excited
0, 100%
transform translateY(0)
50%
transform translateY(-15px)
.container
align-items center
flex-direction column
position relative
text-align center
label
font-size 2rem
text-decoration line-through
.dogmoji
font-size 2.5 rem
margin-bottom 10px
.let-the-dogs-out
height 25px
width 25px
&:hover
& ~ .yard .dogs
animation get-excited .15s infinite
@supports (display: contents)
&:checked
& ~ .dogmoji
animation nod .15s infinite
& ~ .yard
.kennel
display contents
&__front
display none
.dog
animation-iteration-count infinite
for dog in (1..20)
&:nth-child({dog})
if random(10) < 5
animation-name move
else
animation-name move-flipped
.yard
border 4px solid silver
border-radius 5px
background-color grey
height 300px
width 300px
display flex
flex-direction row
flex-wrap wrap
justify-content center
align-items center
margin 0 auto
.kennel
display block
height 150px
width 150px
overflow hidden
position relative
&__front
height 150px
width 150px
display flex
justify-content center
align-items center
animation rock 2s infinite alternate
&__frame
wood-color = #f3a32c
slat-size = 20px
background repeating-linear-gradient(180deg, wood-color, wood-color slat-size, darken(wood-color, 30%) slat-size, darken(wood-color, 30%) slat-size + 2px)
clip-path polygon(0% 100%, 0 40%, 50% 0, 100% 40%, 100% 100%)
height 120px
position relative
width 100px
&__roof
background-color #e74c3c
height 10px
left 50%
position absolute
top 10px
width 90px
&--left
transform-origin left
transform rotate(45deg) skewX(44deg)
&--right
transform-origin 0px
transform rotate(135deg) skewX(-45deg)
&__door
border-radius 25px 25px 0 0
height 70px
width 60px
background-color black
position absolute
bottom 0
left 50%
transform translateX(-50%)
.dogs
position absolute
bottom 0
left 50%
width 60px
margin-left -30px
.dog
position absolute
font-size 4rem
bottom 0
left 50%
.dog:nth-child(1)
font-size 2.5rem
transform translate(-50%, 0%)
.dog:nth-child(2)
font-size 1.5rem
transform translate(-180%, 0%)
.dog:nth-child(3)
font-size 1.25rem
transform translate(120%, 0%)
.dog
display flex
font-size 1.5rem
width 20%
justify-content center
for dog in (1..16)
&:nth-child({dog})
animation-duration random(10) * .1s
animation-delay random(10) * .1s
.no-firefox
display block
font-size 1.5rem
text-decoration none
@supports (display: contents)
.no-firefox
display none
label
text-decoration none
// There is nothing to see here
Also see: Tab Triggers