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

              
                <header id="page-header">
	<a id="skip-link" href="#main">main page content</a>
	<p>A Dao of Web Design</p>
	<nav>
		<button aria-controls="main-menu" hidden="">
			<span class="when-aria-expanded-false">
				<svg viewBox="-0.1 -0.1 1.2 1.2">
					<path d="M0,0.1 h1 M0,0.5 h1 M0,0.9 h1"/>
				</svg>
				Menu
			</span>
			<span class="when-aria-expanded-true">
				<svg viewBox="-0.1 -0.1 1.2 1.2">
					<path d="M0,0 l1,1 M0,1 l1,-1"/>
				</svg>
				Close
			</span>
		</button>
		<ul id="main-menu">
			<li><a href="#dao"><b>A Dao of Web Design</b> John Allsopp, 2000</a></li>
			<li><a href="#rwd"><b>Responsive Web Design</b> Ethan Marcotte, 2010</a></li>
			<li><a href="#iwd"><b>Intrinsic Web Design</b> Jen Simmons, 2018</a></li>
		</ul>
	</nav>
</header>

<main id="main">
	<blockquote>
		<p class="hanging-punctuation">“The control which designers know in the print medium, and often desire in the web medium, is simply a function of the limitation of the printed page. We should embrace the fact that the web doesn’t have the same constraints, and design for this flexibility. But first, we must ‘accept the ebb and flow of things.’&#x202F;”</p>
		<footer>—<cite class="hanging-punctuation">John Allsopp, “<a href="https://alistapart.com/article/dao">A&nbsp;Dao of Web Design</a>”</cite></footer>
	</blockquote>
</main>

              
            
!

CSS

              
                * { box-sizing: border-box }

body
{
	margin: 0;
}

html[data-main-menu-open="true"]
{
	overflow: hidden;
}

#skip-link
{
	position: absolute;
	z-index: 2;
	left: 0;
	top: 0;
	padding: 1em;
	text-decoration: inherit;
	transform: translateY(-100%);
	transition: 0.1s transform;
}

#skip-link:focus
{
	transform: translateY(0);
}

#page-header
{
	padding: 0.5em 1em;
	background: hsl(45, 100%, 70%);
	font-family: Source Sans Pro, Open Sans, Calibri, sans-serif;
}

[data-main-menu-js-enabled] #page-header
{
	display: flex;
	flex-flow: row wrap;
	justify-content: space-between;
	align-items: center;
}

#page-header > p
{
	flex: 1;
	text-align: center;
	font: 2em/1 LiebeDoris;
	margin: 0;
}

#page-header > nav
{
	/* order: -1; */
}

button[aria-controls="main-menu"]
{
	font: inherit;
	min-width: 5.5em;
	position: relative;
	z-index: 1;
}

[data-main-menu-js-enabled] button[aria-controls="main-menu"][aria-expanded="true"] .when-aria-expanded-false,
[data-main-menu-js-enabled] button[aria-controls="main-menu"]:not([aria-expanded="true"]) .when-aria-expanded-true
{
	display: none;
}

button[aria-controls="main-menu"] svg
{
	width: 0.8em;
	stroke: currentcolor;
	stroke-width: 0.2;
	vertical-align: -0.1em;
}

#main-menu
{
	background: hsl(0, 0%, 95%);
	margin: 1em -1em -0.5em;
	list-style: none;
	list-style: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E"); /* Safari hack, see https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html */
	padding: 0;	
}

[data-main-menu-js-enabled] #main-menu
{
	margin: 0;
	position: absolute;
	right: 0; /* left: 0; */
	bottom: 0;
	top: 3em;
	top: var(--page-header-height, 3em);
	width: 80%;
	max-width: 20em;
	transform-origin: right; /* left */
	transition: transform 0.1s;
	overflow: auto;
	border-left: thin solid silver; /* border-right */
}

