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

              
                <svg class="sprite" viewBox="0 0 320 512" xmlns="http://www.w3.org/2000/svg">
	<defs>
		<path id="chevron-down" d="M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z" />
	</defs>
</svg>

<nav>
	<menu id="anchor_1">
		<li>
			<button class="menu-button" popovertarget="submenu_1">
				<span>Open submenu 1</span>
				<svg viewBox="0 0 320 512">
					<use href="#chevron-down"></use>
				</svg>
			</button>
			<div class="positioned-menu" popover id="submenu_1">
				<h2>Submenu 1</h2>
				<menu class="submenu">
					<li>
						<button popovertarget="item_1-level_2-submenu_1">
							<span>Open nested submenu 1</span>
							<svg viewBox="0 0 320 512">
								<use href="#chevron-down"></use>
							</svg>
						</button>
						<menu class="submenu-level-2" id="item_1-level_2-submenu_1" popover>
							<li><a href="#0">Submenu 1 Item 1 Sub item 1</a></li>
							<li><a href="#0">Submenu 1 Item 1 Sub item 2</a></li>
						</menu>
					</li>
					<li>
						<button popovertarget="item_1-level_2-submenu_2">
							<span>Open nested submenu 2</span>
							<svg viewBox="0 0 320 512">
								<use href="#chevron-down"></use>
							</svg>
						</button>
						<menu class="submenu-level-2" id="item_1-level_2-submenu_2" popover>
							<li><a href="#0">Submenu 1 Item 2 Sub item 1</a></li>
							<li><a href="#0">Submenu 1 Item 2 Sub item 2</a></li>
						</menu>
					</li>
					<li><a href="#0">Sub item 3</a></li>
				</menu>
			</div>
		</li>
		<li>
			<button class="menu-button" popovertarget="submenu_2">
				<span>Open submenu 2</span>
				<svg viewBox="0 0 320 512">
					<use href="#chevron-down"></use>
				</svg>
			</button>
			<div class="positioned-menu" popover id="submenu_2">
				<h2>Submenu 2</h2>
				<menu class="submenu">
					<li><a href="#0">Sub item 1</a></li>
					<li><a href="#0">Sub item 2</a></li>
					<li><a href="#0">Sub item 3</a></li>
				</menu>
			</div>
		</li>
		<li>
			<button class="menu-button" popovertarget="submenu_3">
				<span>Open submenu 3</span>
				<svg viewBox="0 0 320 512">
					<use href="#chevron-down"></use>
				</svg>
			</button>
			<div class="positioned-menu" popover id="submenu_3">
				<h2>Submenu 3</h2>
				<menu class="submenu">
					<li><a href="#0">Sub item 1</a></li>
					<li><a href="#0">Sub item 2</a></li>
					<li><a href="#0">Sub item 3</a></li>
				</menu>
			</div>
		</li>
	</menu>
</nav>

<main>
	<div class="warning">
		<p>⚠️ It looks like your browser doesn’t support anchor positioning.</p>
	</div>
</main>


              
            
!

CSS

              
                body {
	font-family: 'Helvetica', sans-serif;
	min-height: 100vh;
	overflow-x: hidden;
}

main {
	padding: 1rem;
}

h2 {
	font-size: 1.8rem;
	font-weight: bold;
	margin-block: 1rem;
}

a {
	text-decoration-color: transparent;
	color: inherit;
	display: block;
	padding: 0.5rem 1rem;
	
	&:hover {
		text-decoration-color: inherit;
	}
}

.sprite {
	display: none;
}

button {
	border: none;
	background: transparent;
	padding: 0.75rem 1rem;
	font-family: inherit;
	font-size: inherit;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	text-align: left;
	
	& svg {
		flex: 0 0 0.75rem;
		transition: transform 150ms;
	}
	
	& span {
		width: max-content;
		flex: 1 0 auto;
	}
}

menu {
	list-style: none;
}

nav {
	background: whitesmoke;
}

nav > menu {
	padding: 0.5rem 1rem;
	display: flex;
	flex-wrap: wrap;
	justify-content: end;
	gap: 1rem;
}

#anchor_1 {
	anchor-name: --anchor_1;
}

.positioned-menu {
	--bg: hotpink;
	width: 100%;
	max-width: 100vw;
	padding: 1rem;
	background: color-mix(in srgb, var(--bg), transparent);
	flex-wrap: wrap;
	gap: 1rem;
	will-change: height;
	height: 0;
	display: none;
	transition: opacity 250ms, height 250ms, display 250ms allow-discrete, overlay 250ms allow-discrete;
	overflow: hidden;
	
	/* Position */
	top: anchor(--anchor_1 bottom);
	left: anchor(--anchor_1 left);
	
	&:popover-open {
		display: block;
		opacity: 1;
		height: calc(100vh - 3rem);
		
		@starting-style {
			opacity: 0;
			height: 0;
		}
	}
}

.submenu {
	margin-left: -1rem;
	border-right: 1px solid var(--bg);
	max-width: calc(100% / 3);
	anchor-name: --anchor_2;
	
	& button {
		width: 100%;
		text-decoration: underline;
		text-decoration-color: transparent;
		
		&:hover {
			text-decoration-color: inherit;
		}
		
		& svg {
			transform: rotate(-90deg);
		}
	}
}

.submenu-level-2 {
	display: none;
	top: anchor(--anchor_2 top);
	left: anchor(--anchor_2 right);
	width: calc(100% / 3);
	background: transparent;
}

/* Only apply the transition to the nested submenu when the parent menu is open.
That prevents the nested menu staying visible outside of its parent when you close the parent 🙃 */
:popover-open {
	.submenu-level-2 {
		transition: opacity 200ms, display 200ms allow-discrete, overlay 200ms allow-discrete;

		&:popover-open {
			display: block;
			opacity: 1;

			@starting-style {
				opacity: 0;
			}
		}
	}
}

#submenu_2 {
	--bg: lightblue;
}

#submenu_3 {
	--bg: turquoise;
}

li:has(.positioned-menu:popover-open) {
	.menu-button svg {
		transform: rotate(180deg);
	}
}

@supports (anchor-name: --anchor_1) and (top: anchor(--anchor_1 bottom)) {
	.warning {
		display: none;
	}
}


              
            
!

JS

              
                
              
            
!
999px

Console