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

              
                <div id="container">
	
	<!-- Grid Tile: Vibrant Super Retina XDR Display -->
  <div class="display">
		<img class="blue-slide slide" style="left: 0; opacity: 1;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668886961/codepens/display_blue_vhiobo.jpg" />
		<img class="purple-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668966381/codepens/display_purple_e05dzw.jpg" />
		<img class="midnight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668966409/codepens/display_midnight_hovnnf.jpg" />
		<img class="starlight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668966430/codepens/display_starlight_xzxxtu.jpg" />
		<img class="red-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668966454/codepens/display_red_xqwm4l.jpg" />
		<p class="small" align="center">Vibrant Super</br>Retina XDR display</p>
  </div>

	<!-- Grid Tile: Beautifully durable -->
  <div class="durability">
		<!-- This tile's slides include text content because it all animates -->
		<div class="blue-slide slide" style="left: 0; opacity: 1;">
			<img src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668889161/codepens/durable_blue_hy3pcn.jpg" />
			<div class="txt-group">
				<p class="large">Beautifully durable</p>
				<p class="small">aerospace-grade aluminum</p>
			</div>
		</div>
		<div class="purple-slide slide" style="left: 100%; opacity: 0;">
			<img src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669235665/codepens/durable_purple_ij65ye.jpg" />
			<div class="txt-group">
				<p class="large">Beautifully durable</p>
				<p class="small">aerospace-grade aluminum</p>
			</div>
		</div>
		<div class="midnight-slide slide" style="left: 100%; opacity: 0;">
			<img src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669235665/codepens/durable_midnight_v5uzd9.jpg" />
			<div class="txt-group">
				<p class="large">Beautifully durable</p>
				<p class="small">aerospace-grade aluminum</p>
			</div>
		</div>
		<div class="starlight-slide slide" style="left: 100%; opacity: 0;">
			<img src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669235665/codepens/durable_starlight_m8q9bi.jpg" />
			<div class="txt-group">
				<p class="large">Beautifully durable</p>
				<p class="small">aerospace-grade aluminum</p>
			</div>
		</div>
		<div class="red-slide slide" style="left: 100%; opacity: 0;">
			<img src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669235665/codepens/durable_red_yz76ei.jpg" />
			<div class="txt-group">
				<p class="large">Beautifully durable</p>
				<p class="small">aerospace-grade aluminum</p>
			</div>
		</div>
  </div>

	<!-- Grid Tile: Upper Right -->
  <div class="lockScreen">
  	<img class="blue-slide slide" style="left: 0; opacity: 1;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668889971/codepens/lockscreen_blue_kvcokh.jpg" />
		<img class="purple-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668974864/codepens/lockscreen_purple_qymskd.jpg" />
		<img class="midnight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668974864/codepens/lockscreen_midnight_qpbexo.jpg" />
		<img class="starlight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668974864/codepens/lockscreen_starlight_edvfn8.jpg" />
		<img class="red-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668974864/codepens/lockscreen_red_lfxayk.jpg" />
  </div>

	<!-- Grid Tile: Center with color controller -->
  <div class="colorPicker">
		<div>
			<p class="small perspective-slide">Five fantastic colors</p>
			<p class="xl slide blue-slide perspective-slide">Blue</p>
			<p class="xl slide purple-slide perspective-slide" style="opacity: 0;">Purple</p>
			<p class="xl slide midnight-slide perspective-slide" style="opacity: 0;">Midnight</p>
			<p class="xl slide starlight-slide perspective-slide" style="opacity: 0;">Starlight</p>
			<p class="xl slide red-slide perspective-slide" style="opacity: 0;">Red</p>
		</div>
		<fieldset id="controller" role="tablist" tabindex="0">
			<button id="blueBtn" data-color="blue" class="active" type="button" role="tab" tabindex="0"><span></span></button>
			<button id="purpleBtn" data-color="purple" type="button" role="tab"><span></span></button>
			<button id="midnightBtn" data-color="midnight" type="button" role="tab" ><span></span></button>
			<button id="starlightBtn" data-color="starlight" type="button" role="tab"><span></span></button>
			<button id="redBtn" data-color="red" type="button" role="tab"><span></span></button>
		</fieldset>
  </div>

	<!-- Grid Tile: Center Left -->
  <div class="camera">
  	<img class="blue-slide slide" style="left: 0; opacity: 1;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668890102/codepens/camera_blue_xqrris.jpg" />
		<img class="purple-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668975350/codepens/camera_purple_aadquj.jpg" />
		<img class="midnight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668975350/codepens/camera_midnight_lgolgu.jpg" />
		<img class="starlight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668975350/codepens/camera_starlight_elbxob.jpg" />
		<img class="red-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668975466/codepens/camera_red_fa5zii.jpg" />
  </div>

	<!-- Grid Tile:Sails through spills -->
	<div class="waterResistance">
		<img class="blue-slide slide" style="left: 0; opacity: 1;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668890701/codepens/waterResistance_blue_o0wz3l.jpg" />
		<img class="purple-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232752/codepens/waterResistance_purple_mx0eqp.jpg" />
		<img class="midnight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232752/codepens/waterResistance_midnight_hn2cjq.jpg" />
		<img class="starlight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232752/codepens/waterResistance_starlight_dabsxk.jpg" />
		<img class="red-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232752/codepens/waterResistance_red_2_atkxgm.jpg" />
		<p class="small">with water resistance</p>
	</div>

	<!-- Grid Tile: Ceramic Shield -->
	<div class="glass">
		<div>
			<p class="large">Ceramic Shield</p>
			<p class="small">is tougher than any amartphone glass</p>
		</div>
		<img class="blue-slide slide" style="left: 0; opacity: 1;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1668890785/codepens/glass_blue_yhsdb6.jpg" />
		<img class="purple-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232689/codepens/glass_purple_dueykc.jpg" />
		<img class="midnight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232689/codepens/glass_midnight_psxtio.jpg" />
		<img class="starlight-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232689/codepens/glass_starlight_zlxyjd.jpg" />
		<img class="red-slide slide" style="left: 100%; opacity: 0;" src="https://res.cloudinary.com/dcelvzyfc/image/upload/v1669232689/codepens/glass_red_xlnoxh.jpg" />
	</div>