#main-menu li
{
	border-bottom: thin solid silver;
}

#main-menu a
{
	display: block;
	padding: 0.5em 1em;
	color: currentColor;
	text-decoration: none;
}

#skip-link,
#main-menu a:focus
{
	background: black;
	color: white;
}

[data-main-menu-js-enabled] button[aria-controls="main-menu"]:not([aria-expanded="true"]) + #main-menu
{
	transform: scaleX(0);
}



#main-menu b
{
	display: block;
	font-size: 1.2em;
	font-weight: normal;
}

main
{
	height: 100vh;
	font: 1em/1.5 xSource Serif Pro, Georgia Pro, Georgia, serif;
}

blockquote p
{
	font-size: 1.5em;
	font-style: italic;
	max-width: 24em;
	hanging-punctuation: first;
	margin: 2em 0 0.5em;
}

blockquote cite
{
	font-style: normal;
}

@supports not (hanging-punctuation: first)
{
	blockquote :first-child
	{
		text-indent: -0.4em;
	}
}

	
              
            
!

JS

              
                String.prototype.toCamelCase = function () {
	return this.replace(/-(.)/g, (match, p1) => p1.toUpperCase());
};

class Collapsible
{
	constructor(id, isNotHidden)
	{
		this.id = id;
		this.isNotHidden = isNotHidden;
		
		if (this.id)
		{
			this.element = document.getElementById(this.id);
			this.controlElement = document.querySelector(`[aria-controls="${this.id}"]`);
		}
		
		if (this.element && this.controlElement)
		{		
			this.idCamelCased = this.id.toCamelCase();
			document.documentElement.dataset[`${this.idCamelCased}JsEnabled`] = true;

			this.controlElement.hidden = false;

			this.controlElement.addEventListener('click', event => {
				this.toggle();
			});

			this.links = Array.from(this.element.querySelectorAll('a[href]'));

			document.documentElement.addEventListener('click', event => {
				if (event.target.closest('button') !== this.controlElement && !event.target.closest(`#${this.id}`))
				{
					this.close();
				}
			});

			const keyupHandler = (event) => {
				if (event.code === 'Escape')
				{
					this.close();
					this.controlElement.focus();
				}
			}

			this.element.addEventListener('keyup', keyupHandler);
			this.controlElement.addEventListener('keyup', keyupHandler);
		}
	}
	
	toggle(force)
	{
		if (this.element)
		{		
			this.isToBeVisible = (force !== undefined) ? force : !this.isToBeVisible;
			this.controlElement.setAttribute('aria-expanded', this.isToBeVisible);
			document.documentElement.dataset[`${this.idCamelCased}Open`] = this.isToBeVisible;
			
			if (this.isNotHidden)
			{
				this.element.setAttribute('aria-hidden', !this.isToBeVisible);
				this.links.forEach(link => {
					link.tabIndex = this.isToBeVisible ? 0 : -1;
				});
			}
			else
			{
				this.element.hidden = !this.isToBeVisible;
			}
		}
	}
		
	open()
	{
		this.toggle(true);
	}
		
	close()
	{
		this.toggle(false);
	}
};

(function ()
{
	'use strict';
	
	new Collapsible('main-menu', true);

	const pageHeaderElement = document.querySelector('#page-header');
	
	pageHeaderElement.setHeightCustomProperty = () => {
		if (window.CSS && CSS.supports && CSS.supports('--page-header-height: 0'))
		{
			pageHeaderElement.style.setProperty('--page-header-height', `${pageHeaderElement.offsetHeight}px`);
		}
		else
		{
			document.querySelector('#main-menu').style.setProperty('top', `${pageHeaderElement.offsetHeight}px`);
		}
	};

	window.addEventListener('DOMContentLoaded', pageHeaderElement.setHeightCustomProperty);
	window.addEventListener('resize', pageHeaderElement.setHeightCustomProperty);
})();

              
            
!
999px

Console