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>Override slotted element styling</h1>

<!--
	This is Demonstration of attaching a Shadow DOM to a basic HTML Element.
 	Some of the elements point to a slot using the slot attribute.
-->
<div id="demodiv" hidden>
	<h2 slot="heading">This heading slot is Navy</h2>
	<p slot="subheading">As defined in the Shadow DOM</p>
	<p>The Element.attachShadow() method attaches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot. <br>This text is now purple.</p>
	<p>Note that you can attach a shadow root to basic HTML Elements. Not only Custom Elements.</p>

</div>

	

<!--
	This is a template element that also contains slot elements.
 	The named slots are the targets of elements with slot attribute above. 
-->
<template id="template">
	<style>
		:host {
			margin-block-start: 1em;
			padding-block: 1ex;
			padding-inline: 3ch;
			background: lightBlue;
		}
	</style>
	<header>
		<slot name="subheading"></slot>
		<slot name="heading"></slot>
	</header>
	<slot></slot>
</template>
              
            
!

CSS

              
                body {
	color: canvasText;
}

h2 {
	color: green;
}
p {
	color: blue;
}

              
            
!

JS

              
                // Get the DIV 
const div = document.getElementById("demodiv");

// Get the Template
const { content } = document.getElementById('template');

// Attach a shadowRoot to the DIV
const shadowRoot = div.attachShadow({ mode: "closed" });

// Insert the template into the shadowRoot
shadowRoot.appendChild(content.cloneNode(true));

// Show the DIV
div.removeAttribute('hidden');


const sheet = new CSSStyleSheet();
sheet.replaceSync(`
	#demodiv {
		& h2 {
			color: navy;
		}
		& p {
			color: purple;
		}
		& [slot="subheading"] {
			color: steelBlue;
			font-size: 1.3333rem;
			font-weight: 300;
		}
	}
`);

document.adoptedStyleSheets.push(sheet);
              
            
!
999px

Console