Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <input type="checkbox" id="toggle" name="toggle" value="is_on">
<label for="toggle" class="toy-toggle">
	<span class="border1"></span>
	<span class="border2"></span>
	<span class="border3"></span>
	<span class="handle">
		<span class="handle-off"></span>
		<span class="handle-on"></span>
	</span>
</label>
              
            
!

CSS

              
                *, *:before, *:after {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
body {
	background: linear-gradient(#fff,#ccc);
	display: flex;
	height: 100vh;
	--on: #88e661;
	--off: #f0f0f0;
	--transDur: 0.6s;
}
input {
	position: fixed;
	transform: translateX(-100%);
}
.toy-toggle {
	background:
		radial-gradient(at top left,#fff 10%,#fff0 20%),
		radial-gradient(at top right,#fff 20%,#e4e4e4 35%);
	border-radius: 6em;
	box-shadow:
		0 0 0.25em #0002,
		0 3em 1.5em 0.5em #0002;
	cursor: pointer;
	display: block;
	font-size: 12px;
	position: relative;
	margin: auto;
	width: 20em;
	height: 12em;
	-webkit-tap-highlight-color: transparent;
}
.toy-toggle span {
	display: block;
	position: absolute;
}
.toy-toggle > span {
	top: 50%;
	left: 50%;
}
.toy-toggle > span:not(.handle) {
	transform: translate(-50%,-50%);
}
.border1 {
	background: #f0f0f0;
	border-radius: 5.5em;
	box-shadow: 0 0 0.2em 0.1em #f0f0f0;
	width: 19em;
	height: 11em;
}
.border2 {
	background: linear-gradient(0deg,#fff 33%,#ccc 45%);
	border-radius: 4.75em;
	box-shadow: 0 0 0.2em 0.3em #f0f0f0 inset;
	width: 16.5em;
	height: 9.5em;
}
.border3, .handle {
	background: linear-gradient(90deg, var(--on) 50%, var(--off) 0);
}
.border3 {
	background-position: 75% 0;
	background-size: 200% 100%;
	border-radius: 4.25em;
	box-shadow:
		0 0 0.1em 0.1em #ddd inset,
		0 1.5em 1.5em 1em #0004 inset,
		0 0 0 4.25em #0002 inset;
	width: 15.5em;
	height: 8.5em;
	transition: background-position var(--transDur) ease-in-out;
}
.handle {
	border-radius: 50%;
	box-shadow: 0 0 0.5em 0 #0007;
	width: 8.5em;
	height: 8.5em;
	transform: translate(-90%,-50%);
	transition: transform var(--transDur) ease-in-out;
	z-index: 0;
}
.handle:before {
	background:
		radial-gradient(2em 1.5em at 50% 35%,#fff6 15%,#fff0),
		radial-gradient(1.5em 2.5em at 75% 40%,#fff6 15%,#fff0),
		radial-gradient(100% 100% at 50% 33%,#0000 25%,#0003 50%);
	border-radius: 50%;
	box-shadow: 0 0 0.3em 0.1em #0003 inset;
	content: "";
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 3;
}
.handle-off, .handle-on {
	width: 50%;
	height: 100%;
	transition: transform calc(var(--transDur)/2);
	z-index: 2;
}
.handle-off {
	background: var(--off);
	border-radius: 100% 0 0 100% / 50% 50% 50% 50%;
	right: 50%;
	transform-origin: 100% 50%;
	transition-delay: calc(var(--transDur)/2);
	transition-timing-function: ease-out;
}
.handle-on {
	background: var(--on);
	border-radius: 0 100% 100% 0 / 50% 50% 50% 50%;
	left: 50%;
	transform: scaleX(0);
	transform-origin: 0 50%;
	transition-timing-function: ease-in;
}

/* On */
input:checked + .toy-toggle .border3 {
	background-position: 25% 0;
}
input:checked + .toy-toggle .handle {
	transform: translate(-10%,-50%);
}
input:checked + .toy-toggle .handle-off {
	transform: scaleX(0);
	transition-delay: 0s;
	transition-timing-function: ease-in;
}
input:checked + .toy-toggle .handle-on {
	transform: scaleX(1);
	transition-delay: calc(var(--transDur)/2);
	transition-timing-function: ease-out;
}
              
            
!

JS

              
                
              
            
!
999px

Console