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

              
                <div data-scheme="light">
	<div class="demo">
		<p>data-scheme=light</p>
		<p>My color scheme is forced to light.</p>
		<p>The styling is determined by the native <code>light-dark()</code> and the custom <code>--light-dark()</code></p>
	</div>
</div>

<div data-scheme="dark">
	<div class="demo">
		<p>data-scheme=dark</p>
		<p>My color scheme is forced to dark.</p>
		<p>The styling is determined by the native <code>light-dark()</code> and the custom <code>--light-dark()</code></p>
	</div>
</div>

<div data-scheme="system">
	<div class="demo">
		<p>data-scheme=system</p>
		<p>I follow the <code>prefers-color-scheme</code> value. Chance your OS setting to see this block change.</p>
		<p>The styling is determined by the native <code>light-dark()</code> and the custom <code>--light-dark()</code></p>
	</div>
</div>

<div class="warning"><p>This is a demo for <a href="https://www.bram.us/2025/02/18/css-at-function-and-css-if/" target="_top">https://www.bram.us/2025/02/18/css-at-function-and-css-if/</a>. It relies on <a href="https://drafts.csswg.org/css-mixins/" target="_top">Custom Functions in CSS</a>. Try it in Chrome Canary with Experimental Web Platform Features enabled.</p></div>
              
            
!

CSS

              
                /* A custom function that returns one of two values depending on light or dark mode being used */
/* Note that this requires storing the color-scheme in a --scheme custom property */
@function --light-dark(--light, --dark) {
	/* Default to the --light value */
	result: var(--light);
	
	/* If the container is set to "dark", use the --dark value */
	@container style(--scheme: dark) {
		result: var(--dark);
	}
}

/* Default --scheme value to use, this is based on the system value */
:root {
	--root-scheme: light;
	--scheme: light;

	@media (prefers-color-scheme: dark) {
		--root-scheme: dark;
		--scheme: dark;
	}
}

/* Allow overriding the --scheme from the data-scheme HTML attribute */
/* Note that I am using @scope to play nice with nested light/dark contexts */
@scope ([data-scheme]) {
	:scope {
		--scheme: attr(data-scheme type(<custom-ident>));
	}
	
	/* When set to system, use the --root-scheme value (which is determined by the MQ) */
	:scope[data-scheme="system"] {
		--scheme: var(--root-scheme);
	}
	
	/* To allow the native light-dark to work */
	:scope > * {	
		color-scheme: var(--scheme);
	}
	
	/* Because I chose to use these elements as extra wrapper elements, I can just display its contents */
	display: contents;
}

/* The color-scheme dependent declarations */
[data-scheme] > * {
	color: light-dark(#333, #e4e4e4);
	background-color: light-dark(aliceblue, #333);
	
	border: 4px --light-dark(dashed, dotted) currentcolor;
	font-weight: --light-dark(500, 300);
	font-size: --light-dark(16px, 18px);
	
	transition: all 0.25s ease, border-style 0.25s allow-discrete;
}

.demo {
	width: 60ch;
	text-align: center;
	text-wrap: balance;
	padding: 1em;
	margin: 1em auto;
}

@layer layout {
	* {
		box-sizing: border-box;
	}

	:root {
		font-family: "Literata", serif;
		background: #fff;
	}

	body,
	html {
		height: 100%;
		margin: 0;
		padding: 0;
	}

	body {
		display: grid;
		place-content: safe center;
	}
}

@layer warning {
	.warning {
		padding: 1em;
		margin: 1em 0;
		border: 1px solid #ccc;
		background: rgba(255 255 205 / 0.8);
		color: black;
		text-align: center;
		position: fixed;
		bottom: 0;
		left: 1em;
		right: 1em;
	}

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

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

	.warning a {
		color: blue;
	}
	.warning--info {
		border: 1px solid #123456;
		background: rgb(205 230 255 / 0.8);
	}
	.warning--alarm {
		border: 1px solid red;
		background: #ff000010;
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console