Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ add another resource


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


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.


Save Automatically?

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.


			// Check if there's any override. If so, let the markup know by setting an attribute on the <html> element
			const colorModeOverride = window.localStorage.getItem('color-mode');
			const hasColorModeOverride = typeof colorModeOverride === 'string';
			if (hasColorModeOverride) {
				document.documentElement.setAttribute('data-force-color-mode', colorModeOverride);
	<h1>Dark Mode + Override (Vanilla JS) <a id="reset-darkmode" href="#" title="Clear Dark Mode Override"><small>(reset)</small></a></h1>
		<input type="checkbox" id="toggle-darkmode" />
		<label for="toggle-darkmode"><span>Toggle Light/Dark Mode</span></label>
			// Check the dark-mode checkbox if
			// - The override is set to dark
			// - No override is set but the system prefers dark mode
			if ((colorModeOverride == 'dark') || (!hasColorModeOverride && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
				document.querySelector('#toggle-darkmode').checked = true;
		<p>Some things to try:</p>
			<li>Change your system preferences. This site will adjust accordingly <em>(if no override is set)</em></li>
			<li>Click the 🔆/🌙 to override the system preferences</li>
			<li>Use this reset link at the top to clear the override <em>(shown only if an override is set)</em></li>


                /* Light Color Scheme */
:root[data-force-color-mode="light"] {
	color-scheme: light dark;
	--text-color: #000;
	--background-color: #fff;
	--link-color: #00f;

/* Dark Color Scheme */
@media (prefers-color-scheme: dark) {
	:root {
		--text-color: #fff;
		--background-color: #333;
		--link-color: #2196f3;
:root[data-force-color-mode="dark"] {
	--text-color: #fff;
	--background-color: #333;
	--link-color: #2196f3;

/* Use the Color Scheme */
body {
	color: var(--text-color);
	background-color: var(--background-color);

a {
	color: var(--link-color);

/* Only show reset button if override is set */
#reset-darkmode {
	display: none;
	text-decoration: none;
	font-style: italic;
[data-force-color-mode] #reset-darkmode {
	display: initial;

/* Visually hide the label text and Inject Light/Dark Mode Icon (based on checkbox value) */
#toggle-darkmode {
	display: none;
#toggle-darkmode + label > span {
	position: absolute;
	overflow: hidden;
	clip: rect(0 0 0 0);
	height: 1px;
	width: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
#toggle-darkmode + label:after {
	font-size: 4em;
	content: "🔆";
	cursor: pointer;
#toggle-darkmode:checked + label:after {
	content: "🌙";

body {
	font-family: Helvetica, Arial, sans-serif;
	margin: 0;
	padding: 0;
	height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;



 * Demo for

const setColorMode = (mode) => {
	// Mode was given
	if (mode) {
		// Update data-* attr on html
		document.documentElement.setAttribute('data-force-color-mode', mode);
		// Persist in local storage
		window.localStorage.setItem('color-mode', mode);
		// Make sure the checkbox is up-to-date
		document.querySelector('#toggle-darkmode').checked = (mode === 'dark');
	// No mode given (e.g. reset)
	else {
		// Remove data-* attr from html
		// Remove entry from local storage
		// Make sure the checkbox is up-to-date, matching the system preferences
		document.querySelector('#toggle-darkmode').checked = window.matchMedia('(prefers-color-scheme: dark)').matches;

document.querySelector('#toggle-darkmode').addEventListener('click', (e) => {
	setColorMode( ? 'dark' : 'light');

document.querySelector('#reset-darkmode').addEventListener('click', (e) => {

// Keep an eye out for System Light/Dark Mode Changes
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
mediaQuery.addListener(() => {
	// Ignore change if there's an override set
	if (document.documentElement.getAttribute('data-force-color-mode')) {

	// Make sure the checkbox is up-to-date
 	document.querySelector('#toggle-darkmode').checked = mediaQuery.matches;