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.

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

<div class="cube-container">

	<div class="cube initial-position">

		<img class="cube-face-image image-1" src="https://images.unsplash.com/photo-1445810694374-0a94739e4a03?w=300&h=300&fit=crop">
		<img class="cube-face-image image-2" src="https://images.unsplash.com/photo-1515260268569-9271009adfdb?w=300&h=300&fit=crop">
		<img class="cube-face-image image-3" src="https://images.unsplash.com/photo-1506045412240-22980140a405?w=300&h=300&fit=crop">
		<img class="cube-face-image image-4" src="https://images.unsplash.com/photo-1514041181368-bca62cceffcd?w=300&h=300&fit=crop">
		<img class="cube-face-image image-5" src="https://images.unsplash.com/photo-1488190211105-8b0e65b80b4e?w=300&h=300&fit=crop">
		<img class="cube-face-image image-6" src="https://images.unsplash.com/photo-1486334803289-1623f249dd1e?w=300&h=300&fit=crop">



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

<div class="image-buttons">

	<input type="image" class="show-image-1" src="https://images.unsplash.com/photo-1445810694374-0a94739e4a03?w=100&h=100&fit=crop"></input>

	<input type="image" class="show-image-2" src="https://images.unsplash.com/photo-1515260268569-9271009adfdb?w=100&h=100&fit=crop"></input>

	<input type="image" class="show-image-3" src="https://images.unsplash.com/photo-1506045412240-22980140a405?w=100&h=100&fit=crop"></input>

	<input type="image" class="show-image-4" src="https://images.unsplash.com/photo-1514041181368-bca62cceffcd?w=100&h=100&fit=crop"></input>

	<input type="image" class="show-image-5" src="https://images.unsplash.com/photo-1488190211105-8b0e65b80b4e?w=100&h=100&fit=crop"></input>

	<input type="image" class="show-image-6" src="https://images.unsplash.com/photo-1486334803289-1623f249dd1e?w=100&h=100&fit=crop"></input>


Full-page view:



@import url(https://fonts.googleapis.com/css?family=Montserrat:500);

: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);

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

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

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

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

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

.cube.show-image-6 {
	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 = e.target.nodeName,
			  targetClass = e.target.className;

		//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;	

🕑 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 ..................