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.
// TODO
// Dynamic sizing / breakpoint sizing
// 2 values, with animation to switch between.
// Remove JS reliance wherever possible for decent fallback
mixin starburst()
.starburst.js-starburst
-
var numberOfStars = 20
, i = 0
while i++ < numberOfStars
-
var scale = (Math.random() * (1 - 0.3) + 0.3).toFixed(2)
, rotation = ((1 / (numberOfStars + 1)) * i).toFixed(2)
, opacity = (Math.random() * (1 - 0.3) + 0.3).toFixed(2)
.starburst__star(style='transform: scale(' + scale + ') rotate(' + rotation + 'turn); opacity: ' + opacity + ';')
.starburst__star-inner
h2 Progress from empty
p Click to animate
.progress-badge.js-progress-badge
//- BADGE
.badge.badge--empty
.badge__fill
.badge__fill-inner
.badge__content
.badge__content-inner
.badge__value
span.badge__previous-value £0
span.badge__current-value £5
//- STARBURST
+starburst()
hr
h2 Progress from full
p Click to animate
.progress-badge.js-progress-badge
//- BADGE
.badge
.badge__fill
.badge__fill-inner
.badge__content
.badge__content-inner
.badge__value
span.badge__previous-value £5
span.badge__current-value £10
//- STARBURST
+starburst()
hr
h2 No change
.progress-badge
//- BADGE
.badge.badge--static
.badge__fill
.badge__fill-inner
.badge__content
.badge__content-inner
.badge__value
span.badge__previous-value £5
span.badge__current-value £10
//- STARBURST
+starburst()
//
// SETUP
//
$color--red = #ee4432
$color--white = #fff
//
// PROGRESS BADGE
// Contains badge and starburst
//
.progress-badge
position relative
display inline-block
//
// BADGE
//
$badge-size = 150px
$badge-fill-duration = 2000ms
$badge-wave-duration = 1000ms
$badge-pop-duration = 300ms
$badge-pop-delay = $badge-fill-duration - 100ms
$badge-full-inner-offset-1 = 5px
$badge-full-inner-offset-2 = 10px
$badge-empty-inner-offset-1 = 7px
$badge-empty-inner-offset-2 = 10px
.badge // Red
position relative
width $badge-size
height $badge-size
border-radius 50%
text-align center
display table
vertical-align middle
color $color--white
background $color--red
z-index 2
.is-filling &
animation badge-pop $badge-pop-duration cubic-bezier(0.6, 1.5, 0.8, 1.15) 1
.is-filling-from-empty &
animation-delay $badge-pop-delay
&:before,
&:after
position absolute
content ''
border-radius 50%
z-index 10
&:before
top $badge-full-inner-offset-1
right $badge-full-inner-offset-1
bottom $badge-full-inner-offset-1
left $badge-full-inner-offset-1
border 2px dotted $color--white
&:after
top $badge-full-inner-offset-2
right $badge-full-inner-offset-2
bottom $badge-full-inner-offset-2
left $badge-full-inner-offset-2
border 2px solid $color--white
.badge__content
display table-cell
vertical-align middle
.badge__content-inner
position relative
.badge__fill
position absolute
top -1px
right -1px
bottom -1px
left -1px
border-radius 50%
overflow hidden
z-index 0
.badge--static &:after
content ''
position absolute
top 0
right (- $badge-size / 3) // Avoid cutting corners off gradient
bottom 0
left (- $badge-size / 3) // Avoid cutting corners off gradient
background-image linear-gradient(-45deg, transparent 40%, $color--white 40%, $color--white 60%, transparent 60%)
background-repeat no-repeat
z-index 1
opacity 0.3
transform translateX($badge-size * -1)
animation badge-shine 700ms 500ms ease-in-out
.badge__fill-inner
position absolute
right 0
bottom -10px // Hides wave off-screen
left 0
top 0
background $color--red
transform translateY(100%)
will-change transform
&:before
content ''
position absolute
left 0
bottom 100%
margin-bottom -2px // Hide aliasing gap
width 400px
height 12px
background-repeat repeat-x
background-image url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iNDAwcHgiIGhlaWdodD0iMTJweCIgdmlld0JveD0iMCAwIDQwMCAxMiIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNDAwIDEyIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBmaWxsPSIjRUU0NDMyIiBkPSJNMzUwLDVjMCwwLTI0LTUtNDkuOC01QzI3NC4zLDAsMjUwLDUsMjUwLDVzLTIyLDUtNTAsNXMtNTAtNS01MC01cy0yNC01LTQ5LjgtNUM3NC4zLDAsNTAsNSw1MCw1cy0yMiw1LTUwLDV2Mmg0MDB2LTJDMzcyLDEwLDM1MCw1LDM1MCw1eiIvPjwvc3ZnPg==')
.badge__value
font-size rem(50)
line-height 1
.badge__previous-value
.is-filling &
animation badge-hide-previous-value 150ms linear 1 forwards
.is-filling-from-empty &
animation-delay $badge-fill-duration
.badge__current-value
display none
.is-filling &
animation badge-show-current-value 150ms linear 1 forwards
.is-filling-from-empty &
animation-delay $badge-fill-duration
.badge__label
font-size rem(14)
.badge--empty
color $color--red
border 4px solid $color--red
background $color--white
&:before
top $badge-empty-inner-offset-1
right $badge-empty-inner-offset-1
bottom $badge-empty-inner-offset-1
left $badge-empty-inner-offset-1
border 1px dotted $color--red
&:after
top $badge-empty-inner-offset-2
right $badge-empty-inner-offset-2
bottom $badge-empty-inner-offset-2
left $badge-empty-inner-offset-2
border 1px solid $color--red
.badge__fill-inner
.is-filling-from-empty &
animation badge-wave-fill $badge-fill-duration linear 1 forwards
will-change transform
.is-filling-from-empty &:before
animation badge-wave-move $badge-wave-duration linear 2 // Just enough loops to outlast the fill animation
@keyframes badge-shine
100%
transform translateX($badge-size)
@keyframes badge-wave-move
100%
transform translateX(-200px)
@keyframes badge-wave-fill
100%
transform translateY(0)
@keyframes badge-pop
50%
transform scale(0.5)
100%
transform scale(1)
@keyframes badge-hide-previous-value
0%
display block
opacity 1
100%
display none
opacity 0
@keyframes badge-show-current-value
0%
display none
opacity 0
100%
display block
opacity 1
//
// STARBURST
//
$starburst-duration = 1200ms
$starburst-delay = 150ms
.starburst
position absolute
top 50%
left 50%
transform translate(-12.5px, -30px)
z-index 1
.is-filling &
animation starburst-fall $starburst-duration $starburst-delay cubic-bezier(0, 0, 0.7, 0) 1
.is-filling-from-empty &
animation-delay 2000ms
.starburst__star
position absolute
.starburst__star-inner
width 25px
height 25px
background-size cover
background-image url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwIDIwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cG9seWdvbiBmaWxsPSIjRUY1NzQ3IiBwb2ludHM9IjEwLDAgMTMuMSw2LjYgMjAsNy42IDE1LDEyLjggMTYuMiwyMCAxMCwxNi42IDMuOCwyMCA1LDEyLjggMCw3LjYgNi45LDYuNiAiLz48L3N2Zz4=')
.is-filling &
animation star-move $starburst-duration $starburst-delay cubic-bezier(0, 0, 0.2, 0.8) 1
.is-filling-from-empty &
animation-delay 2000ms
@keyframes star-move
0%
transform translateX(0)
100%
transform translateX(300px)
@keyframes starburst-fall
0%
opacity 1
100%
opacity 0
transform translateY(30px)
//
// DEMO STYLES
//
*
box-sizing border-box
body
width 300px
margin 0 auto
padding rem(50) rem(25)
text-align center
font-family 'Oswald', sans-serif
hr
margin rem(30) 0
var $badges = $('.js-progress-badge')
, $window = $(window)
$badges.on('click', function () {
incrementBadge($(this))
})
function incrementBadge ($progressBadge) {
var $badge = $progressBadge.find('.badge')
, $badgeValue = $progressBadge.find('.js-badge-value')
, badgeValueTarget = $badgeValue.data('target')
, fillingFromEmpty = $badge.hasClass('badge--empty')
, $starburst = $progressBadge.find('.js-starburst')
$progressBadge.removeClass('badge--static')
$progressBadge.addClass('is-filling')
if (fillingFromEmpty) {
$progressBadge.addClass('is-filling-from-empty')
}
$progressBadge.on('animationend', function () {
$badge.addClass('badge--static badge--filled')
$badge.removeClass('badge--empty')
})
$starburst.on('animationend', function () {
$progressBadge.removeClass('is-filling is-filling-from-empty')
})
}
Also see: Tab Triggers