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.
.form.hidden
.face
%svg{viewbox: "-10 -10 620 620"}
%g{stroke: "#4d4d4d", "stroke-width" => "20", id: "face"}
%circle{cx: "300", cy: "300", r: "300"}
%path{d: "M100,350 Q300,450 500,350 Q300,550 100,350 z", fill: "white", stroke: "#4d4d4d", "stroke-width" => "20", "stroke-linejoin" => "round", id: "mouth"}
%g{fill: "#4d4d4d"}
//%circle{cx: "300", cy: "200", r: "30"}
//%circle{cx: "500", cy: "200", r: "30"}
%path{d: "M285 200 a 30 30 0 1 0 -1 0 z", fill: "#4d4d4d", stroke: "#4d4d4d", "stroke-width" => "20", "stroke-linejoin" => "round", class: "eye--left"}
%path{d: "M515 200 a 30 30 0 1 0 -1 0 z", fill: "#4d4d4d", stroke: "#4d4d4d", "stroke-width" => "20", "stroke-linejoin" => "round", class: "eye--right"}
%h3.heading How do you feel about our customer service?
.sliding-list
%ul
- ["Absolutely Terrible!", "Dissapointing", "Quite Bad hey", "Not impressed", "Nothing to be proud of", "Could have been better", "Satisfactory", "Ok, I guess", "Was Great", "Super Impressed!"].each do |i|
%li #{i}
%input.slider(type="range" min=0 max=99 value=80 oninput="updateSlider(value)")
%footer
%a(href="https://twitter.com/code_dependant" class="twitter-follow-button" data-show-count="false")
Follow @code_dependant
%script !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
html, body
height: 100%
body
font-family: Lato, 'Helvetica Neue'
background-color: rgb(245,245,242)
text-align: center
color: #4d4d4d
margin: 3rem
.face
width: 100%
margin: 3rem auto
max-width: 400px
transition: .6s all
svg
width: 100%
transition: 1.5s all cubic-bezier(.17,.67,.03,1)
transform-origin: 50% 100%
.form.hidden &
opacity: 0
transform: rotateX(75deg) rotateY(-30deg) translateX(50%) rotateZ(90deg)
.heading
transition: .8s all ease .1s
margin: 0
margin-bottom: 1.5rem
.form.hidden &
transform: translateY(60px)
opacity: 0
.sliding-list
font-size: 2em
height: 1.5em
overflow: hidden
margin-bottom: 1.5rem
font-weight: 900
transition: .8s all ease .2s
.form.hidden &
transform: translateY(60px)
opacity: 0
ul
margin: 0
padding: 0
list-style: none
transition: .3s transform
text-align: center
li
line-height: 1.5em
.slider
margin-bottom: 1.5rem
$track-width: 300px
$track-height: 20px
$track-border-radius: $track-height
$track-background-color: white
$track-focus-background-color: darken($track-background-color, 10%)
$thumb-size: $track-height
$thumb-background-color: #4d4d4d
input[type=range]
-webkit-appearance: none
//border: 1px solid white
width: $track-width
background: transparent
transition: .8s all ease .3s
.form.hidden &
transform: translateY(60px)
opacity: 0
&::-webkit-slider-runnable-track
width: $track-width
height: $track-height+6px
background: $track-background-color
border: 3px solid $thumb-background-color
border-radius: $track-border-radius
&::-webkit-slider-thumb
-webkit-appearance: none
border: none
height: $thumb-size
width: $thumb-size
border-radius: 50%
background: $thumb-background-color
cursor: pointer
&:focus
outline: none
&::-webkit-slider-runnable-track
background: $track-focus-background-color
&::-moz-range-track
width: $track-width
height: $track-height
background: $track-background-color
border: 3px solid $thumb-background-color
border-radius: $track-border-radius
&::-moz-range-thumb
border: none
height: $thumb-size
width: $thumb-size
border-radius: 50%
background: $thumb-background-color
cursor: pointer
&:-moz-focusring
outline: 1px solid white
outline-offset: -1px
&::-ms-track
width: $track-width
height: $thumb-size
background: $track-background-color
border: none
border-radius: $track-border-radius
color: transparent
&::-ms-fill-lower
outline: none
background: $track-background-color
border-radius: $track-border-radius 0 0 $track-border-radius
&::-ms-thumb
border: none
height: $thumb-size
width: $thumb-size
border-radius: 50%
background: $thumb-background-color
&:focus
&::-ms-track
background: $track-focus-background-color
&::-ms-fill-lower
background: $track-focus-background-color
footer
position: fixed
bottom: 1.5em
right: 1.5em
$ ->
document.querySelector(".form").classList.remove("hidden")
input =
rating: 80
mouth =
eyes:
width: 30
height: 30
sides: 350
middle:
top: 450
bottom: 550
render = ->
$("#mouth").attr("d", "M100,#{mouth.sides} Q300,#{mouth.middle.top} 500,#{mouth.sides} Q300,#{mouth.middle.bottom} 100,#{mouth.sides} z")
$("#face").attr("fill", "hsl(#{Math.round(input.rating)}, 60%, 74%)")
$(".eye--left").attr("d", "M185 200 a #{mouth.eyes.height} #{mouth.eyes.width} 0 1 0 -1 0 z")
$(".eye--right").attr("d", "M415 200 a #{mouth.eyes.height} #{mouth.eyes.width} 0 1 0 -1 0 z")
update = ->
position = input.rating
keyframes =
0:
eyes:
width: 20
height: 35
sides: 444
middle:
top: 184
bottom: 390
25:
eyes:
width: 23
height: 32
sides: 423
middle:
top: 217
bottom: 217
eyes:
width: 30
height: 30
50:
eyes:
width: 30
height: 30
sides: 400
middle:
top: 400
bottom: 400
75:
eyes:
width: 40
height: 30
sides: 350
middle:
top: 450
bottom: 596
100:
eyes:
width: 50
height: 30
sides: 360
middle:
top: 360
bottom: 680
for index in [0..Object.keys(keyframes).length-1]
startKeyframePosition = parseFloat(Object.keys(keyframes)[index])
endKeyframePosition = parseFloat(Object.keys(keyframes)[index+1])
startKeyframeValue = keyframes[startKeyframePosition]
endKeyframeValue = keyframes[endKeyframePosition]
if startKeyframePosition <= position <= endKeyframePosition
relativePosition = (position - startKeyframePosition)/(endKeyframePosition - startKeyframePosition)
setObjectKeyframe(relativePosition, mouth, startKeyframeValue, endKeyframeValue)
render()
setObjectKeyframe = (position, object, startKeyframeObject, endKeyframeObject)->
for key in Object.keys(startKeyframeObject)
startValue = startKeyframeObject[key]
endValue = endKeyframeObject[key]
if typeof startKeyframeObject[key] is "number"
object[key] = (endValue - startValue) * position + startValue
else if typeof startKeyframeObject[key] is "object"
setObjectKeyframe(position, object[key], startValue, endValue)
gui = new dat.GUI()
gui.close()
gui.add(mouth, "sides", 0, 500).onChange(render)
gui.add(mouth.middle, "top", 0, 1000).onChange(render)
gui.add(mouth.middle, "bottom", 0, 1000).onChange(render)
gui.add(mouth.eyes, "height", 1, 50).onChange(render)
gui.add(mouth.eyes, "width", 1, 50).onChange(render)
gui.add(input, "rating", 0, 100).onChange(update)
window.updateSlider = (value)->
input.rating = value
update()
listIndex = ~~(value/10)
document.querySelector(".sliding-list ul").style.transform = "translateY(#{-listIndex*1.5}em)"
render()
updateSlider(80)
Also see: Tab Triggers