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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
div.container
button Toggle
ul.block
li Vanilla JS
li 60 FPS
//- div.container
//- button Toggle
//- ul.block.with-padding
//- li One
//- li Two
div.container
button Toggle
ul.block.with-border
li One
li Two
li Three
li Four
div.container
button Toggle
ul.block.hidden
li One
li Two
li Three
body
display: flex
min-height: 100vh
justify-content: space-around
align-items: flex-start
background: linear-gradient(to right top, #000000, #e5008d, #ff070b)
user-select: none
font-family: 'Titillium Web', sans-serif
.container
text-align: center
margin: 40px
flex: 1
button
background: black
border: black
width: 100%
color: white
border-radius: .125em
font: inherit
padding: .75em 1em
text-transform: uppercase
letter-spacing: .1em
box-shadow: 0 2px 3px 0 rgba(black,.5)
cursor: pointer
.block
background: black
box-shadow: 0 2px 3px 0 rgba(black,.5)
text-align: left
font-size: 1.25em
color: white
list-style-type: none
overflow: hidden
padding: 0
white-space: nowrap
letter-spacing: .1em
&.with-padding
padding: 5em 0
// box-sizing: border-box
&.with-border
border:
top: 1px solid magenta
bottom: 2px solid magenta
&.hidden
display: none
li
padding: 1em .5em
margin: 0 1em
+ li
border-top: 1px solid white
class slideToggler
constructor: (@el) ->
return unless @el
window.addEventListener 'resize', @getHeight
getHeight: =>
clone = @el.cloneNode(true)
clone.style.cssText = 'visibility: hidden; display: block; margin: -999px 0'
@height = (@el.parentNode.appendChild clone).clientHeight
@el.parentNode.removeChild(clone)
return @height
toggle: (time) =>
@getHeight()
time or= @height / 3 + 150
currHeight = @el.clientHeight * (getComputedStyle(@el).display != 'none')
[start, end] = if currHeight > @height/2 then [@height,0] else [0,@height]
disp = end - start
el = @el
@el.classList[ if end is 0 then 'remove' else 'add' ] 'open'
@el.style.cssText = "overflow: hidden; display: block;"
init = (new Date).getTime()
repeat = ->
instance = (new Date).getTime() - init
step = start + disp * instance / time
if instance <= time
el.style.height = step + 'px' # if Math.floor(step) in [start..end]
else
el.style.cssText = "display: #{if end is 0 then 'none' else 'block'}"
repeatLoop = requestAnimationFrame(repeat)
cancelAnimationFrame repeatLoop unless Math.floor(step) in [start..end]
repeat()
for block in document.querySelectorAll('.block')
block.toggler = new slideToggler block
for trigger in document.querySelectorAll('button')
trigger.addEventListener 'click', ->
@parentNode.querySelector('.block').toggler?.toggle()
Also see: Tab Triggers