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

              
                <header class="visually-hidden">
	<h1>Tri-state theme toggle built using light-dark</h1>
</header>

<main>
	<fieldset>
		<legend class="visually-hidden">Pick your theme</legend>
		<div class="legend" aria-hidden="true">Pick your theme</div>

		<theme-switcher>
			<label for="system" class="chonky-radio">
				<svg fill="currentColor" aria-hidden="true">
					<use href="#system-icon" />
				</svg>
				<input type="radio" id="system" name="color-scheme" value="system" checked>
				<span class="label">System</span>
			</label>

			<label for="light" class="chonky-radio">
				<svg fill="currentColor" aria-hidden="true">
					<use href="#day-icon" />
				</svg>
				<input type="radio" id="light" name="color-scheme" value="light">
				<span class="label">Light</span>
			</label>

			<label for="dark" class="chonky-radio">
				<svg fill="currentColor" aria-hidden="true">
					<use href="#night-icon" />
				</svg>
				<input type="radio" id="dark" name="color-scheme" value="dark">
				<span class="label">Dark</span>
			</label>
		</theme-switcher>

	</fieldset>
	<fieldset>
		<legend class="visually-hidden">More options</legend>
		<extra-toggles>
			<label for="hc-toggle">
				<input id="hc-toggle" type="checkbox" switch>
				High contrast
			</label>
			<label for="snow-toggle">
				<input id="snow-toggle" type="checkbox" switch>
				Snow fall
			</label>
		</extra-toggles>
	</fieldset>
</main>

<svg hidden>
	<symbol id="system-icon" viewBox="0 -3 46 46">
		<path d="M43,35H29.195a11.476,11.476,0,0,0,4.4,7H36a1,1,0,0,1,0,2H12a1,1,0,0,1,0-2h2.4a11.476,11.476,0,0,0,4.4-7H5a4,4,0,0,1-4-4V8A4,4,0,0,1,5,4H43a4,4,0,0,1,4,4V31A4,4,0,0,1,43,35ZM17.4,42H30.6a12.747,12.747,0,0,1-3.459-7H20.856A12.747,12.747,0,0,1,17.4,42ZM45,8a2,2,0,0,0-2-2H5A2,2,0,0,0,3,8V27H45Zm0,21H3v2a2,2,0,0,0,2,2H43a2,2,0,0,0,2-2ZM24,32a1,1,0,1,1,1-1A1,1,0,0,1,24,32Z" transform="translate(-1 -4)" fill-rule="evenodd"></path>
	</symbol>
	<symbol id="day-icon" viewBox="0 -6 46 46">
		<path d="M43,41H5a4,4,0,0,1-4-4V11A4,4,0,0,1,5,7H43a4,4,0,0,1,4,4V37A4,4,0,0,1,43,41Zm2-30a2,2,0,0,0-2-2H5a2,2,0,0,0-2,2V37a2,2,0,0,0,2,2H43a2,2,0,0,0,2-2ZM41.334,34.715,35,28.381,31.381,32l3.334,3.334a.977.977,0,0,1-1.381,1.381L19,22.381,6.666,34.715a.977.977,0,0,1-1.381-1.381l12.905-12.9a.9.9,0,0,1,.095-.144.918.918,0,0,1,1.525.144L30,30.619l4.19-4.19a1.023,1.023,0,0,1,.1-.144,1.05,1.05,0,0,1,1.43,0,1.023,1.023,0,0,1,.1.144l6.9,6.905a.977.977,0,0,1-1.381,1.381ZM29,19a4,4,0,1,1,4-4A4,4,0,0,1,29,19Zm0-6a2,2,0,1,0,2,2A2,2,0,0,0,29,13Z" transform="translate(-1 -7)" fill-rule="evenodd"></path>
	</symbol>
	<symbol id="night-icon" viewBox="0 -6 46 46">
		<path d="M43,41H5a4,4,0,0,1-4-4V11A4,4,0,0,1,5,7H43a4,4,0,0,1,4,4V37A4,4,0,0,1,43,41Zm2-30a2,2,0,0,0-2-2H5a2,2,0,0,0-2,2V37a2,2,0,0,0,2,2H43a2,2,0,0,0,2-2ZM41.334,34.715,35,28.381,31.381,32l3.334,3.334a.977.977,0,0,1-1.381,1.381L19,22.381,6.666,34.715a.977.977,0,0,1-1.381-1.381l12.905-12.9a.9.9,0,0,1,.095-.144.918.918,0,0,1,1.525.144L30,30.619l4.19-4.19a1.023,1.023,0,0,1,.1-.144,1.05,1.05,0,0,1,1.43,0,1.023,1.023,0,0,1,.1.144l6.9,6.905a.977.977,0,0,1-1.381,1.381ZM29,19a4,4,0,0,1-1.641-7.64,3.987,3.987,0,0,0,5.282,5.281A4,4,0,0,1,29,19Z" transform="translate(-1 -7)" fill-rule="evenodd"></path>
	</symbol>
</svg>

