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

              
                <button class="toggle">Toggle Disclosure Widget State</button>

<div class="disclosure-widget">
	<h1 class="disclosure-widget__headline">CSS Stickers</h1>
	<p>A set of beautiful, cute, and funny CSS stickers to showcase your love for CSS.</p>
	<p><a href="https://stickers.css-weekly.com" target="_blank">Check out CSS Stickers »</a></p>
</div>
              
            
!

CSS

              
                body {
	margin: 0;
	padding-block: 1rem;
	padding-inline: 2rem;
	min-block-size: 100vb;
	box-sizing: border-box;
	line-height: 1.5;
	font-size: 1.2rem;
	font-family: sans-serif;
	background: linear-gradient(
		to right bottom, 
		hsl(225deg 76% 48%), 
		hsl(225deg 71% 40%), 
		hsl(220deg 40% 11%)
	);
}

a {
	color: hsl(225deg 76% 48%);
}

p {
	margin-block: 1rem;
}

code {
	white-space: nowrap;
}

.notice { 
	max-inline-size: 30rem;
	margin-inline: auto;
	margin-block: 0rem 3rem;
	color: hsl(0 100% 95%);
	text-align: center;
	text-wrap: balance;
	display: no<p class="notice">…</p>ne; 
	background: hsl(0 70% 30% / 0.8);
	border: 1px solid hsl(0 70% 35% / 0.8);
	padding: 2rem;
	border-radius: 0.5rem;
}

.disclosure-widget[open] + .notice {
	margin-block-start: 2rem;
}

.toggle {
	position: relative;
	display: block;
	width: auto;
	margin-block: 1rem 2rem;
	margin-inline: auto;
	padding-block: 0.8rem;
	padding-inline: 1.5rem;
	color: hsl(261deg 100% 25%);
	text-decoration: none;
	cursor: pointer;
	background: hsl(261deg 100% 95%);
	border: 1px solid hsl(0 0% 10%);
	border-radius: 0.5rem;
	transition: all 0.4s ease-in-out;
}

.toggle:hover {
	color: hsl(261deg 100% 15%);
	background: hsl(261deg 100% 100%);
}

.toggle:active {
	inset-block-start: 0.1rem;
	inset-inline-start: 0.1rem;
}

.disclosure-widget {
	position: relative;
	max-inline-size: 30rem;
	margin-block: 2rem 0;
	margin-inline: auto;
	padding-block: 0;
	padding-inline: 2rem;
	overflow: hidden;
	border-radius: 0.5rem;
	background-image: linear-gradient(
		to top left,
		hsl(260 80% 80%) 0,
		hsl(0 100% 95%)
	);
}

.disclosure-widget__headline { 
	margin-block-start: 0;
	margin-block-end: 1rem;
	line-height: 1;
	color: hsl(225deg 71% 20%);
}

.disclosure-widget > :first-child {
	margin-block-start: 2.5rem;
}

.disclosure-widget > :last-child {
	margin-block-end: 2.5rem;
}

/* Demo Code */
.disclosure-widget {
	height: 0;
	transition: all 0.7s ease-in-out;
}
	
.disclosure-widget[open] {
	/* Custom styles for the open state. */
}
              
            
!

JS

              
                // The video guide: https://youtu.be/1VsMKz4Zweg

// Get page elements
const toggle = document.querySelector('.toggle');
const widget = document.querySelector('.disclosure-widget');

// Widget State
let isOpen = false;

// Get the widget open/closed height
// 1. Get the closed state height (could be different from 0, based on CSS)
// 2. Set the 'height' to auto to force content-sized dimensions
// 3. Store the open widget height in 'px' units
// 4. Return the widget to its intial height
// This is necessary but suboptimal as if forces the browser to do extra layouts.
const closedHeight = widget.style.height;
widget.style.height = 'auto';
const openHeight = widget.offsetHeight + 'px';
widget.style.height = closedHeight;

// Toggle the open/close widget state on click of the 'toggle' button
toggle.addEventListener('click', (e) => {
	let height = isOpen ? closedHeight : openHeight;
	
	widget.toggleAttribute('open');
	widget.style.height = height;
	isOpen = !isOpen;
});

              
            
!
999px

Console