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><i>Star Trek: Discovery</i></h1>
<hgroup>
	<h2 id="s1">Season 1</h2>
	<button>
		<span aria-hidden="true">🔗</span>
		<span class="visually-hidden">copy to clipboard</span>
	</button>
</hgroup>
<hgroup>
	<h3 id="s1c1">Chapter 1</h3>
	<button>
		<span aria-hidden="true">🔗</span>
		<span class="visually-hidden">copy to clipboard</span>
	</button>
</hgroup>
<p>The series begins around ten years before the events of <i>Star Trek: The Original Series</i>, when Commander Michael Burnham’s actions start a war between the United Federation of Planets and the Klingon Empire. She is court-martialed, stripped of rank, and reassigned to the USS <i>Discovery</i>, which has a unique means of propulsion called the “Spore Drive”.</p>
<hgroup>
	<h3 id="s1c2">Chapter 2</h3>
	<button>
		<span aria-hidden="true">🔗</span>
		<span class="visually-hidden">copy to clipboard</span>
	</button>
</hgroup>
<p>After an adventure in the Mirror Universe, <i>Discovery</i> helps end the Klingon war.</p>
<hgroup>
	<h2 id="s2">Season 2</h2>
	<button>
		<span aria-hidden="true">🔗</span>
		<span class="visually-hidden">copy to clipboard</span>
	</button>
</hgroup>
<p>In the second season they investigate seven mysterious signals and a strange figure known as the “Red Angel”, and fight off a rogue artificial intelligence. This conflict ends with the <i>Discovery</i> traveling to the 32nd century, more than 900 years into their future.</p>
              
            
!

CSS

              
                body {
	font: 1em/1.4 Lato, sans-serif;
	max-width: 68ch;
}

hgroup {
	display: flex;
	align-items: end;
	gap: 1em;
}

h1, h2, h3, h4, h5, h6 {
	margin-block: 1em 0;
}

.visually-hidden:not(:focus):not(:active) {
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	height: 1px;
	overflow: hidden;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}
              
            
!

JS

              
                document.body.addEventListener('click', (event) => {
	const buttonElement = event.target.closest('button');
	
	if (buttonElement) {
		const hash = buttonElement.closest('hgroup')?.querySelector('h1, h2, h3, h4, h5, h6')?.id;		
		writeClipboardText(`${window.location.protocol}${window.location.host}${window.location.pathname}${window.location.search}#${hash}`);
	}
});

async function writeClipboardText(text) {
	try {
		await navigator.clipboard.writeText(text);
	}
	catch (error) {
		console.error(error.message);
	}
}
              
            
!
999px

Console