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.
<h2>Add-ons</h2>
<input class="checkbox-btn" name="checkbox-collection" id="checkbox-1" type="checkbox" value="49">
<label class="checkbox-label" for="checkbox-1" tabindex="1">
<span>
White-labeled Domain
<em>Use your own custom domain with SSL security included.</em>
</span>
<span>$49/mo</span>
</label>
<input class="checkbox-btn" name="checkbox-collection" id="checkbox-2" type="checkbox" value="49">
<label class="checkbox-label" for="checkbox-2" tabindex="2">
<span>
API Access
<em>Make API calls to perform custom serving and account actions.</em>
</span>
<span>$49/mo</span>
</label>
<input class="checkbox-btn" name="checkbox-collection" id="checkbox-3" type="checkbox" value="349">
<label class="checkbox-label" for="checkbox-3" tabindex="3">
<span>
Priority Support
<em>A dedicated account manager to assist your team with ongoing deployments.</em>
</span>
<span>$349/mo</span>
</label>
<div class="total-cost">
<h2>Your Plan</h2>
<div>
<span>$</span>
<span id="total-cost-inner">0</span>
<input id="output" type="text" value="0" disabled/>
<span>/mo</span>
</div>
</div>
/* Extra design fluff - not needed for main radio styling */
* {
box-sizing: border-box;
}
body {
background: lavender;
border-top: 10px solid mediumpurple;
font: 18px 'Avenir', 'Helvetica', sans-serif;
margin: 0 auto;
max-width: 800px;
padding: 2rem;
}
h2 {
margin-top: 0;
}
.checkbox-label {
align-items: center;
background-color: none;
border: 1px solid lightgrey;
border-radius: 5px;
cursor: pointer;
display: flex;
font-weight: 600;
justify-content: space-between;
margin: 0 auto 10px;
padding: 20px 20px 20px 70px;
position: relative;
transition: .3s ease all;
width: 100%;
}
.checkbox-label span:last-child {
padding: 0 0 0 20px;
}
.checkbox-label:hover {
background-color: rgba(255,255,255,0.2);
}
.checkbox-label:focus {
outline: dotted;
}
.checkbox-label:before {
background-repeat: no-repeat;
background-position: center;
background-size: 15px;
border: 1px solid lightgrey;
border-radius: 50%;
content:'';
height: 30px;
left: 20px;
position: absolute;
top: calc(50% - 15px);
transition: .3s ease background-color;
width: 30px;
}
.checkbox-label:hover:before {
background-image:
url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="23.571429" height="23.571429" viewBox="0.000000 -47.142857 23.571429 23.571429"><path fill="lightgrey" d="M23.571429 -36.964286L23.571429 -33.750000C23.571429 -33.303571 23.415179 -32.924107 23.102679 -32.611607C22.790179 -32.299107 22.410714 -32.142857 21.964286 -32.142857L15.000000 -32.142857L15.000000 -25.178571C15.000000 -24.732143 14.843750 -24.352679 14.531250 -24.040179C14.218750 -23.727679 13.839286 -23.571429 13.392857 -23.571429L10.178571 -23.571429C9.732143 -23.571429 9.352679 -23.727679 9.040179 -24.040179C8.727679 -24.352679 8.571429 -24.732143 8.571429 -25.178571L8.571429 -32.142857L1.607143 -32.142857C1.160714 -32.142857 0.781250 -32.299107 0.468750 -32.611607C0.156250 -32.924107 0.000000 -33.303571 0.000000 -33.750000L0.000000 -36.964286C0.000000 -37.410714 0.156250 -37.790179 0.468750 -38.102679C0.781250 -38.415179 1.160714 -38.571429 1.607143 -38.571429L8.571429 -38.571429L8.571429 -45.535714C8.571429 -45.982143 8.727679 -46.361607 9.040179 -46.674107C9.352679 -46.986607 9.732143 -47.142857 10.178571 -47.142857L13.392857 -47.142857C13.839286 -47.142857 14.218750 -46.986607 14.531250 -46.674107C14.843750 -46.361607 15.000000 -45.982143 15.000000 -45.535714L15.000000 -38.571429L21.964286 -38.571429C22.410714 -38.571429 22.790179 -38.415179 23.102679 -38.102679C23.415179 -37.790179 23.571429 -37.410714 23.571429 -36.964286ZM23.571429 -36.964286"></path></svg>');
}
.checkbox-label span {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.checkbox-label span em {
display: block;
font-size: 80%;
font-style: normal;
font-weight: 400;
line-height: 1.2;
}
.checkbox-btn {
position: absolute;
visibility: hidden;
}
.checkbox-btn:checked + .checkbox-label {
background-color: white;
border-color: mediumpurple;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.checkbox-btn:checked + .checkbox-label:before {
background-color: mediumpurple;
background-image:
url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="25.948661" height="19.888393" viewBox="2.025670 -40.011161 25.948661 19.888393"><path fill="white" d="M27.974330 -36.127232C27.974330 -35.680804 27.818080 -35.301339 27.505580 -34.988839L15.385045 -22.868304L13.108259 -20.591518C12.795759 -20.279018 12.416295 -20.122768 11.969866 -20.122768C11.523438 -20.122768 11.143973 -20.279018 10.831473 -20.591518L8.554688 -22.868304L2.494420 -28.928571C2.181920 -29.241071 2.025670 -29.620536 2.025670 -30.066964C2.025670 -30.513393 2.181920 -30.892857 2.494420 -31.205357L4.771205 -33.482143C5.083705 -33.794643 5.463170 -33.950893 5.909598 -33.950893C6.356027 -33.950893 6.735491 -33.794643 7.047991 -33.482143L11.969866 -28.543527L22.952009 -39.542411C23.264509 -39.854911 23.643973 -40.011161 24.090402 -40.011161C24.536830 -40.011161 24.916295 -39.854911 25.228795 -39.542411L27.505580 -37.265625C27.818080 -36.953125 27.974330 -36.573661 27.974330 -36.127232ZM27.974330 -36.127232"></path></svg>');
border-color: mediumpurple;
}
.total-cost {
align-items: baseline;
border-top: 1px solid lightgrey;
display: flex;
justify-content: space-between;
margin-top: 40px;
padding: 40px 20px 0;
}
.total-cost div {
align-items: baseline;
display: flex;
}
.total-cost span:nth-child(1) {
align-self: flex-start;
padding-top: 5px;
}
.total-cost span:nth-child(2) {
font-size: 32px;
font-weight: bold;
}
.total-cost input {
display: none;
}
@media(max-width:480px) {
.checkbox-label {
align-items: flex-start;
flex-direction: column;
flex-wrap: wrap;
}
.checkbox-label span:last-child {
padding: 10px 0 0 0;
}
}
window.onload=function(){
var inputs = document.getElementsByClassName('checkbox-btn')
for (var i=0; i < inputs.length; i++) {
inputs[i].onchange = function() {
var add = this.value * (this.checked ? 1 : -1);
var new_total = parseFloat(document.getElementById('output').value);
var updated_total = document.getElementById('output').value=new_total + add
document.getElementById('total-cost-inner').innerHTML = updated_total;
}
}
}
Also see: Tab Triggers