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.
<div class="button">
<input type="checkbox" id="liked"><label for="liked"><span></span></label>
</div>
/*#ff3c41*/
/*#444857*/
:root {
--u: 1.5vmin;
--clr: #777;
--bg: #444857;
}
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background-color: #131417;
background-image: linear-gradient(315deg, #131417 0%, #1e1f26 74%);
}
.button {
position: relative;
width: calc(var(--u) * 10);
height: calc(var(--u) * 10);
}
input { display: none; }
label {
background: var(--bg);
width: 100%;
height: 100%;
position: absolute;
border-radius: calc(var(--u) * 1.5);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
label:before {
content: "49";
position: absolute;
min-width: 50%;
left: 25%;
text-align: center;
top: 0;
bottom: 0;
background: var(--bg);
border-radius: calc(var(--u) * 2);
font-size: calc(var(--u) * 2);
font-family: Arial, Helvetica, serif;
padding: calc(var(--u) * 0.5);
box-sizing: border-box;
color: var(--clr);
line-height: calc(var(--u) * 2.25);
z-index: -1;
transition: all 0.5s ease 0s;
animation: counter-bot 1s ease 0s;
}
input:checked + label:before {
content: "50";
color: #fff;
background: #ff3c41;
bottom: inherit;
transition: all 0.5s ease 0s;
animation: counter-top 1s ease 0s;
}
@keyframes counter-top {
70% { top: calc(var(--u) * -4.75); }
}
@keyframes counter-bot {
70% {
top: inherit;
bottom: calc(var(--u) * -5);
}
}
label:after {
content: "";
width: calc(var(--u) * 8);
height: calc(var(--u) * 8);
position: absolute;
border-radius: 100%;
box-sizing: border-box;
z-index: -2;
animation: disc-gray 1s ease 0s, spin-gray 0.65s ease-in-out 0.25s;
transform: rotate(0deg);
--pos: 95%;
background:
radial-gradient(circle at 50% 50%, #fff0 0 62%, var(--bg) 63% 65%, #fff0 66% 100%),
radial-gradient(circle at 50% var(--pos), var(--bg) 0 4%, #fff0 4.5% 100%);
}
@keyframes spin-gray {
100% {
transform: rotate(-360deg);
}
}
@keyframes spin-red {
100% {
transform: rotate(360deg);
}
}
@keyframes disc-gray {
70% {
width: calc(var(--u) * 19);
height: calc(var(--u) * 19);
}
}
@keyframes disc-red {
70% {
width: calc(var(--u) * 19);
height: calc(var(--u) * 19);
}
}
input:checked + label:after {
--bg: #ff3c41;
--pos: 5%;
animation: disc-red 1s ease 0s, spin-red 0.65s ease-in-out 0.25s;
}
label span {
position: absolute;
width: 100%;
height: 100%;
animation: dislike 0.5s ease 0s;
}
/*
label span:before {
content: "";
width: 2px;
height: 2px;
position: absolute;
border-radius: calc(var(--u) * 5);
transform: translate(calc(var(--u) * 2.235), calc(var(--u) * 4.5));
border: calc(var(--u) * 2.71) solid transparent;
border-top: calc(var(--u) * 2.9) solid var(--clr);
}
label span:after {
content: "";
background:
radial-gradient(circle at 40% 45%, var(--clr) 0 calc(var(--u) * 1.25), #fff0 calc(var(--u) * 1.325) 100%),
radial-gradient(circle at 60% 45%, var(--clr) 0 calc(var(--u) * 1.25), #fff0 calc(var(--u) * 1.325) 100%);
width: 100%;
height: 100%;
position: absolute;
}
*/
label span:before {
content: "";
position: absolute;
border-radius: 0.25vmin;
border: 3.8vmin solid #fff0;
border-top: 4vmin solid var(--clr);
margin-top: 7.65vmin;
margin-left: 3.8vmin;
}
label span:after {
content: "";
position: absolute;
background: var(--clr);
width: 5vmin;
height: 5vmin;
border-radius: 100%;
margin-left: 3.35vmin;
margin-top: 3.5vmin;
box-shadow: 3.5vmin 0 0 0 var(--clr);
}
input:checked + label span {
--clr: #ff3c41;
animation: like 0.5s ease 0s;
}
@keyframes like {
75% { transform: scale(1.25); }
}
@keyframes dislike {
75% { transform: scale(0.75); }
}
.button:hover label span:before, .button:hover label span:after {
--clr: #9d4958;
}
.button:hover input:checked + label span:before, .button:hover input:checked + label span:after {
--clr: #ff3c41;
}
//Inpired by this pen from Jhey:
//https://codepen.io/jh3y/pen/bGYoEwX
Also see: Tab Triggers