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.
.output
#wrapper.wrapper
#circle.circle
.counter
span.text
img#trophy(alt="trophy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAVLUlEQVR4Ae2aCXRU5Rn3nyyEACELWSYzc2fJQkKALAm7gPsHuFQREIRW60IXtbWVU+1XsWq1LrRSbW0VtUeEKruWsCeELJllshN2NFD2xWBkAcky973P97937pmEKSEEsdjTb875nXszy73v83//7/M89wVi5v9p9BMca6OJF9iI63HuBl+CD4KJ51iIKYSOTSH6Svs+OArWgmpwELwPasFWokJ8r35WD+KzwXRqWV86v8lGosoc7v0kMV1+O364sso+zltkndG8zjKtZX1HpOmiKGmKskga6303doh3o8nIm01Bx/INVJsfRrylB62dEEx73iDiJlCgj7MRMNgBjvnOj+wmOkc4z4wlfsdAXIrzI8ABPL2JVyYDw1US4BCYB5xgRw86uqAfnS43hnOJ6ZbWooQ5ssOySSk37xP1Fq/Ya2NRYWalzMzCeRFKTSy2SCz2qN+TzrDbXN9cZlzSlJ/wC3Zb0o5uMNCpRRHEh4l4DXB+FwTYR0EiP4SaV8dQs9PcX6lPmqN4pD1ep8SKx8Ki3AQQnKMD5Z0Q8B0vhFJwHa62slxukpVaW5G3yv7g+U2GMKW0j+/+x66FAMdAPqgIJd7dl1ochphWl/0NxS21CI/EXgTgLdUCwMB1ynx4VfT3AtG+rxLwHf+1VJfg+rLL2iAq7ffIGzHmr74NAVy6AG8EEb+O94LD6cgjIe0CHAZFRM0FJhKbB/8fdpoaFQ8GqAeuImszamEFR3ZbWbjgBrdZBueUEutxb5F9n3eTfT/QkIvsB5RySxM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EAAAAAElFTkSuQmCC")
.input
pre.code-block
| .wrapper {
| background: #8BC34A
span.color.orange
|;
| color: #FFFFFF
span.color.white
| ;
textarea#wrapper_code.code(placeholder="Put CSS here" spellcheck="false")
|
| }
// .circle == .block
pre.code-block
| .circle {
| background: #424242
span.color.gray
| ;
| border-radius: 50%;
textarea#block_code.code(placeholder="Put CSS here" spellcheck="false")
|
| }
=mq($bp)
@if $bp == s
@media (max-width: 500px)
@content
@else if $bp == l
@media (min-width: 1201px)
@content
$bezier: cubic-bezier(0.175, 0.885, 0.32, 1.275)
$orange: #FF5722
$green: #8BC34A
$gray: #424242
$cross: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAE9JREFUeNrs17ENACAIBEB1WWdiWrRwAy2IuW/oyOUr6JnZHibOnK8WjlY8gICAgICAgICAgKXT98kfGrxs0NMECAgICAgICAgI+C1wCTAAl9UL3o6lLWgAAAAASUVORK5CYII='
p, textarea
margin: 0
padding: 0
html
box-sizing: border-box
*, *::after, *::before
box-sizing: inherit
.output
width: 100vw
height: 60vh
+mq(l)
position: absolute
right: 0
top: 0
height: 100vh
width: 60vw
&.correct
#wrapper
background-position: 50% 50%, 0 0 !important
#circle
&::before
content: "good job!"
color: $green
&::after
opacity: 1
transform: scale(1)
.counter
opacity: 1
transform: translate(-50%, 0%)
.input
width: 100vw
min-height: 40vh
display: flex
padding: 2em 0
+mq(s)
min-height: none
flex-direction: column
+mq(l)
flex-direction: column
justify-content: center
min-width: 300px
width: 40vw
height: 100vh
padding: 0 2em
background: white
#wrapper
width: 100% !important
height: 100% !important
background: url($cross) 50% 50% no-repeat, linear-gradient(120deg, $green 50%, $orange 50%) 100% 0 no-repeat !important
background-size: 40px 40px, 300% 100% !important
transition: background 0.5s 0.25s !important
#circle
width: 100px !important
height: 100px !important
background: $gray !important
border-radius: 50% !important
text-align: center !important
line-height: 100px !important
&::before
content: "center me!"
position: relative
z-index: 2
color: white
transition: color 0.5s
&::after
content: ""
position: absolute
left: 0
top: 0
z-index: 1
width: 100%
height: 100%
border-radius: 50%
background: white
opacity: 0
transform: scale(0)
transition: 1s $bezier
.circle
position: relative
.counter
position: absolute
bottom: 110%
left: 50%
min-width: 200px
padding: 0.8em 1em
background: white
border-radius: 5px
color: $green
line-height: 1 !important
text-align: center
opacity: 0
transform: translate(-50%, 50%) scale(1.5, 0.5)
transition: all 0.5s 0.25s $bezier
&:after
content: ""
position: absolute
left: 50%
bottom: -10px
width: 15px
height: 15px
background: inherit
transform: rotate(45deg) translate(-50%, 0)
#trophy
display: block
margin: 5px auto 0
&.silver
-webkit-filter: grayscale(100%) brightness(1.1)
filter: grayscale(100%) brightness(1.1)
&.bronze
-webkit-filter: hue-rotate(-35deg) contrast(90%) saturate(90%)
filter: hue-rotate(-35deg) contrast(90%) saturate(90%)
.code-block
flex: 1
height: 100%
padding: 0 1em
margin: 0
+mq(s)
height: auto
flex: none
&:first-child
margin-bottom: 2em
+mq(l)
height: auto
flex: none
padding: 0
&:first-child
margin-bottom: 2em
.code
outline: none
resize: none
border: 0
display: block
height: 6.4em
width: 100%
background: #f2f2f2
padding: 0.2em 1.2em
transition: 0.5s
&:focus
background: #FFECB3
.color
display: inline-block
margin: 0 0.2em
width: 0.8em
height: 0.8em
border-radius: 3px
vertical-align: -0.05em
&.orange
background: $orange
&.gray
background: $gray
&.white
background: white
border: 1px solid #CCC
$.fn.getCenter = function() {
let offset = $(this).offset(),
size = {width: $(this).width(), height: $(this).height()};
return {
x: Math.round(size.width / 2 + offset.left),
y: Math.round(size.height / 2 + offset.top)
};
};
$.fn.setStyleTo = function($el, cb = null) {
let val = $(this).val(),
styles = val.replace(/\n|\s(!important)/ig, "");
if (typeof cb === "function") cb(val);
$el.attr("style", styles);
return this;
};
var center, blockCenter, timer,
startTime = null;
const $output = $(".output"),
$wrapperCode = $("#wrapper_code"),
$blockCode = $("#block_code"),
$textareas = $("#wrapper_code, #block_code"),
$wrapper = $(".wrapper"),
$circle = $(".circle"),
$counter = $(".counter"),
$$trophy = document.getElementById("trophy"),
timeout = 500,
maxTimer = 120,
midTimer = 60;
const watchTableCellProperty = function(val) {
if (val.indexOf("table-cell") > -1) {
$output.css('display', 'table');
} else {
$output.removeAttr('style');
}
};
const isCenterAligned = (p1, p2) => {
return Math.abs(p1.x - p2.x) < 2 && Math.abs(p1.y - p2.y) < 2
}
const showSuccess = () => {
let totalTime = ((new Date() - startTime - timeout) / 1000).toFixed(2);
if (totalTime > maxTimer) {
console.log(maxTimer)
$$trophy.className = "bronze";
} else if (totalTime > midTimer) {
$$trophy.className = "silver";
} else {
$$trophy.className = "";
}
startTime = null;
$textareas.trigger("blur");
$output.addClass("correct");
$counter.find('.text').text(`Completed in ${totalTime}s!`);
};
const syncStyles = () => {
$wrapperCode.setStyleTo($wrapper, watchTableCellProperty);
$blockCode.setStyleTo($circle);
blockCenter = $circle.getCenter();
center = $wrapper.getCenter();
if (isCenterAligned(center, blockCenter)) {
showSuccess();
}
};
const refreshTimer = (cb) => {
clearTimeout(timer);
timer = setTimeout(cb, timeout);
};
const init = () => {
if (startTime === null) {
$textareas.val("");
$output.removeClass("correct");
$wrapper.removeAttr("style");
$circle.removeAttr("style");
startTime = new Date();
}
}
$textareas.on("input", () => refreshTimer(syncStyles));
$textareas.on("focus", init);
Also see: Tab Triggers