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 lang="en">
	<a
		class="lightbox-link"
		href="https://images.unsplash.com/photo-1611042553365-9b101441c135?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2000&q=40"
	>
		<img
			src="https://images.unsplash.com/photo-1611042553484-d61f84d22784?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8d29tYW4lMjBoYXR8ZW58MHx8MHx8&auto=format&fit=crop&w=400&q=20"
			width="200"
			height="250"
			alt="woman with hat and colored fingernails"
		/>
	</a>
	<a
		class="lightbox-link"
		href="https://images.unsplash.com/photo-1610441995419-a673724a8224?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8NjZ8fHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=2000&q=40"
	>
		<img
			src="https://images.unsplash.com/photo-1610360665397-c78136fff4e7?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8Njd8fHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=400&q=20"
			width="200"
			height="250"
			alt="woman making faces"
		/>
	</a>
	<footer>
		Photos by
		<a href="https://unsplash.com/@raaminka" target="_top">Raamin ka</a>
		on Unsplash
	</footer>
</main>
<dialog id="lightbox">
	<img/>
	<button id="lightbox-close-button">close</button>
</dialog>
              
            
!

CSS

              
                body {
	margin: 0;
	font: 300 1em/1.4 Fira Sans, Calibri, sans-serif;
	text-transform: uppercase;
	letter-spacing: 0.11em;
}

main {
	padding: 1em;
	display: flex;
	flex-wrap: wrap;
	align-items: end;
	gap: 1em;
}

a {
	outline-offset: 0.3em;
	color: currentColor;
	text-decoration-color: darkgray;
	text-underline-offset: 0.2em;
}

.lightbox-link img {
	display: block;
	width: auto;
	height: 12em;
}

footer {
	width: 100%;
	margin-top: -0.5em;
}

#lightbox[open] {
	width: 100vw;
	height: 100vh;
	max-width: 100vw;
	max-height: 100vh;
	border: none;
	padding: 0;
	margin: 0;
	display: grid;
	justify-content: center;
	align-content: center;
	background: hsl(40deg 40% 10% / 80%);
}

#lightbox img {
	display: block;
	max-width: 100vw;
	max-height: 100vh;
	outline: 0.02em solid white;
}

#lightbox-close-button {
	position: absolute;
	inset: 1em 1em auto auto;
	font: inherit;
	text-transform: inherit;
	letter-spacing: inherit;
	border: transparent;
	background: transparent;
	color: white;
}

#lightbox-close-button::before {
	content: '✕ ';
	content: '✕ ' / '';
	font-weight: 800;
}

              
            
!

JS

              
                const lightbox = document.querySelector('#lightbox');
const lightboxImage = lightbox.querySelector('img');
const lightboxCloseButton = lightbox.querySelector('#lightbox-close-button');

lightbox.showLightbox = (lightboxLink) => {
	const lightboxThumbnail = lightboxLink.querySelector('img');

	// show enlarged preview image while big image is being loaded
	lightboxImage.src = lightboxThumbnail.src;
	requestAnimationFrame(() => {
		lightboxImage.src = lightboxThumbnail.dataset.src ?? lightboxLink.href;
	});

	lightboxImage.srcset = lightboxThumbnail.dataset.srcset ?? '';
	lightboxImage.alt = lightboxThumbnail.dataset.alt ?? lightboxThumbnail.alt;

	lightbox.showModal();		
};

document.body.addEventListener('click', event => {
	const lightboxLink = event.target.closest('.lightbox-link');
	if (lightboxLink) {
		event.preventDefault();
		lightbox.showLightbox(lightboxLink);
	}
	
	// else if (event.target.closest('#lightbox-close-button')) {
	// 	lightbox.close();
	// }
	
	else if (lightbox.open && !event.target.closest('img')) {
		lightbox.close();
	}
});
              
            
!
999px

Console