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="toggle">
<input type="checkbox" id="btn">
<label for="btn">
<span class="thumb"></span>
</label>
<div class="lights">
<span class="light-off"></span>
<span class="light-on"></span>
</div>
</div>
/*** IN PROGRESS ***/
:root {
--sz: 10vmin;
--on: #99dc39;
--of: #F44336;
--lg: var(--of);
--sp: 1s;
}
*, *:before, *:after {
box-sizing: border-box;
transition: all var(--sp) ease 0s;
}
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
transition: none;
background: linear-gradient(135deg, #1f1f23, #2d2d31, #101012);
background: linear-gradient(135deg, #161618, #212125, #060606);
}
body:before, body:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background:
repeating-conic-gradient(#0002 0.000095%, #fff0 .0005%, #fff0 .005%, #fff0 .0005%),
repeating-conic-gradient(#0002 0.00001%, #fff0 .00009%, #fff0 .00075%, #fff0 .000025%);
opacity: 0.75;
filter: blur(0.75px);
}
.toggle {
position: relative;
width: calc(var(--sz) * 5.55);
height: calc(var(--sz) * 2);
display: flex;
align-items: center;
justify-content: center;
}
input {
display: none;
}
label[for=btn] {
position: absolute;
width: calc(var(--sz) * 5.55);
height: calc(var(--sz) * 2);
background: linear-gradient(0deg, #12172080, #0d121780);
border-radius: var(--sz);
display: flex;
align-items: center;
/*
box-shadow:
0 0 calc(var(--sz) / 50) calc(var(--sz) / 50) #0006,
0 calc(var(--sz) / -20) calc(var(--sz) / 5) calc(var(--sz) / 25) #0b0b10,
0 calc(var(--sz) / 20) calc(var(--sz) / 10) calc(var(--sz) / 50) #f5f5f588,
0 calc(var(--sz) / -20) calc(var(--sz) / 50) calc(var(--sz) / 15) #00000060;
*/
background: radial-gradient(circle at 50% calc(var(--sz) / 0.085), #fff0 calc(var(--sz) / 0.1), #000 calc(calc(var(--sz) / 0.1) + 1px) calc(var(--sz) / 0.0875), #fff0 calc(calc(var(--sz) / 0.0875) + 1px) 100%),
radial-gradient(circle at 50% calc(var(--sz) / -0.1025), #fff0 calc(var(--sz) / 0.1), #000 calc(calc(var(--sz) / 0.1) + 1px) calc(var(--sz) / 0.0875), #fff0 calc(calc(var(--sz) / 0.0875) + 1px) 100%);
}
label[for=btn]:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
border-radius: var(--sz);
/* box-shadow: 0 0 calc(var(--sz) / 3) calc(var(--sz) / 10) #000 inset; */
background: radial-gradient(circle at 50% calc(var(--sz) / 0.0845), #fff0 calc(var(--sz) / 0.1), #121212 calc(calc(var(--sz) / 0.1) + 1px) calc(var(--sz) / 0.0875), #fff0 calc(calc(var(--sz) / 0.0875) + 1px) 100%), radial-gradient(circle at 50% calc(var(--sz) / -0.1015), #fff0 calc(var(--sz) / 0.1), #121212 calc(calc(var(--sz) / 0.1) + 1px) calc(var(--sz) / 0.0875), #fff0 calc(calc(var(--sz) / 0.0875) + 1px) 100%);
filter: drop-shadow(0px -2px 1px #000) drop-shadow(0px -2px 2px #000) drop-shadow(0px -2px 3px #0008) drop-shadow(0px 2px 2px #fff8);
}
.thumb {
position: absolute;
width: calc(calc(var(--sz) * 2) - calc(var(--sz) / 8));
height: calc(calc(var(--sz) * 2) - calc(var(--sz) / 8));
margin-top: calc(calc( var(--sz) / 10) + calc(var(--sz) / -7));
left: calc(calc( var(--sz) / 10) + calc(var(--sz) / -30));
background:
/* radial-gradient( #fff0 0 calc(var(--sz) / 3.5), var(--lg) calc(calc(var(--sz) / 3) + 1px) calc(var(--sz) / 2.75), #fff0 calc(var(--sz) / 1.15)), */
linear-gradient(0deg, #212121, #fff0 35% 65%, #474747),
radial-gradient( #fff0 0 calc(var(--sz) / 3), #393939 calc(calc(var(--sz) / 3) + 1px) calc(var(--sz) / 1), #474747);
border-radius: var(--sz);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
overflow: hidden;
box-shadow:
0 0 calc(var(--sz) / 3) calc(var(--sz) / -8) var(--lg),
0 0 calc(var(--sz) / 5) calc(var(--sz) / -15) var(--lg) inset,
calc(var(--sz) / -50) calc(var(--sz) / 50) calc(var(--sz) / 30) 0 #fff2 inset, 0 0 calc(var(--sz) / 10) calc(var(--sz) / 50) #000c, 0 calc(var(--sz) / 4) calc(var(--sz) / 5) 0 #000d;
animation: grow calc(var(--sp) / 3) ease 0s 2 alternate;
}
#btn:checked + label .thumb {
--lg: var(--on);
left: calc(calc(100% - calc(calc(var(--sz) * 2) - calc(var(--sz) / 3))) - calc(calc( var(--sz) / 10) + calc(var(--sz) / 6)));
/*
box-shadow:
calc(var(--sz) / 10) 0 calc(var(--sz) / 10) calc(var(--sz) / -10) var(--lg),
calc(var(--sz) / -10) 0 calc(var(--sz) / 10) calc(var(--sz) / -10) var(--lg) inset,
calc(var(--sz) / -50) calc(var(--sz) / 50) calc(var(--sz) / 30) 0 #fff2 inset,
0 0 calc(var(--sz) / 10) calc(var(--sz) / 50) #000c,
0 calc(var(--sz) / 4) calc(var(--sz) / 5) 0 #000d;
*/
animation: grow2 calc(var(--sp) / 3) ease 0s 2 alternate;
}
@keyframes grow {
80%, 100% {
height: calc(calc(var(--sz) * 2) - calc(var(--sz) / 2.5));
width: calc(calc(var(--sz) * 2) - calc(var(--sz) * -0.5));
}
}
@keyframes grow2 {
80%, 100% {
height: calc(calc(var(--sz) * 2) - calc(var(--sz) / 2.5));
width: calc(calc(var(--sz) * 2) - calc(var(--sz) * -0.5));
}
}
.thumb:before {
content: "";
width: calc(var(--sz) / 1.65);
height: calc(var(--sz) / 1.65);
background: #fff0;
border-radius: 100%;
box-shadow:
0 calc(var(--sz) / -1) calc(var(--sz) / 2) var(--lg),
0 calc(var(--sz) / 1) calc(var(--sz) / 2) var(--lg),
0 0 2vmin 0.25vmin var(--lg) inset, 0 0 5vmin 1.5vmin var(--lg),
0 0 calc(var(--sz) / 5) 0 #fff;
}
.lights {
position: absolute;
width: calc(100% + calc(var(--sz) * 2));
height: calc(var(--sz) / 1.75);
display: flex;
justify-content: space-between;
padding: 0;
z-index: 0;
}
.lights span {
background: #121212;
position: relative;
width: calc(var(--sz) / 1.75);
height: calc(var(--sz) / 1.75);
border-radius: var(--sz);
box-shadow:
0 0 calc(var(--sz) / 50) calc(var(--sz) / 50) #0008,
0 calc(var(--sz) / -20) calc(var(--sz) / 10) calc(var(--sz) / 500) #000,
0 calc(var(--sz) / 20) calc(var(--sz) / 10) calc(var(--sz) / 500) #fff8,
0 0 calc(var(--sz) / 20) calc(var(--sz) / 25) #000;
display: flex;
align-items: center;
justify-content: center;
}
.lights {
position: absolute;
width: calc(100% - calc(var(--sz) * 1.425));
height: calc(var(--sz) / 1.75);
display: flex;
justify-content: space-between;
padding: 0;
z-index: 0;
margin-top: -1px;
}
.lights span {
background: #121212;
position: relative;
width: calc(var(--sz) / 1.75);
height: calc(var(--sz) / 1.75);
border-radius: var(--sz);
box-shadow:
0 0 calc(var(--sz) / 50) calc(var(--sz) / 50) #0008,
0 calc(var(--sz) / -20) calc(var(--sz) / 10) calc(var(--sz) / 500) #000,
0 calc(var(--sz) / 20) calc(var(--sz) / 10) calc(var(--sz) / 500) #fff8,
0 0 calc(var(--sz) / 20) calc(var(--sz) / 25) #000;
display: flex;
align-items: center;
justify-content: center;
}
.lights span:after {
content: "";
color: #fff;
width: calc(100% - calc(var(--sz) / 15));
height: calc(100% - calc(var(--sz) / 15));
position: absolute;
background: radial-gradient(circle at 50% 32%, #fff5 0 calc(var(--sz) / 20), #000 calc(var(--sz) / 3) calc(var(--sz) / 3));
border-radius: var(--sz);
top: calc(var(--sz) / 50);
}
/* off */
span.light-off:after {
box-shadow:
0 0 calc(var(--sz) / 2.5) 0 var(--lg),
0 0 calc(var(--sz) / 3) calc(var(--sz) / 20) var(--lg) inset,
0 calc(var(--sz) / -20) calc(var(--sz) / 10) calc(var(--sz) / 10) #000 inset;
background: radial-gradient(circle at 50% 32%, #fff 0 calc(var(--sz) / 20), #fff8 calc(var(--sz) / 3) calc(var(--sz) / 3));
}
#btn:checked + label + .lights span.light-off:after {
box-shadow: 0 0 calc(var(--sz) / 3) 0 #f5000020, 0 0 calc(var(--sz) / 3) calc(var(--sz) / 20) #f5000020 inset;
background: radial-gradient(circle at 50% 32%, #fff5 0 calc(var(--sz) / 20), #000 calc(var(--sz) / 3) calc(var(--sz) / 3));
}
/* on */
span.light-on:after {
box-shadow: 0 0 calc(var(--sz) / 3) 0 #00f56d20, 0 0 calc(var(--sz) / 3) calc(var(--sz) / 20) #00f56d20 inset;
}
#btn:checked + label + .lights span.light-on:after {
--lg: var(--on);
box-shadow: 0 0 calc(var(--sz) / 2.5) 0 var(--lg), 0 0 calc(var(--sz) / 3) calc(var(--sz) / 20) var(--lg) inset, 0 calc(var(--sz) / -20) calc(var(--sz) / 10) calc(var(--sz) / 10) #000 inset;
background: radial-gradient(circle at 50% 32%, #fff 0 calc(var(--sz) / 20), #fff2 calc(var(--sz) / 3) calc(var(--sz) / 3));
}
#btn:checked + label + .lights span.light-on:before {
--lg: var(--on);
}
#btn:checked + label + .lights span.light-off:before {
--lg: #666;
}
Also see: Tab Triggers