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

              
                /* Page Style */
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;
}

.notice { 
	max-inline-size: 30rem;
	margin-inline: auto;
	margin-block: 0rem 3rem;
	color: hsl(0 100% 95%);
	text-align: center;
	text-wrap: balance;
	display: none; 
	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;
}

@supports not (transition-behavior: allow-discrete) {
	.notice { display: block; }
}

.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 {
	display: none;
	height: 0;
	transition: all 0.7s ease-in-out;
	/* transition-behavior: allow-discrete; */
}
	
.disclosure-widget[open] {
	/* @starting-style {
		height: 0;
	} */

	height: auto;
	height: calc-size(auto);
	
	/* Intentionally setting this to fixed value so that demo works in browsers that don't support calc-size() */
	height: 240px;
	/* display: block; */
}
              
            
!

JS

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

// Widget state
let isOpen = false;

// Set display to block immediately after clicking 
// the button before adding the "open" attribute 
// to ensure the CSS transition happens
toggle.addEventListener('click', (e) => {
	if (isOpen === false) {
		widget.style.display = 'block';
	}
	
	// Ensure the display is switched before
	// the "open" attribute is toggled
	requestAnimationFrame(() => {
		widget.toggleAttribute('open');
	});

	// Click always toggles the state
	isOpen = !isOpen;
});

// At the end of the transition, 
// when the widget is closed,
// hide it by changing the display value
widget.addEventListener('transitionend', (event) => {
	
	// We only want to trigger this on the close transition
	if (isOpen === false) {
		widget.style.display = 'none';
	}
});
              
            
!
999px

Console