Pen Settings



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


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.


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.


	<h1>Web Components - Named Slots, Style Overrides, and Parts</h1>	
		/* You can style slotted content from the outside... */
		[slot="heading"] {
			background: red;
		/* But you can't style shadow DOM styles from outside. */
		x-component .part-example {
			background: green;
		/* Unless you use a hook like `::part()`! */
		/* */
		x-component::part(example) {
			background: lightblue;
		<h2 slot="heading">Multiple Slots</h2>
		<div slot="content">
			<p>Woah! You can define <em>multiple</em> named slots to pass content into your web component.</p>
			<p>How cool is that?</p>
		Don't forget you can still use the "default" slot for content too.



                html {
	box-sizing: border-box;

::before {
	box-sizing: inherit;

body {
	margin: 1rem auto 3rem;
	line-height: 1.4;
	tab-size: 4;

main {
	max-width: 42rem;
	margin: 0 auto;
	padding-inline: 1rem;

pre {
	padding: 1rem;
	overflow: auto;
	border: 1px solid #ccc;

/* ul li { margin: 1rem 0; } */
/* ul li li { margin: 0.5rem 0; } */

/* Colors */
.colors > *:nth-child(7n + 1) { background-color: red; }
.colors > *:nth-child(7n + 2) { background-color: orange; }
.colors > *:nth-child(7n + 3) { background-color: yellow; }
.colors > *:nth-child(7n + 4) { background-color: green; }
.colors > *:nth-child(7n + 5) { background-color: blue; }
.colors > *:nth-child(7n + 6) { background-color: indigo; }
.colors > *:nth-child(7n + 7) { background-color: violet; }



                // Make a new dynamic template.
const template = document.createElement('template');
template.innerHTML = `
		/* We can add styles inside our template. */
		div {
			padding: 1rem;
			border: 1px solid black;
			border-radius: 1rem;
			background: lightgray;
		/* And then override the slotted content styles on the inside. */
		/* */
		::slotted([slot="heading"]:first-child) {
			margin-top: 0;
			color: lightblue;
			/* But what specificity do we need to override the cascade? */
			/* It seems like the only way I can break out is with !important. */
			background: blue !important;
	<!-- And any other HTML we want too. -->
	<div class="part-example" part="example">
			To render dynamic "slotted" content,
			add a slot element:
		<slot name="heading" part="heading"></slot>
		<slot name="content"></slot>

class XComponent extends HTMLElement {
	constructor() {
		// Slots require the "Shadow DOM" API.
		// Shadow DOM also encapsulates CSS (and other cool features).
		// attachShadow() creates a shadow root instance.
		this.attachShadow({ mode: 'open' });
		// Instead of simply appending to our component's HTML,
		// now we append to its shadow root...

customElements.define('x-component', XComponent);