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-container">
<input class="toggle-input" type="checkbox">
<svg class="toggle" viewBox="0 0 292 142" xmlns="http://www.w3.org/2000/svg">
<path class="toggle-background" d="M71 142C31.7878 142 0 110.212 0 71C0 31.7878 31.7878 0 71 0C110.212 0 119 30 146 30C173 30 182 0 221 0C260 0 292 31.7878 292 71C292 110.212 260.212 142 221 142C181.788 142 173 112 146 112C119 112 110.212 142 71 142Z" />
<rect class="toggle-icon on" x="64" y="39" width="12" height="64" rx="6" />
<path class="toggle-icon off" fill-rule="evenodd" d="M221 91C232.046 91 241 82.0457 241 71C241 59.9543 232.046 51 221 51C209.954 51 201 59.9543 201 71C201 82.0457 209.954 91 221 91ZM221 103C238.673 103 253 88.6731 253 71C253 53.3269 238.673 39 221 39C203.327 39 189 53.3269 189 71C189 88.6731 203.327 103 221 103Z" />
<g filter="url('#goo')">
<rect class="toggle-circle-center" x="13" y="42" width="116" height="58" rx="29" fill="#fff"/>
<rect class="toggle-circle left" x="14" y="14" width="114" height="114" rx="58" fill="#fff" />
<rect class="toggle-circle right" x="164" y="14" width="114" height="114" rx="58" fill="#fff" />
</g>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
</filter>
</svg>
</div>
<div class="toggle-container">
<input class="toggle-input" type="checkbox" checked>
<svg class="toggle" viewBox="0 0 292 142" xmlns="http://www.w3.org/2000/svg">
<path class="toggle-background" d="M71 142C31.7878 142 0 110.212 0 71C0 31.7878 31.7878 0 71 0C110.212 0 119 30 146 30C173 30 182 0 221 0C260 0 292 31.7878 292 71C292 110.212 260.212 142 221 142C181.788 142 173 112 146 112C119 112 110.212 142 71 142Z" />
<rect class="toggle-icon on" x="64" y="39" width="12" height="64" rx="6" />
<path class="toggle-icon off" fill-rule="evenodd" d="M221 91C232.046 91 241 82.0457 241 71C241 59.9543 232.046 51 221 51C209.954 51 201 59.9543 201 71C201 82.0457 209.954 91 221 91ZM221 103C238.673 103 253 88.6731 253 71C253 53.3269 238.673 39 221 39C203.327 39 189 53.3269 189 71C189 88.6731 203.327 103 221 103Z" />
<g filter="url('#goo')">
<rect class="toggle-circle-center" x="13" y="42" width="116" height="58" rx="29" fill="#fff"/>
<rect class="toggle-circle left" x="14" y="14" width="114" height="114" rx="58" fill="#fff" />
<rect class="toggle-circle right" x="164" y="14" width="114" height="114" rx="58" fill="#fff" />
</g>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
</filter>
</svg>
</div>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
font-size: 2em; // resize for demo
gap: 1em;
}
@function em($pixels) {
@if not (unit($pixels) == 'px') {
@error 'Value #{$pixels} must have `px` unit.';
}
@return $pixels / 16px * 1em;
}
.toggle-container {
--inactive-color: #d3d3d6;
position: relative;
aspect-ratio: 292 / 142;
height: em(30px);
&:nth-child(1) {
--active-color: #35c759;
}
&:nth-child(2) {
--active-color: #1868e3;
}
}
.toggle-input {
appearance: none;
margin: 0;
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.toggle {
width: 100%;
height: 100%;
overflow: visible;
}
.toggle-background {
fill: var(--inactive-color);
transition: fill .4s;
.toggle-input:checked + .toggle & {
fill: var(--active-color);
}
}
.toggle-circle-center {
transform-origin: center;
transition: transform .6s;
.toggle-input:checked + .toggle & {
transform: translateX(150px);
}
}
.toggle-circle {
transform-origin: center;
backface-visibility: hidden;
transition: transform .45s;
&.left {
transform: scale(1);
.toggle-input:checked + .toggle & {
transform: scale(0);
}
}
&.right {
transform: scale(0);
.toggle-input:checked + .toggle & {
transform: scale(1);
}
}
}
.toggle-icon {
transition: fill .4s;
&.on {
fill: var(--inactive-color);
.toggle-input:checked + .toggle & {
fill: #fff;
}
}
&.off {
fill: #eaeaec;
.toggle-input:checked + .toggle & {
fill: var(--active-color);
}
}
}
// to do: absolute units for transform origins
Also see: Tab Triggers