</div>
              
            
!

CSS

              
                /* Global Setup */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');

:root {
	--gray1: #f5f5f7;
	--gray2: #6e6e73;
	--gray3: #1d1d1f;
}

*, html, body {
	font-family: 'Inter', sans-serif;
	box-sizing: border-box;
	margin: 0;
}

body {
	min-width: 100%;
	display: flex;
	justify-content: center;
	padding: 60px 0;
}

#container {
	width: 980px;
	display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 336px);
  gap: 15px;
  grid-auto-flow: row;
  grid-template-areas:
    "display durability lockScreen"
    "display colorPicker camera"
    "waterResistance glass glass";
}

/* Shared Styles */

#container > div {
	min-height: 336px;
	position: relative;
	background: var(--gray1);
	border-radius: 18px;
	overflow: hidden;
}

p.xl {
	font-size: 56px;
	line-height: 1.0714285714;
	font-weight: 600;
  letter-spacing: -0.005em;
}

p.large {
	font-size: 40px;
	line-height: 1.1;
	font-weight: 600;
	letter-spacing: -0.022em;
	color: var(--gray3);
}

p.small {
	font-size: 21px;
	line-height: 1.1904761905;
	font-weight: 600;
	letter-spacing: .011em;
	color: var(--gray2);
}

.slide {
	position: absolute;
	left: 0;
	right: 0;
	margin: 0 auto;
	transition: left 1s cubic-bezier(0.8,0,0.2,1), opacity 1.3s ease;
}

/* Display Card */

.display {
	grid-area: display;
	display: flex;
	flex-direction: column;
	justify-content: end;
	align-items: center;
	padding: 20px 17px;
}

.display img {
	top: 20px;
	width: 282px;
	height: 570px;
	margin-bottom: 20px;
	flex-grow: 1;
}

