Pen Settings



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


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


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.


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.


                <h1>3D Cube Image Gallery</h1>

<div class="cube-container">

	<div class="cube initial-position">

		<img class="cube-face-image image-1" src="">
		<img class="cube-face-image image-2" src="">
		<img class="cube-face-image image-3" src="">
		<img class="cube-face-image image-4" src="">
		<img class="cube-face-image image-5" src="">
		<img class="cube-face-image image-6" src="">



<h2>Click the images below to rotate the cube</h2>

<div class="image-buttons">

	<input type="image" class="show-image-1" src=""></input>

	<input type="image" class="show-image-2" src=""></input>

	<input type="image" class="show-image-3" src=""></input>

	<input type="image" class="show-image-4" src=""></input>

	<input type="image" class="show-image-5" src=""></input>

	<input type="image" class="show-image-6" src=""></input>




Full-page view:


@import url(;

:root {
	/* Base font size */
	font-size: 10px;

	/* Border color variable */
	--border-color: #e70;

* {
	box-sizing: border-box;

body {
	font-family: "Montserrat", Arial, sans-serif;
	font-weight: 500;
	line-height: 1.5;
	text-align: center;
	min-height: 100vh;
	padding: 4rem 2rem;
	color: #fafafa;
	background-color: #080808;

h1 {
	font-size: 4rem;

h2 {
	font-size: 2rem;
	margin-bottom: 2.5rem;

.cube-container {
	position: relative;
	width: 30rem;
	height: 30rem;
	margin: 5rem auto 6rem;
	perspective: 100rem;

.cube {
	position: absolute;
	width: 100%;
	height: 100%;
	transform-style: preserve-3d;
	transition: transform 1s cubic-bezier(0.32, 0.05, 0.35, 1.6);

.cube-face-image {
	display: block;
	position: absolute;
	/* opacity: 0.95; */
	/* border: 0.2rem solid #fafafa; */
	box-shadow: 0 0 0.5rem #fff, 
				0 0 1.5rem var(--border-color),
				0 0 3rem var(--border-color);

.image-buttons {
	display: grid;
	grid-template-columns: repeat(3, auto);
	grid-gap: 1.5rem;
	justify-content: center;

.image-buttons input {
	border: 0.2rem solid #fafafa;

.image-buttons input:focus {
	outline: none;
	border: 0.2rem solid var(--border-color);

/* Transform images to create cube */

.image-1 {
	transform: translateZ(15rem);

.image-2 {
	transform: rotateX(-180deg) translateZ(15rem);

.image-3 {
	transform: rotateY(90deg) translateZ(15rem);

.image-4 {
	transform: rotateY(-90deg) translateZ(15rem);

.image-5 {
	transform: rotateX(90deg) translateZ(15rem);

.image-6 {
	transform: rotateX(-90deg) translateZ(15rem);

/* Transform cube to show correct image */

.cube.initial-position {
	transform: translateZ(-15rem) translateY(-2rem) rotateX(-15deg) rotateY(18deg) rotateZ(2deg);
} {
	transform: translateZ(-15rem);
} {
	transform: translateZ(-15rem) rotateX(180deg);
} {
	transform: translateZ(-15rem) rotateY(-90deg);
} {
	transform: translateZ(-15rem) rotateY(90deg);
} {
	transform: translateZ(-15rem) rotateX(-90deg);
} {
	transform: translateZ(-15rem) rotateX(90deg);



                //DOM load event
window.addEventListener("DOMContentLoaded",	() => {
	const cube = document.querySelector(".cube"),
		  imageButtons = document.querySelector(".image-buttons");
	let cubeImageClass = cube.classList[1];

	//Add click event listener to image buttons container
	imageButtons.addEventListener("click", e => {
		//Get node type and class value of clicked element
		const targetNode =,
			  targetClass =;

		//Check if image input has been clicked and isn't the currently shown image
		if (targetNode === "INPUT" && targetClass !== cubeImageClass) {
			console.log(`Show Image: ${targetClass.charAt(11)}`);

			//Replace previous cube image class with new class
			cube.classList.replace(cubeImageClass, targetClass);

			//Update cube image class variable with new class
			cubeImageClass = targetClass;