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

              
                <main>
	<h1>Main content</h1>
	<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum, ipsum. Corrupti magnam ut autem eligendi doloribus tenetur repudiandae. Quae officia iusto doloremque repudiandae quaerat ipsa deleniti fugiat vero velit modi.</p>
	<button id="openDialog" class="primary">Open Dialog</button>
	<p>Woodlands payment Osgiliath tightening. Barad-dur follow belly comforts tender tough bell? Many that live deserve death. Some that die deserve life. Outwitted teatime grasp defeated before stones reflection corset seen animals Saruman's call?</p>
	<h2>Tad survive ensnare joy mistake courtesy Bagshot Row.</h2>
	<p>Ligulas step drops both? You shall not pass! Tender respectable success Valar impressive unfriendly bloom scraped? Branch hey-diddle-diddle pony trouble'll sleeping during jump Narsil.</p>
	<h3>North valor overflowing sort Iáve mister kingly money?</h3>
	<p>Curse you and all the halflings! Deserted anytime Lake-town burned caves balls. Smoked lthilien forbids Thrain?</p>
	<ul>
		<li>Adamant.</li>
		<li>Southfarthing!</li>
		<li>Witch-king.</li>
		<li>Precious.</li>
		<li>Gaffer's!</li>
	</ul>
</main>

<dialog id="testDialog" class="dialog">
	<h1>This is a native dialog</h1>
	<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Laudantium accusantium cupiditate, voluptate distinctio hic mollitia. Assumenda porro, maiores laboriosam, eaque amet qui natus voluptas aliquam odio facere quae asperiores quidem.</p>
	<div class="buttonRow">
		<button class="dialog--cancel">Cancel</button>
		<button class="dialog--confirm primary">Confirm</button>
	</div>
</dialog>
              
            
!

CSS

              
                html {
	min-height: 100%;
	margin: 0; 
	padding: 0;
}
body {
	background-color: #191919;
	background-image: linear-gradient(135deg, #1E1E1E, #111); background-repeat: no-repeat;
	box-sizing: border-box;
	color: #D5D6D8;
	font-family: system-ui,sans-serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	padding: 2rem;
	position: relative;
}

h1, h2, h3 {
	color: #FFF;
	font-weight: 700;
	line-height: 1.2;
	margin: 1.5em 0 .5em;
}
h1 {
	font-size: 3rem;
	margin-top: .25em;
}
h2 {font-size: 2.25rem;}
h3 {font-size: 1.75rem;}

p,li {
	font-size: 1.2rem;
	line-height: 1.5;
	margin: 1em 0 2em;
}

ul li {
	margin: .25em 0 .5em;
}

button {
	background: transparent;
	border: solid 2px #ABADB1;
	border-radius: .5rem;
	box-sizing: border-box;
	color: #FFF;
	font-size: 1rem; font-weight: 700;
	line-height: 1;
	margin: .25em 0 1em;
	min-width: 6em;
	padding: .75em 1em;
	text-align: center;
	transition: background .2s ease, border-color .2s ease;

	&:hover {
		background: #545454;
	}
	&:active {
		background: #1F1F1F;
		transition-duration: 0s;
	}
	&:focus {
		box-shadow: 
			0 0 0 3px #000,
			0 0 0 5px #FFF
			;
		outline: none;
	}
}

button.primary {
	background: #008659;
	border-color: transparent;

	&:hover {
		background: #146947;
	}
	&:active {
		background: #124d35;
	}
}


dialog {
	background-color: #1F1F1F;
	border-color: transparent;
	border-radius: .5rem;
	box-shadow: 0 4px 44px 10px rgba(0,0,0,.3);
	color: inherit;
	max-width: 44rem;
	padding: 2rem;

	&::backdrop {
		background: rgba(0,0,0,.82);
		backdrop-filter: blur(.25rem);
		-webkit-backdrop-filter: blur(.25rem);
	}

	button {

	}
}

.buttonRow {
	display: flex;
	gap: 1.5rem;

	button {
		margin-bottom: 0;
	}
}


@media screen and (max-width: 48rem) {
	dialog {
		border-radius: 0;
	}
}

@media screen and (prefers-reduced-motion: no-preference) {
	dialog[open] {
		animation: 4s fadeIn ease-out, 4s scaleUp ease-out;
		
		&::backdrop {
			animation: 2s fadeIn ease-out;
		}
	}
}



/* animation keyframes */
@keyframes fadeIn {
	0%     {
		opacity: 0;
	}
	100%   {
		opacity: 1;
	}
}

@keyframes scaleUp {
	0%     {
		transform: scale(.8);
	}
	100%   {
		transform: scale(1);
	}
}
/* end animation keyframes */
              
            
!

JS

              
                let openDialog;
let dialog;

function initDialog(dialog,trigger) {
	// get elements
	dialog = document.getElementById(dialog)
	trigger = document.getElementById(trigger);
	let cancel = dialog.querySelector('.dialog--cancel');
	let confirm = dialog.querySelector('.dialog--confirm');

	// show dialog on click
	trigger.addEventListener('click', function() {
		dialog.showModal();
	});

	// handle cancel click
	if(cancel) {
		cancel.addEventListener('click', function() {
			dialog.close();
			console.log('Canceled via button');
		});
	}

	// handle cancel event (escape key pressed)
	dialog.addEventListener('cancel',function(e) {
		console.log('Canceled via keyboard');
	});

	// handle confirm click
	confirm.addEventListener('click', function() {
		dialog.close();
		console.log('Confirmed');
	});
}

document.addEventListener('DOMContentLoaded', function(e) {
	console.clear();

	initDialog('testDialog','openDialog');
})
              
            
!
999px

Console