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="Container">
<div class="grid-full">
<div class="Rating Rating__large">
<span class="Rating_label">Rating</span>
<div class="Rating_input">
<input id="Rating5" name="rating" type="radio" value="5" />
<label for="Rating5"><div></div></label>
<input id="Rating4" name="rating" type="radio" value="4" />
<label for="Rating4"><div></div></label>
<input id="Rating3" name="rating" type="radio" value="3" checked />
<label for="Rating3"><div></div></label>
<input id="Rating2" name="rating" type="radio" value="2" />
<label for="Rating2"><div></div></label>
<input id="Rating1" name="rating" type="radio" value="1" />
<label for="Rating1"><div></div></label>
</div>
</div>
<div class="Rating">
<span class="Rating_label">Rating</span>
<div class="Rating_input">
<input id="Rating15" name="rating2" type="radio" value="10" />
<label for="Rating15"><div></div></label>
<input id="Rating14" name="rating2" type="radio" value="9" />
<label for="Rating14"><div></div></label>
<input id="Rating13" name="rating2" type="radio" value="8" />
<label for="Rating13"><div></div></label>
<input id="Rating12" name="rating2" type="radio" value="7" />
<label for="Rating12"><div></div></label>
<input id="Rating11" name="rating2" type="radio" value="6" />
<label for="Rating11"><div></div></label>
<input id="Rating10" name="rating2" type="radio" value="5" />
<label for="Rating10"><div></div></label>
<input id="Rating9" name="rating2" type="radio" value="4" />
<label for="Rating9"><div></div></label>
<input id="Rating8" name="rating2" type="radio" value="3" />
<label for="Rating8"><div></div></label>
<input id="Rating7" name="rating2" type="radio" value="2" />
<label for="Rating7"><div></div></label>
<input id="Rating6" name="rating2" type="radio" value="1" />
<label for="Rating6"><div></div></label>
</div>
</div>
</div>
<div class="grid-full">
<div class="Range Range__large">
<input id="RangeLarge" name="RangeLarge" type="range" min="0" max="100" step="1" value="50" />
<label for="RangeLarge">Range</label>
</div>
<div class="Range_row">
<div class="Range">
<input id="Range1" name="Range1" type="range" min="0" max="100" step="1" value="0" />
<label for="Range1">Range</label>
</div>
<div class="Range">
<input id="Range2" name="Range2" type="range" min="0" max="100" step="1" value="100" />
<label for="Range2">Range</label>
</div>
</div>
</div>
<div>
<div class="Toggle Toggle__large">
<input id="CheckboxLarge" name="checkboxLarge" type="checkbox" />
<label for="CheckboxLarge">Toggles</label>
</div>
<div class="Toggle">
<input id="Checkbox1" name="checkbox1" type="checkbox" />
<label for="Checkbox1">Bubble 1</label>
</div>
<div class="Toggle">
<input id="Checkbox2" name="checkbox2" type="checkbox" checked/>
<label for="Checkbox2">Bubble 2</label>
</div>
</div>
<div>
<div class="Radio Radio__large">
<input id="RadioLarge" name="radio" type="radio" value="" checked />
<label for="RadioLarge">Radio</label>
</div>
<div class="Radio">
<input id="Radio1" name="radio" type="radio" value="radio1" />
<label for="Radio1">Bubble 1</label>
</div>
<div class="Radio">
<input id="Radio2" name="radio" type="radio" value="radio2" />
<label for="Radio2">Bubble 2</label>
</div>
</div>
<div>
<div class="Color Color__large">
<input id="ColorLarge" name="color" type="color" value="#ffffff" />
<label for="ColorLarge">Color</label>
</div>
</div>
<div>
<div class="File">
<input id="File" name="file" type="file" />
<label for="File">Select or drag a file...</label>
</div>
</div>
</div>
<a class="Me" href="https://bio.link/jordandey" target="_top">Pen by Jordan Dey</a>
.Container {
display: grid;
gap: 1rem;
max-height: 100vh;
overflow: auto;
padding: 3rem 4rem;
border-radius: .5rem;
box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
@media (min-width: 712px) {
grid-template-columns: repeat(2, clamp(20vw, 20rem, 50vw));
}
}
/* ----------------
Global input
---------------- */
.Toggle input[type="checkbox"],
.Radio input[type="radio"],
.Rating input[type="radio"] {
position: absolute;
left: -100vw;
}
.Toggle input[type="checkbox"] + label,
.Radio input[type="radio"] + label,
.Rating input[type="radio"] + label {
position: relative;
display: block;
line-height: 3rem;
cursor: pointer;
white-space: nowrap;
}
.Toggle input[type="checkbox"] + label::before,
.Toggle input[type="checkbox"] + label::after,
.Radio input[type="radio"] + label::before,
.Radio input[type="radio"] + label::after,
.Rating input[type="radio"] + label::before,
.Rating input[type="radio"] + label::after {
content: '';
display: inline-block;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
transition: .5s;
}
/* large */
.Color__large input[type="color"] + label,
.Toggle__large input[type="checkbox"] + label,
.Radio__large input[type="radio"] + label,
.Range__large input[type="range"] + label,
.Rating__large .Rating_label {
font-size: 2rem;
line-height: 6rem;
}
/* ----------------
File input
---------------- */
.File {
position: relative;
text-align: center;
background: #eee;
border-radius: 1rem;
}
.File input[type="file"] {
position: absolute;
inset: 0;
text-align: center;
padding: 4rem 3rem 0 3rem;
}
.File input[type="file"]::file-selector-button {
display: none;
}
.File input[type="file"] + label {
display: block;
padding: 2rem 3rem 4rem 3rem;
height: auto;
cursor: pointer;
}
.File input[type="file"] + label::before {
pointer-events: none;
}
/* ----------------
Color input
---------------- */
.Color,
.Color > * {
cursor: pointer;
}
.Color input[type="color"] {
display: inline-block;
vertical-align: middle;
width: 2rem;
height: 2rem;
border: none;
border-radius: 50%;
}
.Color input[type="color"]::-webkit-color-swatch {
width: 1.3rem;
height: 1.3rem;
}
.Color input[type="color"] + label {
vertical-align: middle;
margin-left: 1rem;
}
/* Color large */
.Color__large input[type="color"] {
width: 4rem;
height: 4rem;
}
.Color__large input[type="color"]::-webkit-color-swatch {
width: 3.3rem;
height: 3.3rem;
}
/* ----------------
Rating input
---------------- */
.Rating .Rating_label {
display: block;
line-height: 1.3;
margin-bottom: .3rem;
}
.Rating_input {
display: flex;
justify-content: space-evenly;
flex-direction: row-reverse;
max-width: 30rem;
margin: auto;
margin-bottom: 1rem;
}
.Rating input[type="radio"] + label {
width: 2rem;
aspect-ratio: 1 / 1;
}
.Rating input[type="radio"] + label::before {
content: "★";
width: 2rem;
aspect-ratio: 1 / 1;
border-radius: 50%;
background: #eee;
color: #fff;
text-align: center;
font-size: 2rem;
line-height: 2rem;
}
.Rating input[type="radio"] + label::after {
left: .2rem;
width: 1.4rem;
transform: translateY(-50%) scale(0);
}
.Rating input[type="radio"]:checked ~ label::after {
animation: rating 2s linear infinite;
}
.Rating input[type="radio"] ~ label > div::before,
.Rating input[type="radio"] ~ label > div::after {
content: "";
position: absolute;
width: 0;
aspect-ratio: 1 / 1;
border-radius: 50%;
transform: translate(-50%, -50%);
transition: .5s;
}
.Rating input[type="radio"]:checked ~ label > div::before {
top: 10%;
width: 33%;
animation: ratingBubbles 2s linear infinite;
}
.Rating input[type="radio"]:checked ~ label > div::after {
top: 40%;
left: 100%;
width: 33%;
animation: ratingBubbles 2s linear reverse infinite;
}
.Rating input[type="radio"]:checked ~ label::before {
font-size: 0;
}
.Rating input[type="radio"]:checked ~ label::after {
transform: translateY(-50%) scale(1);
}
/* Rating large */
.Rating__large input[type="radio"] + label,
.Rating__large input[type="radio"] + label::before {
width: 4rem;
font-size: 4rem;
line-height: 4rem;
}
.Rating__large input[type="radio"] + label::after {
left: .4rem;
width: 3rem;
}
/* ----------------
Range input
---------------- */
.Range {
display: flex;
flex-direction: column-reverse;
margin-bottom: 1rem;
}
.Range input[type="range"] + label {
display: block;
line-height: 1.3;
margin-bottom: .3rem;
}
.Range input[type="range"] {
appearance: none;
height: 2rem;
border-radius: 1rem;
padding: .5rem;
background: #eee;
cursor: pointer;
}
.Range input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 1.4rem;
height: 1.4rem;
cursor: pointer;
transition: .5s;
transition-timing-function: cubic-bezier(.73,2,.25,-0.7);
}
// For Firfox support
// Can't be fusioned with previous selector...
.Range input[type="range"]::-moz-range-thumb {
appearance: none;
width: 1.4rem;
height: 1.4rem;
cursor: pointer;
transition: .5s;
}
.Range input[type="range"]:active::-webkit-slider-thumb {
transition-timing-function: linear;
transform: scale(1.3, 0.7);
}
.Range input[type="range"]:active::-moz-range-thumb {
animation: none;
transform: scale(1.3, 0.7);
}
.Range_row {
@media (min-width: 712px) {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
.Range {
width: calc(50% - .5rem);
margin-bottom: 0;
}
}
}
/* Toggle large */
.Range__large input[type="range"] {
height: 4rem;
border-radius: 2rem;
}
.Range__large input[type="range"]::-webkit-slider-thumb {
width: 3rem;
height: 3rem;
}
.Range__large input[type="range"]::-moz-range-thumb {
width: 3rem;
height: 3rem;
}
/* ----------------
Toggles input
---------------- */
.Toggle input[type="checkbox"] + label {
padding-left: 5rem;
}
.Toggle input[type="checkbox"] + label::before {
width: 4rem;
aspect-ratio: 2 / 1;
border-radius: 1rem;
background: #eee;
}
.Toggle input[type="checkbox"]:checked + label::before {
background: #ddf8eb;
}
.Toggle input[type="checkbox"] + label::after {
left: .25rem;
width: 1.4rem;
}
.Toggle input[type="checkbox"]:checked + label::after {
animation: toggle 0.5s linear;
transform: translate(125%, -50%);
}
/* Toggle large */
.Toggle__large input[type="checkbox"] + label {
padding-left: 9rem;
}
.Toggle__large input[type="checkbox"] + label::before {
width: 8rem;
border-radius: 2rem;
}
.Toggle__large input[type="checkbox"] + label::after {
left: .5rem;
width: 3rem;
}
/* ----------------
Radio input
---------------- */
.Radio input[type="radio"] + label {
padding-left: 3rem;
}
.Radio input[type="radio"] + label::before {
width: 2rem;
aspect-ratio: 1 / 1;
border-radius: 50%;
background: #eee;
}
.Radio input[type="radio"] + label::after {
left: .2rem;
width: 1.4rem;
transform: translateY(-50%) scale(0);
}
.Radio input[type="radio"]:not(:checked) + label::after {
animation: radio 0.5s linear;
}
.Radio input[type="radio"]:checked + label::after {
transform: translateY(-50%) scale(1);
}
/* Radio large */
.Radio__large input[type="radio"] + label {
padding-left: 5rem;
}
.Radio__large input[type="radio"] + label::before {
width: 4rem;
}
.Radio__large input[type="radio"] + label::after {
left: .4rem;
width: 3rem;
}
/* ----------------
Bubble display
---------------- */
.Toggle input[type="checkbox"] + label::after,
.Radio input[type="radio"] + label::after,
.Rating input[type="radio"] + label::after,
.Rating input[type="radio"]:checked ~ label > div::before,
.Rating input[type="radio"]:checked ~ label > div::after,
.Range input[type="range"]::-webkit-slider-thumb,
.Color input::-webkit-color-swatch {
aspect-ratio: 1 / 1;
border: 0.1rem solid #fff;
border-radius: 50%;
background: radial-gradient(circle at 70% 30%, #fff, rgba(0,0,0,0) 25%),
radial-gradient(circle at 60% 55%, rgba(0,0,0,0) 60%, rgba(255, 0, 255, 0.8) 100%),
radial-gradient(circle at 50% 50%, rgba(0,0,0,0) 40%, rgba(0, 255, 255, 0.2) 60%, rgba(0,0,0,0) 68%),
radial-gradient(circle at 50% 55%, rgba(0,0,0,0) 35%, rgba(255, 255, 0, 0.2) 45%, rgba(0,0,0,0) 55%);
}
// For Firfox support
// Can't be fusioned with previous selector...
.Range input[type="range"]::-moz-range-thumb {
aspect-ratio: 1 / 1;
border: 0.1rem solid #fff;
border-radius: 50%;
background: radial-gradient(circle at 70% 30%, #fff, transparent 25%),
radial-gradient(circle at 60% 55%, transparent 60%, rgba(255, 0, 255, 0.8) 100%),
radial-gradient(circle at 50% 50%, transparent 40%, rgba(0, 255, 255, 0.2) 60%, transparent 68%),
radial-gradient(circle at 50% 55%, transparent 35%, rgba(255, 255, 0, 0.2) 45%, transparent 55%);
}
/* squar aspect */
.File input[type="file"] + label::before {
content: "";
position: absolute;
inset: .5rem;
border: 0.1rem solid #fff;
border-radius: 1rem;
background: linear-gradient(rgba(0,0,0,0) 5%, rgba(255, 255, 0, 0.2) 8%, rgba(0,0,0,0) 15%, rgba(0,0,0,0) 90%, rgba(255, 255, 0, 0.2)) no-repeat;
box-shadow: inset -10px -10px 15px 0px rgba(0, 255, 255, 0.2),
inset 5px 5px 15px -9px rgba(255, 0, 255, 0.8);
}
/* ----------------
Animation
---------------- */
@keyframes toggle {
0% { transform: translate(0, -50%); }
25% { transform: translate(32%, -75%); }
35% { transform: translate(44.8%, -75%); }
65% { transform: translate(84.06%, -40%); }
75% { transform: translate(96%, -40%); }
100% { transform: translate(125%, -50%); }
}
@keyframes radio {
0% { transform: translateY(-50%) scale(1); }
100% { transform: translateY(-50%) scale(1.7); }
}
@keyframes rating {
0%, 100% { top: 45%; }
50% { top: 55%; }
}
@keyframes ratingBubbles {
0%, 100% { transform: translate(-50%, 0%); }
25% { transform: translate(-50%, 50%); }
75% { transform: translate(-50%, -50%); }
}
/* ----------------
Other
---------------- */
* {
box-sizing: border-box;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family: 'Poppins', sans-serif;
overflow: hidden;
}
.grid-full {
@media (min-width: 712px) {
grid-column-start: 1;
grid-column-end: span 2;
}
}
.Me {
position: fixed;
z-index: 10;
bottom: 20px;
left: 50%;
color: #000;
transform: translateX(-50%);
font-weight: 700;
opacity: .5;
}
Also see: Tab Triggers