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

              
                <h1>CSS <code>light-dark()</code> demo</h1>
<div class="warning"><p>Your browser does not support <code>light-dark()</code> so this demo will not work properly. Try Firefox 120+</p></div>
<h2>CSS Used</h2>
<pre><code>#demo {
	color-scheme: light dark;
	
	.dark {
		color-scheme: dark;
	}

	.light {
		color-scheme: light;
	}
	
	& div {
		background: light-dark(#d4d4d4, #000);
		color: light-dark(#333, #ccc);
	}
}</code></pre>

<h2>Live Output</h2>

<main>
	<div id="demo">
		<div class="auto">
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>
		</div>

		<div class="dark">
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>

			<div class="light">
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>

				<div class="auto">
					<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>
				</div>
			</div>

			<div class="auto">
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>
			</div>
		</div>

		<div class="auto">
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae soluta nobis deserunt hic sed. Neque iure saepe earum quis fugiat ipsa repudiandae tempore, culpa autem laborum doloribus ratione officia at?</p>
		</div>
	</div>
</main>

<footer>
	<p>Demo for <a href="https://brm.us/light-dark" target="_top">https://brm.us/light-dark</a></p>
</footer>
              
            
!

CSS

              
                @layer reset, layout;

#demo {
	color-scheme: light dark;
	
	.dark {
		color-scheme: dark;
	}

	.light {
		color-scheme: light;
	}
	
	.auto {
		color-scheme: light dark;
	}
	
	& div {
		border: 1px solid #ccc;
		padding: 1em;
		margin: 1em;
		
		&[class] {
			position: relative;
			padding-top: 1.8em;
			
			&::before {
				content: "." attr(class);
				position: absolute;
				top: 0;
				left: 0;
				font-size: 0.8rem;
				padding: 0.3em;
				background: #e4e4e4;
				color: #333;
				font-weight: normal;
				font-family: monospace;
			}
		}
	}
	
	& div {
		background: light-dark(#d4d4d4, #000);
		color: light-dark(#333, #ccc);
	}
}

@supports(color: light-dark(black, white)) {
	.warning {
		display: none;
	}
}

@layer layout {
	@layer general {
		body {
			padding: 3rem 0 2rem;
			width: 90%;
			max-width: 60em;
			margin: 0 auto;
		}
		body > footer {
			text-align: center;
			margin: 2rem 0;
			font-style: italic;
		}
 	}
	@layer visualization {
		body > main {
			margin: 2rem auto;
		}
		body > main [data-identifier] {
			position: relative;
			padding: 1.8rem 1.2rem;
			border: 2px solid #ccc;
			margin: 0.5rem 0 0 0;
		}
		body > main [data-identifier]::before {
			content: '<' attr(data-identifier) '>';
			position: absolute;
			top: 0;
			left: 0;
			font-size: 0.8rem;
			padding: 0.3em;
			background: #e4e4e4;
			color: #333;
			font-weight: normal;
			font-family: monospace;
		}

		main img {
			max-height: 0px;
			width: auto;
		}

		main span.img {
			display: inline-block;
		}
	}
	
	@layer warning {
		/* Show warning for browsers without support */
		.warning {
			padding: 1em;
			border: 1px solid black;
			z-index: 9999;
			color: black;
			background: rgba(255 255 225 / 0.9);
			z-index: 10001;
			
			width: 100%;
			margin: 1em auto;
			text-align: center;
		}
		
		:is(
			.warning:hover,
			.warning:has(:focus-within)
		) {
			opacity: 1;
		}

		.warning > :first-child {
			margin-top: 0;
		}

		.warning > :last-child {
			margin-bottom: 0;
		}

		.warning a {
			color: blue;
		}

		.warning--info {
			border: 1px solid #123456;
			background: rgba(205 230 255 / 0.8);
		}
	}
	
	@layer code {
		pre {
			border: 1px solid #dedede;
			padding: 1em;
			background: #f7f7f7;
			font-family: "Courier 10 Pitch", Courier, monospace;
			overflow-x: auto;
			border-left: 0.4em solid cornflowerblue;
			tab-size: 4;
		}
		
		code:not(pre code), /* output:not(code:has(output) output) */ {
			background: #f7f7f7;
			border: 1px solid rgb(0 0 0 / 0.2);
			padding: 0.1rem 0.3rem;
			margin: 0.1rem 0;
			border-radius: 0.2rem;
			display: inline-block;
		}
	}
}

@layer reset {
	* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}
	html {
		line-height: 1;
	}
	h1, h2, h3, h4 {
		margin: 2em 0 0.5em;
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console