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.form{action: ''}
%p.field.required
%label.label.required{for: 'name'} Full name
%input.text-input#name{type: 'text', name: 'name', required: true, value: 'Use Tab'}
%p.field.required.half
%label.label{for: 'email'} E-mail
%input.text-input#email{type: 'email', name: 'email', required: true}
%p.field.half
%label.label{for: 'phone'} Phone
%input.text-input#phone{type: 'phone', name: 'phone'}
%p.field.half.required.error
%label.label{for: 'login'} Login
%input.text-input#login{type: 'text', name: 'login', required: true, value: 'mican'}
-# %span.message Already taken
%p.field.half.required
%label.label{for: 'password'} Password
%input.text-input#password{type: 'password', name: 'password', required: true}
%div.field
%label.label Sport?
%ul.checkboxes
- %w(Football Basketball Volleyball Golf Swimming).each_with_index do |item,i|
%li.checkbox
%input.checkbox-input{name: 'choice', type: 'checkbox', value: i, id: "choice-#{i}"}/
%label.checkbox-label{:for => "choice-#{i}"}= item
%div.field
%label.label Favourite JS framework
%ul.options
- %w(React Vue Angular Riot Polymer Ember Meteor Knockout).each_with_index do |item,i|
%li.option
%input.option-input{name: 'option', type: 'radio', value: i, id: "option-#{i}"}/
%label.option-label{:for => "option-#{i}"}= item
%p.field
%label.label{for: "about"} About
%textarea.textarea#about{cols: 50, name: "about", rows: 4}
%p.field.half
%label.label{for: "select"} Position
%select#select.select
%option{value: '', selected: true}
%option{value: "ceo"} CEO
%option{value: "front-end"} Front-end developer
%option{value: "back-end"} Back-end developer
%p.field.half
%input.button{type: "submit", value: "Send"}
// colors
$bg: #111111
$vibrant: #E8474C
$text: white
$label: white
$border: transparent
$static: #222222
$focus: #4E4E4E
$active: white
$inactive: #4E4E4E
$error: #E8474C
html
-webkit-font-smoothing: antialiased
body
background-color: $bg
font-family: 'Titillium Web', sans-serif
@media screen and (min-width: 40em)
font-size: 1.25em
%block
padding: .75em 1em
appearance: none
outline: none
line-height: normal
border-radius: 0
border: none
background: none
display: block
%label
@extend %block
font-weight: bold
color: $label
padding:
top: 0
left: 0
letter-spacing: .025em
font-size: 1.125em
line-height: 1.25
position: relative
z-index: 100
.required &:after
content: '\0020*'
color: $error
font-weight: normal
font-size: .75em
vertical-align: top
=stripes($color1: #555, $color2: transparent, $angle: 0deg, $stripe1-width: 25px, $stripe2-width: null)
@if $stripe2-width == null
$stripe2-width: $stripe1-width
$tile-size: ($stripe1-width + $stripe2-width) * 2
$stripe2-start: $stripe1-width / $tile-size * 100%
$stripe3-start: $stripe2-start + $stripe2-width / $tile-size * 100%
$stripe4-start: $stripe3-start + $stripe1-width / $tile-size * 100%
background-size: $tile-size $tile-size
background-image: linear-gradient($angle, $color1, $color1 $stripe2-start, $color2 $stripe2-start, $color2 $stripe3-start, $color1 $stripe3-start, $color1 $stripe4-start, $color2 $stripe4-start, $color2)
background-repeat: repeat
%input
@extend %block
font: inherit
line-height: normal
width: 100%
box-sizing: border-box
background: $static
color: white
position: relative
&:placeholder
color: $label
&:-webkit-autofill
box-shadow: 0 0 0px 1000px $bg inset
-webkit-text-fill-color: white
border-top-color: $bg
border-left-color: $bg
border-right-color: $bg
&.required, &[required]
&:not(:focus):not(:active)
&.error, .error &
+stripes(rgba($vibrant,.5), transparent, 135deg, 2px, 2px)
&:active, &:focus
@extend %input-active
%input-active
.form:not(.has-magic-focus) &
background: $focus
%error
@extend %block
// color: red
position: absolute
bottom: 0
right: 0
z-index: 100
font-size: .625em
color: $label
%checkbox
border: 0
clip: rect(0 0 0 0)
height: 1px
margin: -1px
overflow: hidden
padding: 0
position: absolute
width: 1px
+ label
@extend %input
display: inline-block
width: auto
color: $inactive
position: relative
user-select: none
cursor: pointer
&:focus, &:active
+ label
color: $focus
&:checked
+ label
color: $active
// &:focus, &:active
// + label:before
// box-shadow: inset 0px 0px 0px .5em $focus
// color: $active
%option
+ label
// &:before
// border-radius: 50%
// &:after
// top: 1px
// left: 1px
// width: 1em
// height: 1em
// box-sizing: border-box
// border: 3px solid $bg
// border-radius: 50%
// transform: none
%button
@extend %block
font: inherit
// font-size: 1em
line-height: normal
cursor: pointer
background: $vibrant
color: white
font-weight: bold
width: auto
margin-left: auto
font-weight: bold
padding:
left: 2em
right: 2em
&:hover, &:focus, &:active
color: white
border-color: white
&:active
position: relative
top: 1px
left: 1px
body
padding: 2em
.form
max-width: 40em
margin: 0 auto
position: relative
display: flex
flex-flow: row wrap
justify-content: space-between
align-items: flex-end
.field
width: 100%
margin: 0 0 1.5em 0
&.half
@media screen and (min-width: 40em)
width: calc(50% - 1px)
&.last
margin-left: auto
.text-input
@extend %input
.textarea
@extend %input
max-width: 100%
.button
@extend %button
.label
@extend %label
.message
@extend %error
.select
@extend %input
text-indent: 0.01px
text-overflow: ""!important
&::-ms-expand
display: none
.checkboxes, .options
padding: 0
margin: 0
list-style-type: none
overflow: hidden
.checkbox, .option
float: left
margin: 1px
.checkbox-input
@extend %checkbox
.option-input
@extend %checkbox
// @extend %option
.customSelect
@extend %input
pointer-events: none
&:after
content: ''
pointer-events: none
width: .5em
height: .5em
border-style: solid
border-color: $label
border-width: 0 3px 3px 0
position: absolute
top: 50%
margin-top: -.625em
right: 1em
transform-origin: 0 0
transform: rotate(45deg)
&.customSelectHover
&.customSelectOpen
&.customSelectFocus
@extend %input-active
&:after
border-color: white
.customSelectInner
.magic-focus
position: absolute
z-index: 0
width: 0
// height: 0
pointer-events: none
background: rgba(white,.15)
transition: top .2s, left .2s, width .2s
backface-visibility: hidden
transform-style: preserve-3d
will-change: top, left, width
transform-origin: 0 0
class magicFocus
constructor: (@parent) ->
return unless @parent
@focus = document.createElement 'div'
@focus.classList.add 'magic-focus'
@parent.classList.add 'has-magic-focus'
@parent.appendChild @focus
for input in @parent.querySelectorAll('input, textarea, select')
input.addEventListener 'focus', ->
window.magicFocus.show()
input.addEventListener 'blur', ->
window.magicFocus.hide()
show: =>
return unless ['INPUT','SELECT','TEXTAREA'].includes? (el = document.activeElement).nodeName
clearTimeout(@reset)
el = document.querySelector("[for=#{el.id}]") if ['checkbox', 'radio'].includes? el.type
@focus.style.top = "#{el.offsetTop||0}px"
@focus.style.left = "#{el.offsetLeft||0}px"
@focus.style.width = "#{el.offsetWidth||0}px"
@focus.style.height = "#{el.offsetHeight||0}px"
hide: =>
@focus.style.width = 0 unless ['INPUT','SELECT','TEXTAREA', 'LABEL'].includes? (el = document.activeElement).nodeName
@reset = setTimeout ->
window.magicFocus.focus.removeAttribute('style')
, 200
# initialize
window.magicFocus = new magicFocus document.querySelector('.form')
$ ->
$('.select').customSelect()
Also see: Tab Triggers