css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!-- Lightbox usage markup -->
<link href="https://fonts.googleapis.com/css?family=Raleway:200,100,400" rel="stylesheet" type="text/css" />
<h1>Mostly CSS Lightbox</h1>
<p>Supports images, youtube, and vimeo content.</p>

<!-- thumbnail image wrapped in a link -->
<a class="thumbnail" href="#img1" onclick="lightboxShow('img1'); return false;" style="background-image: url(https://unsplash.it/240/135?image=1044);">image 1</a>

<a class="thumbnail" href="#img2" onclick="lightboxShow('img2'); return false;" style="background-image: url(https://unsplash.it/240/135?image=1033);">image 2</a>

<a class="thumbnail" href="#img3" onclick="lightboxShow('img3'); return false;" style="background-image: url(https://unsplash.it/240/135?image=877);">image 3</a>


<a class="thumbnail" href="#img4" onclick="lightboxShow('img4'); return false;" style="background-image: url(https://unsplash.it/240/135?image=731);">image 4</a>

<a class="thumbnail" href="#img5" onclick="lightboxShow('img5'); return false;" style="background-image: url(https://unsplash.it/240/135?image=476);">image 5</a>

<a class="thumbnail" href="#img6" onclick="lightboxShow('img6'); return false;" style="background-image: url(https://unsplash.it/240/135?image=599);">image 6</a>

<!-- lightbox containers hidden with CSS -->
<a class="lightbox animate" href="#!" onclick="lightboxHide('img1'); return false;" id="img1">
	<img class="animate" src="https://unsplash.it/1280/720?image=1044" alt="image 1" /><span class="close"></span></a>

<a class="lightbox animate" href="#!" onclick="lightboxHide('img2'); return false;" id="img2">
	<img class="animate" src="https://unsplash.it/1280/720?image=1033" alt="image 2" /><span class="close"></span></a>

<a class="lightbox animate" href="#!" onclick="lightboxHide('img3'); return false;" id="img3">
	<img class="animate" src="https://unsplash.it/1280/720?image=877" alt="image 3" /><span class="close"></span></a>

<a class="lightbox animate" href="#!" onclick="lightboxHide('img4'); return false;" id="img4">
	<img class="animate" src="https://unsplash.it/1280/720?image=731" alt="image 4" /><span class="close"></span></a>

<a class="lightbox animate" href="#!" onclick="lightboxHide('img5'); return false;" id="img5">
	<img class="animate" src="https://unsplash.it/1280/720?image=476" alt="image 5" /><span class="close"></span></a>

<a class="lightbox animate" href="#!" onclick="lightboxHide('img6'); return false;" id="img6">
	<img class="animate" src="https://unsplash.it/1280/720?image=599" alt="image 6" /><span class="close"></span></a>


<!-- thumbnails wrapped in a link -->
<a class="thumbnail" href="#vid1" onclick="lightboxShow('vid1'); vid1.playVideo(); return false;" style="background-image: url(https://i1.ytimg.com/vi/ZVkT-kunlWw/hqdefault.jpg);">YouTube video</a>

<a class="thumbnail" href="#vid2" onclick="lightboxShow('vid2'); vid2.play(); return false;" style="background-image: url(https://i.vimeocdn.com/video/545172616_600x340.jpg);">Vimeo video</a>

<a class="thumbnail" href="#vid3" onclick="lightboxShow('vid3'); vid3.play(); return false;" style="background-image: url(https://i.vimeocdn.com/video/593475133_600x340.jpg);">Vimeo video</a>

<!-- lightbox containers hidden with CSS -->
<div class="lightbox animate" id="vid1">
	<a class="close" href="#!" onclick="lightboxHide('vid1'); vid1.pauseVideo(); return false;"></a>
	<iframe class="animate" src="https://www.youtube.com/embed/ZVkT-kunlWw?enablejsapi=1" allowfullscreen onload="vid1=new YT.Player(this)"></iframe></div>

<div class="lightbox animate" id="vid2">
	<a class="close" href="#!" onclick="lightboxHide('vid2'); vid2.pause(); return false;"></a>
	<iframe class="animate" src="https://player.vimeo.com/video/146707828" width="100%" height="100%" allowfullscreen onload="vid2=new Vimeo.Player(this)"></iframe>

