cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

              <img width="1400" height="900" src="https://placehold.it/1400x900" data-basicLightbox data-id="0">
<a href="#" class="button" data-show-id="0">img</a>

<iframe width="560" height="315" src="https://www.youtube.com/embed/Scxs7L0vhZ4" frameborder="0" allowfullscreen data-basicLightbox data-id="1"></iframe>
<a href="#" class="button" data-show-id="1">iframe</a>

<video controls data-basicLightbox data-id="2">
	<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4">
<a href="#" class="button" data-show-id="2">video</a>

<div data-basicLightbox data-id="3">
	<p>I'm a div inside a lightbox.</p>
<a href="#" class="button" data-show-id="3">div</a>

<div data-basicLightbox data-id="4">
	<p>Take a look at the console of your browser.<br>This lightbox will close automaticly to demonstrate the close-callback.</p>
<a href="#" class="button callbacks" data-show-id="4">callbacks</a>

<div data-basicLightbox data-id="5">
	<p>It's not possible to close this lightbox,<br>because the beforeClose function returns false.</p>
<a href="#" class="button blocked" data-show-id="5">blocked</a>

<div data-basicLightbox data-id="6">
	<p>No callback should fire, because non of them is a function.<br>No HTML should be appended, because non of them is a function or string.</p>
<a href="#" class="button invalid" data-show-id="6">invalid</a>

<div data-basicLightbox data-id="7">
	<p>It's possible to close this lightbox with a click (default).</p>
<a href="#" class="button closable" data-show-id="7">closable</a>

<div data-basicLightbox data-id="8">
	<h1>Not closable</h1>
	<p>It's not possible to close this lightbox with a click.</p>
<a href="#" class="button notclosable" data-show-id="8">not closable</a>

<div data-basicLightbox data-id="9">
	<h1>Custom HTML</h1>
	<p>You can add custom HTML before and after the HTML placeholder element.</p>
<a href="#" class="button custom" data-show-id="9">custom</a>

<div data-basicLightbox data-id="10">
	<h1>Custom classNames</h1>
	<p>You can add custom classNames to the lightbox element.</p>
<a href="#" class="button classNames" data-show-id="10">classNames</a>

<a href="#" class="button dynamic">dynamic</a>

<a href="#" class="button stack">stack</a>
              html {
	width: 100%;
	height: 100%;

body {
	text-align: center;
	min-height: 100%;
	font-size: 14px;
	color: white;

a.button {
	display: inline-block;
	margin: 50px 0;
	padding: 6px 10px;
	background: #2875ed;
	color: #fff;
	text-decoration: none;
	border-radius: 3px;
	user-select: none;

div.classNames {
	background: #2875ed;
              const getTargetHTML = function(elem) {

	const id = elem.getAttribute('data-show-id')
	const target = document.querySelector(`[data-id="${ id }"]`)

	return target.outerHTML


document.querySelectorAll('[data-show-id]').forEach(function(elem) {

	const html = getTargetHTML(elem)

	elem.onclick = basicLightbox.create(html).show


document.querySelector('.button.callbacks').onclick = function(e) {

	const html = getTargetHTML(this)

	const instance = basicLightbox.create(html, {
		beforeShow: (instance) => console.log('beforeShow', instance),
		afterShow: (instance) => console.log('afterShow', instance),
		beforeClose: (instance) => console.log('beforeClose', instance),
		afterClose: (instance) => console.log('afterClose', instance)

	instance.show((instance) => console.log('finished show()', instance))

	setTimeout(() => {

		instance.close((instance) => console.log('finished close()', instance))

	}, 3000)


document.querySelector('.button.blocked').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		beforeClose: () => false


document.querySelector('.button.invalid').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		closable: null,
		className: null,
		beforeShow: null,
		afterShow: null,
		beforeClose: null,
		afterClose: null,
		beforePlaceholder: null,
		afterPlaceholder: null


document.querySelector('.button.closable').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		closable: true


document.querySelector('.button.notclosable').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		closable: false


document.querySelector('.button.custom').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		beforePlaceholder: () => 'beforePlaceholder',
		afterPlaceholder: 'afterPlaceholder'


document.querySelector('.button.classNames').onclick = function(e) {

	const html = getTargetHTML(this)

	basicLightbox.create(html, {
		className: 'classNames one two three'


document.querySelector('.button.dynamic').onclick = function(e) {

	const html = `
		<h1>Dynamic Content</h1>
		<p>You can set the content of the lightbox with JS.</p>



const openStack = function(e) {

	const html = '<a class="button" href="#">Open another lightbox on top</a>'
	const instance = basicLightbox.create(html)

	instance.element().querySelector('.button').onclick = openStack


document.querySelector('.button.stack').onclick = openStack
🕑 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 ..................