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>
	<h1>HWB color explorer</h1>
	<p class="warning">
		Sorry, your browser doesn’t support HWB colors.
	</p>
	<code class="result" data-result>hwb(0 0 0)</code>
	<div class="controls" data-controls>
		<div class="input-group">
			<label for="h">Hue</label>
			<input id="h" type="range" min="0" max="360">
		</div>
		<div class="input-group">
			<label for="w">Whiteness</label>
			<input id="w" type="range" min="0" max="100" value="0">
		</div>
		<div class="input-group">
			<label for="b">Blackness</label>
			<input id="b" type="range" min="0" max="100" value="0">
		</div>
	</div>
</div>
              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

body {
	font-family: "Open Sans", sans-serif;
	margin: 0;
	min-height: 100vh;
	background: hsl(0, 50%, 80%);
	display: flex;
	justify-content: center;
	align-items: center;
	color: var(--text, #000000);
}

.controls {
	padding: 1.75rem;
	background: #ffffff;
	border-radius: 0.5rem;
	display: none;
	color: #000000;
	
	> * + * {
		margin-top: 0.75rem;
	}
}

.result {
	display: block;
	font-size: 1.4rem;
	margin: 0 0 1rem;
	text-align: center;
}

.input-group {
	display: flex;
	align-items: center;
	
	label {
		margin-right: 0.5rem;
		width: 6rem;
	}
	
	input {
		flex: 1 1 auto;
	}
}

@supports (color: hwb(0 0% 0%)) {
	body {
		background: hwb(var(--h, 0) calc(var(--w, 0) * 1%) calc(var(--b, 0) * 1%));
	}
	
	.controls {
		display: block;
	}
	
	.warning {
		display: none;
	}
}



              
            
!

JS

              
                const controls = document.querySelector('[data-controls]')
const inputs = [...document.querySelectorAll('input')]
const result = document.querySelector('[data-result]')

const setTextColor = () => {
	const wInput = inputs[1].value
	const bInput = inputs[2].value
	let textColor = '#ffffff'
	
	if (wInput > 50 && bInput <= 50) {
		textColor = '#000000'
	} else if (bInput > 50 && wInput <= 50) {
		textColor = '#ffffff'
	}
	
	document.body.style.setProperty('--text', textColor)
}

controls.addEventListener('input', (e) => {
	if (!e.target.id) return
	
	const { value } = e.target
	document.body.style.setProperty(`--${e.target.id}`, value)
	
	const results = inputs.map((input, i) => {
		return i === 0 ? `${input.value}%` : input.value
	}).join(' ')
	
	result.innerText = `hwb(${results})`
	
	// Change text color for accessibility
	setTextColor()
})
              
            
!
999px

Console