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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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.
<form>
<h1>Customize Your Pizza</h1>
<div class="form-columns">
<div class="form-column">
<h2>Size</h2>
<label>
<input class="pristine" type="radio" name="size" value="small"> <span>Small <small>(10.00)</small></span>
</label>
<label>
<input class="pristine" type="radio" name="size" value="medium"> <span>Medium <small>(15.00)</small></span>
</label>
<label>
<input class="pristine" type="radio" name="size" value="large"> <span>Large <small>(20.00)</small></span>
</label>
</div>
<div class="form-column">
<h2>Toppings</h2>
<label>
<input class="pristine" type="checkbox" name="toppings" value="ham"> <span>Ham <small>(0.50)</small></span>
</label>
<label>
<input class="pristine" type="checkbox" name="toppings" value="pepperoni"> <span>Pepperoni <small>(0.50)</small></span>
</label>
<label>
<input class="pristine" type="checkbox" name="toppings" value="bacon"> <span>Bacon <small>(0.50)</small></span>
</label>
</div>
</div>
<div class="screen">
<span class="screen-value">0.00</span>
</div>
<button type="reset">
<span tabindex="-1">Order</span>
</button>
</form>
* {
border: 0;
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--animDur: 0.3s;
--transDur: 0.1s;
--buttonTiming: linear;
--checkboxTiming: linear;
--radioTiming: linear;
font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
}
body, button, input {
font: 1em/1.5 "Manjari", sans-serif;
}
body, label {
display: flex;
}
body {
background-color: #f48d25;
color: #17181c;
height: 100vh;
}
form {
background-color: #e3e4e8;
background-image:
linear-gradient(180deg,#0000,#0001),
radial-gradient(0.5em 0.5em at 0.75em 0.75em,#fff 25%,#fff0 50%),
radial-gradient(95% 0.75em at 50% 0.75em,#fff 25%,#fff0 50%);
border-radius: 1.5em;
box-shadow:
0 0.5em 0.5em #fff4 inset,
0 -0.25em 0.5em 0.25em #0007 inset,
0 0.5em 1.5em #0007;
margin: auto;
max-width: 24.5em;
padding: 1.5em;
width: calc(100% - 3em);
}
button, h2, label {
margin-bottom: 0.75em;
}
button, label {
-webkit-tap-highlight-color: transparent;
}
button, .screen {
margin-left: auto;
margin-right: auto;
}
h1, h2, input + span {
text-shadow: 0 0 0.25em #0004;
}
h1, .screen {
font-size: 1.5em;
line-height: 1;
}
h1 {
margin-bottom: 0.75rem;
padding-top: 0.75rem;
text-align: center;
}
h2 {
font-size: 1em;
}
label {
align-items: center;
flex-wrap: wrap;
position: relative;
}
small {
font-size: 0.75em;
vertical-align: middle;
}
.form-columns {
display: grid;
grid-gap: 1.5em;
grid-template-columns: repeat(auto-fit,minmax(10em,1fr));
margin-bottom: 1.5em;
}
.screen {
background-image: linear-gradient(180deg,#9aa38f,#8d9781);
border-radius: 0.25rem;
box-shadow:
0 -0.25rem 0.25rem #0004,
0 0.25rem 0.25rem #fff4,
0 0.25rem 0.25rem #0007 inset;
font-family: "VT323", monospace;
margin-bottom: 2rem;
padding: 0.5rem 0.75rem;
max-width: 6.5rem;
}
.screen-value {
display: inline-block;
text-align: right;
text-shadow: 0.1rem 0.1rem 0.1rem #0004;
text-transform: uppercase;
width: 100%;
}
.fade-in {
animation: valueFadeIn 0.05s linear;
}
/* All */
button:focus, button span:focus, input:focus {
outline: transparent;
}
input:focus + span {
color: #db0b0b;
text-shadow: 0 0 0.25em #db0b0b44;
}
button, input[type=checkbox], input[type=radio], label {
cursor: pointer;
}
input[type=checkbox], input[type=checkbox]:before, input[type=checkbox]:after,
input[type=radio], input[type=radio]:before, input[type=radio]:after {
width: 2.25rem;
}
button, input[type=checkbox], input[type=checkbox]:before,
input[type=radio], input[type=radio]:before, input[type=radio]:after {
height: 2.25rem;
}
input[type=checkbox], input[type=radio] {
margin-right: 0.75em;
-webkit-appearance: none;
appearance: none;
}
input[type=checkbox]:before, input[type=checkbox]:after,
input[type=radio]:before, input[type=radio]:after {
display: block;
position: absolute;
top: 0;
left: 0;
}
input[type=checkbox]:before,
input[type=radio]:before, input[type=radio]:after {
content: "";
}
/* Buttons */
button {
background-color: #db0b0b;
background-image:
linear-gradient(180deg,#0000,#0002),
radial-gradient(90% 7% at 50% 8%,#fff7 25%,#fff0 50%);
box-shadow:
0.25em 0.25em 0.5em #0007,
0 -0.1em 0 0.1em #0004,
0 0.1em 0 0.1em #fff4,
-0.25rem 0 0.25rem #aa0909 inset,
0 0.25rem 0.25rem #fff4 inset,
0.25rem 0 0.25rem #fff4 inset,
0 -0.25rem 0.25rem #aa0909 inset;
border-radius: 1.125em;
color: #fff;
display: block;
text-shadow: 0 0 0.25em #fff7;
transition: box-shadow var(--transDur) var(--buttonTiming);
max-width: 14rem;
width: 100%;
}
button span {
display: block;
padding: 0.5em;
transition: transform var(--transDur) var(--buttonTiming);
}
button:active {
box-shadow:
0 0 0 #0007,
0 -0.1em 0 0.1em #0004,
0 0.1em 0 0.1em #fff4,
-0.25rem 0 0.25rem #7a0606 inset,
0 0.25rem 0.25rem #0004 inset,
0.25rem 0 0.25rem #0004 inset,
0 -0.25rem 0.25rem #7a0606 inset;
}
button:active span {
transform: scale(0.95);
}
button:focus {
color: #fbb7b7;
text-shadow: 0 0 0.25em #fbb7b777;
}
/* Checkboxes */
input[type=checkbox] {
animation: checkboxFlipFalse var(--animDur) var(--checkboxTiming);
box-shadow:
0.25em 0.25em 0.5em #0007,
0 -0.1em 0 0.1em #0004,
0 0.75em 0.5em 0.25em #0003 inset,
0 0.1em 0 0.1em #fff4;
}
input[type=checkbox]:checked {
animation: checkboxFlipTrue var(--animDur) var(--checkboxTiming);
}
input[type=checkbox]:before, input[type=checkbox]:after {
background-color: #db0b0b;
}
input[type=checkbox]:before {
animation: checkboxFlipFalseBefore var(--animDur) var(--checkboxTiming);
background-image:
linear-gradient(180deg,#0000,#0002),
radial-gradient(7% 7% at 8% 8%,#fff7 37.5%,#fff0 50%),
radial-gradient(90% 7% at 50% 8%,#fff7 25%,#fff0 50%);
box-shadow:
-0.25rem 0 0.25rem #920707 inset,
0 0.25rem 0.25rem #fff4 inset,
0.25rem 0 0.25rem #fff4 inset,
0 -0.25rem 0.25rem #920707 inset;
color: #0000;
content: "\2713";
font-size: 2.25em;
text-align: center;
text-shadow: 0 0 0.25rem #0000;
transform: translateZ(0.5rem);
}
input[type=checkbox]:checked:before {
animation: checkboxFlipTrueBefore var(--animDur) var(--checkboxTiming);
color: #fff;
text-shadow: 0 0 0.25rem #fffa;
}
input[type=checkbox]:after {
animation: checkboxFlipFalseAfter var(--animDur) var(--checkboxTiming);
box-shadow:
0.25rem 0 0.25rem #fff3 inset,
0 0.25rem 0.25rem #aa0909 inset,
-0.25rem 0 0.25rem #aa0909 inset;
content: "";
height: 1rem;
transform: translateY(1rem) rotateX(-90deg) translateZ(1.5rem);
}
input[type=checkbox]:checked:after {
animation: checkboxFlipTrueAfter var(--animDur) var(--checkboxTiming);
}
/* Radios */
input[type=radio], input[type=radio]:before, input[type=radio]:after {
border-radius: 50%;
}
input[type=radio] {
box-shadow:
0.25em 0.25em 0.5em #0007,
0 -0.1em 0 0.1em #0004,
0 0.1em 0 0.1em #fff4,
0 0 1.5em #0004 inset;
transition: box-shadow var(--animDur) var(--radioTiming);
}
input[type=radio]:checked {
box-shadow:
0.25em 0.25em 1em #0000,
0 -0.1em 0 0.1em #0004,
0 0.1em 0 0.1em #fff7,
0 0 1.5em #0004 inset;
}
input[type=radio]:before, input[type=radio]:after {
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
input[type=radio]:before {
animation: radioFlipFalseBefore var(--animDur) var(--radioTiming);
background:
linear-gradient(#0000 25%,#0004 75%),
radial-gradient(50% 100% at 15% 50%,#aa0909 8%,#aa090900 24%),
radial-gradient(50% 100% at 85% 50%,#aa0909 8%,#aa090900 24%),
radial-gradient(100% 100% at center,#e90b0b00 41%,#e90b0b 46%),
radial-gradient(100% 100% at center,#c20a0a00 36%,#c20a0a 38%),
radial-gradient(100% 100% at 22% 38%,#fff4 6%,#fff0 12%),
radial-gradient(100% 100% at 35% 25%,#fff4,#fff0 13%),
radial-gradient(120% 100% at 50% 20%,#fff2,#fff0 13%),
radial-gradient(100% 100% at 40% 40%,#fff4 4%,#fff0 12%),
radial-gradient(100% 100% at 65% 20%,#fff4 4%,#fff0 12%),
radial-gradient(100% 100% at 75% 33%,#fff4 6%,#fff0 12%),
radial-gradient(100% 100% at center,#ee0c0c 13%,#db0b0b 25% 49%,#db0b0b00 50%);
background-position: 0 0;
background-repeat: no-repeat;
background-size: 2.25em 2.25em;
}
input[type=radio]:checked:before {
animation: radioFlipTrueBefore var(--animDur) var(--radioTiming);
border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;
height: 1.125em;
}
input[type=radio]:after {
animation: radioFlipFalseAfter var(--animDur) var(--radioTiming);
background-color: #fff;
background-image:
radial-gradient(2.25rem 2.25rem at 1.125rem 1.175rem,#fff0 0.905rem,#fff1 0.925rem),
radial-gradient(2.25rem 2.25rem at 1.125rem 1.075rem,#0000 0.905rem,#0003 0.925rem),
radial-gradient(2.25rem 2.25rem at center,#db0b0b00 0.605rem,#db0b0b 0.625rem),
radial-gradient(2.25rem 2.25rem at 1.125rem 1.225rem,#0000 0.555rem,#0003 0.575rem),
radial-gradient(2.25rem 2.25rem at 1.125rem 1.025rem,#fff0 0.555rem,#fff3 0.575rem),
radial-gradient(2.25rem 2.25rem at center,#db0b0b00 0.455rem,#db0b0b 0.475rem),
radial-gradient(2.25rem 2.25rem at 1.325rem 1.325rem,#0000 0.475rem,#0003 0.675rem);
filter: brightness(0.1);
-webkit-filter: brightness(0.1);
transform: rotateX(-180deg);
}
input[type=radio]:checked:after {
animation: radioFlipTrueAfter var(--animDur) var(--radioTiming);
filter: brightness(1);
-webkit-filter: brightness(1);
transform: rotateX(0);
}
input[type=checkbox].pristine,
input[type=checkbox].pristine:before, input[type=checkbox].pristine:after,
input[type=radio].pristine:before, input[type=radio].pristine:after {
animation-name: none;
}
/* Animations */
@keyframes checkboxFlipTrue {
from, to {
box-shadow:
0.25em 0.25em 0.5em #0007,
0 -0.1em 0 0.1em #0004,
0 0.75em 0.5em 0.25em #0003 inset,
0 0.1em 0 0.1em #fff4;
}
50% {
box-shadow:
0.25em 0.25em 1em #0000,
0 -0.1em 0 0.1em #0004,
0 0.75em 0.5em 0.25em #0003 inset,
0 0.1em 0 0.1em #fff4;
}
}
@keyframes checkboxFlipFalse {
from, to {
box-shadow:
0.25em 0.25em 0.5em #0007,
0 -0.1em 0 0.1em #0004,
0 0.75em 0.5em 0.25em #0003 inset,
0 0.1em 0 0.1em #fff4;
}
50% {
box-shadow:
0.25em 0.25em 1em #0000,
0 -0.1em 0 0.1em #0004,
0 0.75em 0.5em 0.25em #0003 inset,
0 0.1em 0 0.1em #fff4;
}
}
@keyframes checkboxFlipTrueBefore {
from {
color: #0000;
filter: brightness(1);
-webkit-filter: brightness(1);
text-shadow: 0 0 0.25rem #0000;
transform: rotateX(0deg) translateZ(0.5rem);
}
50% {
color: #0000;
filter: brightness(0.55);
-webkit-filter: brightness(0.55);
text-shadow: 0 0 0.25rem #0000;
transform: rotateX(90deg) translateZ(0.5rem);
}
50.1% {
color: #fff;
filter: brightness(0.55);
-webkit-filter: brightness(0.55);
text-shadow: 0 0 0.25rem #fffa;
transform: rotateX(-90deg) translateZ(0.5rem);
}
to {
color: #fff;
filter: brightness(1);
-webkit-filter: brightness(1);
text-shadow: 0 0 0.25rem #fffa;
transform: rotateX(0deg) translateZ(0.5rem);
}
}
@keyframes checkboxFlipFalseBefore {
from {
color: #fff;
filter: brightness(1);
-webkit-filter: brightness(1);
text-shadow: 0 0 0.25rem #fffa;
transform: rotateX(0deg) translateZ(0.5rem);
}
50% {
color: #fff;
filter: brightness(0.55);
-webkit-filter: brightness(0.55);
text-shadow: 0 0 0.25rem #fffa;
transform: rotateX(90deg) translateZ(0.5rem);
}
50.1% {
color: #0000;
filter: brightness(0.55);
-webkit-filter: brightness(0.55);
text-shadow: 0 0 0.25rem #0000;
transform: rotateX(-90deg) translateZ(0.5rem);
}
to {
color: #0000;
filter: brightness(1);
-webkit-filter: brightness(1);
text-shadow: 0 0 0.25rem #0000;
transform: rotateX(0deg) translateZ(0.5rem);
}
}
@keyframes checkboxFlipTrueAfter {
from {
filter: brightness(0.775);
-webkit-filter: brightness(0.775);
transform: translateY(0.625rem) rotateX(-90deg) translateZ(1.125rem);
}
50% {
filter: brightness(1);
-webkit-filter: brightness(1);
transform: translateY(0.625rem) rotateX(0deg) translateZ(1.125rem);
}
to {
filter: brightness(0.775);
-webkit-filter: brightness(0.775);
transform: translateY(0.625rem) rotateX(90deg) translateZ(1.125rem);
}
}
@keyframes checkboxFlipFalseAfter {
from {
filter: brightness(0.775);
-webkit-filter: brightness(0.775);
transform: translateY(0.625rem) rotateX(-90deg) translateZ(1.125rem);
}
50% {
filter: brightness(1);
-webkit-filter: brightness(1);
transform: translateY(0.625rem) rotateX(0deg) translateZ(1.125rem);
}
to {
filter: brightness(0.775);
-webkit-filter: brightness(0.775);
transform: translateY(0.625rem) rotateX(90deg) translateZ(1.125rem);
}
}
@keyframes radioFlipTrueBefore {
from {
border-radius: 50%;
height: 2.25rem;
}
50%, to {
border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;
height: 1.125rem;
}
}
@keyframes radioFlipFalseBefore {
from, 50% {
background-position: 0 100%;
border-radius: 50% 50% 50% 50% / 0% 0% 100% 100%;
height: 1.125rem;
transform: translateY(1.125rem);
}
to {
background-position: 0 100%;
border-radius: 50%;
height: 2.25rem;
transform: translateY(0);
}
}
@keyframes radioFlipTrueAfter {
from {
filter: brightness(0.1);
-webkit-filter: brightness(0.1);
transform: rotateX(-180deg);
}
to {
filter: brightness(1);
-webkit-filter: brightness(1);
transform: rotateX(0);
}
}
@keyframes radioFlipFalseAfter {
from {
filter: brightness(1);
-webkit-filter: brightness(1);
transform: rotateX(0);
}
to {
filter: brightness(0.1);
-webkit-filter: brightness(0.1);
transform: rotateX(180deg);
}
}
@keyframes valueFadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
document.addEventListener("DOMContentLoaded",() => {
let toyForm = new ToyForm();
});
class ToyForm {
constructor() {
let form = document.forms[0];
this.screen = form.querySelector(".screen-value");
form.addEventListener("change",this.calcPrice.bind(this));
form.addEventListener("reset",this.updatePrice.bind(this,0));
form.reset();
}
calcPrice(e) {
let inputs = document.querySelectorAll("[name='size'],[name='toppings']"),
items = [
{
name: "small",
price: 10
},
{
name: "medium",
price: 15
},
{
name: "large",
price: 20
},
{
name: "ham",
price: 0.5
},
{
name: "pepperoni",
price: 0.5
},
{
name: "bacon",
price: 0.5
}
],
totalPrice = 0;
// remove the target’s `pristine` class, which prevents the CSS animation on load
if (e && e.target.classList.contains("pristine"))
e.target.removeAttribute("class");
// calculate the price
inputs.forEach(i => {
if (i.checked) {
let selectedItem = items.find(I => I.name == i.value);
if (selectedItem)
totalPrice += selectedItem.price;
}
});
this.updatePrice(totalPrice);
}
updatePrice(value) {
let fadeInClass = "fade-in",
screenCL = this.screen.classList;
this.screen.textContent = value < 1e5 ? value.toFixed(2) : "Overflow";
// replay CSS animation
screenCL.remove(fadeInClass);
void this.screen.offsetWidth;
setTimeout(() => {
screenCL.add(fadeInClass);
},0);
}
}
Also see: Tab Triggers