<svg id="skyline" viewBox="0 -200 1280 640" aria-hidden="true">
	<path d="M484.4 151.7c-1 22.5-1.3 31.3-1.3 54.1 0 12.6-.3 18.8-1.1 19.7-.7.9-.9 2.6-.6 4 .5 2.1.2 2.7-1.9 3.5-1.4.5-2.5 1.7-2.5 2.5 0 .9-.7 1.8-1.6 2.2-1.4.5-1.6 1.7-1 7.7.7 7.4 2 9.6 5.9 9.6 2 0 2 .6 1.3 24.2-2.1 72.4-4.4 114.3-6.1 114.3-.6 0-1.2-5.6-1.5-13.7-.3-9-.9-14.1-1.7-15-.7-.6-1.3-2.2-1.3-3.4s-.7-2.7-1.5-3.4c-1.6-1.3-6.5-.6-6.5 1 0 .6-1.8 1-4 1-2.7 0-4.3.5-4.6 1.5-.4.8-1.2 1.5-2 1.5-1 0-1.4 1.6-1.6 5.7-.1 4.1-.2 4.8-.5 2.3-.6-4.7-1.9-6-5.9-6H441v-7c0-7.9-.4-8.3-7.4-8.4-4.1-.1-4.1-.1-4.4 3.9-.2 2.2-1 4.4-1.8 4.8-1 .6-1.4 2.6-1.4 6.7 0 5.3-.2 6-1.9 6-1.1 0-2.6.9-3.4 2.1-1.7 2.3-9.7 4-9.7 2 0-2.8-3.5-5.1-7.8-5.1-6.5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24.5-1-29.7v-9.3l2.9-.7c3.2-.7 4.7-3.1 3.1-5-.6-.8-.6-1.5.2-2.3 1.8-1.8 1.5-9.2-.5-10.7-.9-.6-1.7-1.7-1.7-2.3s-.9-1.4-2-1.7c-1.4-.4-2-1.5-2-3.5 0-1.6-.5-3.2-1.1-3.5-.7-.5-1-6.5-.9-17.9.2-9.4 0-17.8-.3-18.6s-.8-7.8-1.1-15.5c-1.3-29.9-1.9-39.5-2.6-39.5-.4 0-1.1 8-1.6 17.7M36 395v8h-9v-16h9z" />
</svg>

<script type="module" src="https://esm.sh/@zachleat/snow-fall@1.0.3"></script>
              
            
!

CSS

              
                @layer theme {
	html {
		color-scheme: light dark;

		&[data-color-scheme="light"] {
			color-scheme: light;
		}

		&[data-color-scheme="dark"] {
			color-scheme: dark;
		}

		--accent: light-dark(var(--cyan-9), var(--cyan-4));
		--backdrop: light-dark(var(--stone-4), var(--stone-11));
		--text: light-dark(var(--stone-9), var(--stone-3));
		--stroke: light-dark(var(--stone-8), var(--stone-5));

		--snow-fall-color: light-dark(var(--cyan-7), var(--cyan-3));

		&[data-high-contrast="true"] {
			--accent: light-dark(var(--cyan-10), var(--cyan-3));
			--backdrop: light-dark(var(--stone-1), var(--stone-12));
			--text: light-dark(var(--stone-12), var(--stone-2));
			--stroke: light-dark(var(--stone-10), var(--stone-3));

			--snow-fall-color: light-dark(var(--cyan-9), var(--cyan-1));
		}
	}
}

html {
	accent-color: var(--accent);
	color: var(--text);
	background-color: var(--backdrop);
}

* {
	border-color: var(--stroke);
}

*::selection {
	background-color: var(--accent);
	color: var(--backdrop);
}

svg {
	color: var(--stroke);
}

/* --------------------------------------------------- */

@layer {
	html {
		transition: 800ms var(--ease-in-out-1);
		transition-property: accent-color, background-color, color;
	}
	main {
		min-block-size: 100dvb;
		display: grid;
		place-items: center;
		place-content: center;
		gap: 8px;
		padding: 8px;
	}
	fieldset {
		border: none;
		display: grid;
		gap: 8px;

		> .legend {
			font-weight: bold;
		}
	}
	theme-switcher {
		display: flex;
		flex-wrap: wrap;
		gap: 12px;
		align-items: center;
		justify-content: center;
	}
	.chonky-radio {
		display: grid;
		padding: 8px;
		gap: 4px;
		grid-template: "svg svg" "input label" / auto 1fr;
		border: 1.5px solid;
		border-radius: 4px;
		--_color: currentColor;

		&:has(> :checked) {
			font-weight: bold;
		}

		> svg {
			grid-area: svg;
			block-size: min(calc(2rem + 30px), 30vmin);
			aspect-ratio: 2;
			transition: scale 400ms var(--ease-elastic-in-3);

			&:has(+ :checked) {
				scale: 1.07;
				color: var(--_color) !important;
			}
		}

		> input[type="radio"] {
			grid-area: input;

			&:focus {
				outline-color: transparent;
			}
		}

		> .label {
			grid-area: label;
		}

		&:focus-within {
			outline: 3px solid var(--accent);
			outline-offset: 3px;
		}
	}
	extra-toggles {
		display: flex;
		gap: 12px;
	}

	snow-fall {
		opacity: 0.4;
	}
	#skyline {
		position: fixed;
		inline-size: 100%;
		inset-block-end: 0;
		z-index: -1;
		fill: currentColor;
		opacity: 0.07;
	}
}

              
            
!

JS

              
                customElements.define(
	"theme-switcher",
	class extends HTMLElement {
		connectedCallback() {
			this.oninput = ({ target }) => {
				setColorScheme(target.value);
			};
		}
	}
);

function setColorScheme(mode) {
	if (!["light", "dark"].includes(mode)) {
		delete document.documentElement.dataset.colorScheme;
		return;
	}
	document.documentElement.dataset.colorScheme = mode;
}

customElements.define(
	"extra-toggles",
	class extends HTMLElement {
		#snowFall = Object.assign(document.createElement("snow-fall"), {
			hidden: true
		});

		connectedCallback() {
			this.appendChild(this.#snowFall);

			const snowToggle = this.querySelector("#snow-toggle");
			snowToggle.onchange = () => {
				this.#snowFall.hidden = !snowToggle.checked;
			};

			const contrastToggle = this.querySelector("#hc-toggle");
			contrastToggle.onchange = () => {
				document.documentElement.dataset.highContrast = contrastToggle.checked;
			};
		}
	}
);

              
            
!
999px

Console