/* Durability Card */

.durability {
	grid-area: durability;
	position: relative;
	display: flex;
	align-items: end;
	padding: 20px 0px 0px 20px;
}

.durability > div {
	display: flex;
	align-items: center;
	justify-content: center;
	max-width: 100%;
}

.durability img {
	height: 312px;
	margin-right: 25px;
	margin-left: 20px;
}

.durability .txt-group {
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.durability .txt-group p:first-of-type {
	margin-bottom: 10px;
}

/* Lock Screen Card */

.lockScreen {
	grid-area: lockScreen;
	display: flex;
	justify-content: center;
	align-items: end;
}

.lockScreen img {
	width: 245px;
	height: 312px; 
}

/* Color Picker Card */

.colorPicker {
	grid-area: colorPicker;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	align-items: center;
	padding: 67px 45px 36px 45px;
}

.perspective-slide {
	transform: rotateY(0deg);
	transform-origin: center center;
  transform-style: preserve-3d;
	animation-name: none;
	transform: perspective(var(350px)) translateZ(0px) rotateY(0deg) scale(1);
	transition: opacity 400ms ease 200ms;
}

.perspective-slide.rotate,
.perspective-slide.rotate-reverse {
	animation-duration: 1.5s;
	animation-timing-function: cubic-bezier(0,0,0.33,0.93);
}

.perspective-slide.rotate {animation-name: rotate;}
.perspective-slide.rotate-reverse {animation-name: rotateReverse;}

@keyframes rotate {
	0% {transform: perspective(350px) translateZ(0px) rotateY(0deg) scale(1)}
	20% {transform: perspective(350px) translateZ(-327px) rotateY(25deg) scale(2)}
	100% {transform: perspective(350px) translateZ(0px) rotateY(0deg) scale(1)}
}

@keyframes rotateReverse {
	0% {transform: perspective(350px) translateZ(0px) rotateY(0deg) scale(1)}
	20% {transform: perspective(350px) translateZ(-327px) rotateY(-25deg) scale(2)}
	100% {transform: perspective(350px) translateZ(0px) rotateY(0deg) scale(1)}
}

.colorPicker .slide {
	display: inline-block;
	width: max-content;
	top: 135px;
	left: 0px !important;
}

#controller {
	display: flex;
	border: none;
}

#controller button {
	position: relative;
	height: 42px;
	width: 42px;
	margin: 0px 4px;
	display: flex;
	justify-content: center;
	align-items: center;
	background: transparent;
	border: 3px solid transparent;
	border-radius: 50%;
	cursor: pointer;
}

#controller button.active {
	border-color: var(--gray3);
  background-color: #fff;
}

#controller button span {
	flex-shrink: 0;
	display: block;
	height: 32px;
	width: 32px;
	border-radius: 50%;
	box-shadow: inset 0 1px 1px rgb(0 0 0 / 10%);
}

#blueBtn span {background: #c0cfde;}
#purpleBtn span {background: #e7d7e9;}
#midnightBtn span {background: #31353a;}
#starlightBtn span {background: #f0ece8;}
#redBtn span {background: #e11c2a}

/* Camera Card */

.camera {
	grid-area: camera;
	display: flex;
	align-items: end;
}

.camera img {
	width: 544px;
	height: 305px;
	padding-left: 25px;
}

/* Water Resistance Card */

.waterResistance {
	grid-area: waterResistance;
	display: flex;
	position: relative;
	flex-direction: column;
	justify-content: end;
	align-items: center;
	padding: 30px 20px
}

.waterResistance .slide {
	top: 60px;
	left: 0px !important;
}

/* Glass Card */

.glass {
	grid-area: glass;
	display: flex;
	flex-direction: column;
	justify-content: start;
	align-items: center;
	padding: 25px 60px;
}

.glass div {
	display: flex;
	align-items: end;
	margin-bottom: 20px;
}

.glass div p.large {
	white-space: nowrap;
	margin-right: 16px;
}

.glass img {
	width: 531px;
	height: 232px;
}