<div class="lightbox animate" id="vid3">
	<a class="close" href="#!" onclick="lightboxHide('vid3'); vid3.pause(); return false;"></a>
	<iframe class="animate" src="https://player.vimeo.com/video/183607212" allowfullscreen onload="vid3=new Vimeo.Player(this)"></iframe></div>


<p> While this uses only HTML and CSS for layout and animation, it <i>does</i> require Javascript to allow for automated play/pause when opening/closing the layer. In addition, this variation also uses Javascript to override default :target behaviour to set states. This stops the browser history from filling up with endless anchor links, but if javascript is disabled, the :target behaviour still works as expected.</p>

<p>YouTube and Vimeo API scripts are loaded in the header, while the iframes include onload actions to initialise the APIs, and the anchor elements include onclick actions for setting status.</p>

<h3>Known bugs:</h3>

<p>The YouTube API will not automatically restart a finished video until the second "play" commend. This means watching a video, letting it finish, then closing and re-opening the lightbox will not autoplay from the begining, but trying a second time will.</p>

<p>If the lightbox closing animation hasn't finished yet, clicks can sometimes catch the video in mid-scale, causing the media to start playing again (continuing while invisible) or activating other buttons. Speeding up the animation can help prevent this, or simply removing animation entirely (delete the "animation" class from the lightbox elements).</p>
              /*Eliminates padding, sets up document style */

body, html {
	padding: 0;
	margin: 0;
	text-align: center;
	font-family: 'Raleway', sans-serif;
	font-size: 18px;
	color: #888480;
	background-color: #202428;

p {
	width: 40%;
	min-width: 420px;
	max-width: 800px;
	margin: 30px auto;
	line-height: 1.3em;

/* Removes browser highlight outlines for all links */

a {
	color: #fff;
	text-decoration: none;

a:focus {
	outline: none;

/* Styles the thumbnail */

.thumbnail {
	/* make link text transparent, but retain content for accessibility */
	color: rgba(255, 255, 225, 0);
	/* positioning and styling of thumbnails */
	position: initial;
	display: inline-block;
	width: 240px;
	height: 135px;
	background-position: center center;
	background-size: cover;
	border: 2px solid white;
	margin: 20px;
	border-radius: 10px;

/* Styles the lightbox elements, removes it from sight and defines animation curves */

.lightbox {
	position: fixed;
	display: block;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	background: #000;
	background: rgba(0, 0, 0, .75);
	visibility: hidden;
	opacity: 0;
	/*	z-index: 999;*/

.close {
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;

.animate {
	-webkit-transition: .15s ease-in-out;
	-moz-transition: .15s ease-in-out;
	-ms-transition: .15s ease-in-out;
	-o-transition: .15s ease-in-out;
	transition: .15s ease-in-out;

/* Styles the lightbox content, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */

.lightbox img {
	position: absolute;
	display: block;
	margin: auto;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	max-width: 30%;
	max-height: 30%;
	border: 2px solid white;
	/*	box-sizing: border-box;*/

.lightbox iframe {
	position: absolute;
	display: block;
	margin: auto;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 30vw;
	/* 30% of viewport width */
	height: 16.875vw;
	/* 9/16 * 30 = 16.875 */
	max-height: 30vh;
	/* 30% of viewport height */
	max-width: 53.333333333vh;
	/* 16/9 * 90 = 53.333333333 */
	border: 2px solid white;
	/*	box-sizing: border-box;*/

/* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox anchor */

.lightbox:target, .overlay {
	visibility: visible;
	opacity: 1;

.lightbox:target img, .overlay img {
	max-width: 90%;
	max-height: 90%;

.lightbox:target iframe, .overlay iframe {
	width: 90vw;
	/* 90% of viewport width */
	height: 50.625vw;
	/* (9/16) * 90 = 50.625 */
	max-height: 90vh;
	/* 90% of viewport height */
	max-width: 160vh;
	/* (16/9) * 90 = 160 */

              // ClassList approach taken from https://stackoverflow.com/questions/195951/change-an-elements-class-with-javascript

function lightboxShow(id) {

function lightboxHide(id) {
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................