.glass .slide {
	bottom: 0;
}

              
            
!

JS

              
                const container = document.getElementById('container')
const buttons = document.querySelectorAll('#controller button')
const perspectiveSlides = document.querySelectorAll('.perspective-slide')
let currentColor = 'blue'

// For each color picker button, on click, do the following
buttons.forEach(button => {
	button.addEventListener("click", function() {
		
		// On click, remove the "active" class (black ring) from color circle button
		buttons.forEach(button => {
			button.classList.remove('active');
		})
		// On click, add the "active" class (black ring) to the clicked color circle button
		button.classList.add('active');
		
		// On click, get the newly clicked color circle button's color
		let newColor = button.getAttribute('data-color')
		
		// On click, remove the "rotate" and "rotate-reverse" classes (perspective animations) from the center tile text
		perspectiveSlides.forEach(el=>el.classList.remove('rotate', 'rotate-reverse'))
		perspectiveSlides.forEach(el=>el.offsetHeight) // This call to "offsetHeight" forces the browser to repaint the styles
		
		// Reusable function for adding classes "rotate" or "rotate-reverse" depending on color selected (depends on if it was selected to left or right of the currently selected color)
		function rotateColor(nextColors) {
			if (nextColors.includes(currentColor)) {
				perspectiveSlides.forEach(el=>el.classList.add('rotate'));
			} else {
				perspectiveSlides.forEach(el=>el.classList.add('rotate-reverse'));
			}
			currentColor = newColor
		}
		
		// If the color picked is X style the tile "slide" content to the left, bring opacity from 0 to 1, and do the opposite for the others. Trigger reusable function that adds "rotate" or "rotate-reverse" classes to the center tile text.
		if (newColor == "blue") {
			document.querySelectorAll('.blue-slide').forEach(el=>{el.style.left = '0'; el.style.opacity = "1"});
			document.querySelectorAll('.purple-slide, .midnight-slide, .starlight-slide, .red-slide').forEach(el=>{el.style.left = '150%'; el.style.opacity = "0"});
			rotateColor(["purple", "midnight", "starlight", "red"])
			
		} else if (newColor == "purple") {
			document.querySelectorAll('.purple-slide').forEach(el=>{el.style.left = '0'; el.style.opacity = "1"});
			document.querySelectorAll('.blue-slide').forEach(el=>{el.style.left = '-150%'; el.style.opacity = "0"});
			document.querySelectorAll('.midnight-slide, .starlight-slide, .red-slide').forEach(el=>{el.style.left = '150%'; el.style.opacity = "0"});
			rotateColor(["midnight", "starlight", "red"])
			
		} else if (newColor == "midnight") {
			document.querySelectorAll('.midnight-slide').forEach(el=>{el.style.left = '0'; el.style.opacity = "1"});
			document.querySelectorAll('.blue-slide, .purple-slide').forEach(el=>{el.style.left = '-150%'; el.style.opacity = "0"});
			document.querySelectorAll('.starlight-slide, .red-slide').forEach(el=>{el.style.left = '150%'; el.style.opacity = "0"});
			rotateColor(["starlight", "red"])
			
		} else if (newColor == "starlight") {
			document.querySelectorAll('.starlight-slide').forEach(el=>{el.style.left = '0'; el.style.opacity = "1"});
			document.querySelectorAll('.blue-slide, .purple-slide, .midnight-slide').forEach(el=>{el.style.left = '-150%'; el.style.opacity = "0"});
			document.querySelectorAll('.red-slide').forEach(el=>{el.style.left = '150%'; el.style.opacity = "0"});
			rotateColor(["red"])
			
		} else if (newColor == "red") {
			document.querySelectorAll('.red-slide').forEach(el=>{el.style.left = '0'; el.style.opacity = "1"});
			document.querySelectorAll('.blue-slide, .purple-slide, .midnight-slide, .starlight-slide').forEach(el=>{el.style.left = '-150%'; el.style.opacity = "0"});
			rotateColor([])
		}
	});
});
              
            
!
999px

Console