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

              
                		<header>
			<h1>View Transitions Demo: Accordion</h1>
		</header>
		<main>
			<div class="accordion">
				<div class="item" id="item-1">
					<input type="radio" name="accordion" value="unblur" id="unblur" checked />
					<label for="unblur">
						<span class="title">Photo Unblur fixes your pics, even the old ones.</span>
						<span class="marker">&rsaquo;</span>
					</label>
					<div>
						<h2>Photo Unblur fixes your pics, even the old ones.</h2>
						<p>With a tap, sharpen and brighten picture-imperfect photos – even ones from non-Pixel phones. #FixedOnPixel</p>
					</div>
				</div>
				<div class="item" id="item-2">
					<input type="radio" name="accordion" value="magic-eraser" id="magic-eraser" />
					<label for="magic-eraser">
						<span class="title">Easily remove distractions in photos with Magic Eraser.</span>
						<span class="marker">&rsaquo;</span>
					</label>
					<div>
						<h2>Easily remove distractions in photos with Magic Eraser.</h2>
						<p>Make unwanted objects or photobombers disappear. Or change the color and brightness so an object blends right in. #FixedOnPixel</p>
					</div>
				</div>
				<div class="item" id="item-3">
					<input type="radio" name="accordion" value="night-sight" id="night-sight" />
					<label for="night-sight">
						<span class="title">Details pop out in the dark with Night Sight.</span>
						<span class="marker">&rsaquo;</span>
					</label>
					<div>
						<h2>Details pop out in the dark with Night Sight.</h2>
						<p>Now it’s easier to create rich, vibrant photos when it’s dark – city lights, portraits in low light, and starry skies with astrophotography.</p>
					</div>
				</div>
				<div class="item" id="item-4">
					<input type="radio" name="accordion" value="super-res-zoom" id="super-res-zoom" />
					<label for="super-res-zoom">
						<span class="title">Get amazing closeups with Super Res Zoom.</span>
						<span class="marker">&rsaquo;</span>
					</label>
					<div>
						<h2>Get amazing closeups with Super Res Zoom.</h2>
						<p>The Pixel 7a camera includes Super Res Zoom. So you can get up close without an extra telephoto lens.</p>
					</div>
				</div>
				<div class="item" id="item-5">
					<input type="radio" name="accordion" value="long-exposure" id="long-exposure" />
					<label for="long-exposure">
						<span class="title">Create energetic photos with Long Exposure.</span>
						<span class="marker">&rsaquo;</span>
					</label>
					<div>
						<h2>Create energetic photos with Long Exposure.</h2>
						<p>Add motion, texture, and artful blurs – including light trails – to waterfalls, crowds, city streets, and more. All without a tripod.</p>
					</div>
				</div>
			</div>
		</main>
		<footer>
			<p>Example URL: <a href="https://store.google.com/us/product/pixel_7a?hl=en-US">Pixel 7a – Google Store</a></p>
		</footer>
              
            
!

CSS

              
                @layer reset, layout, transitions;

@layer transitions {
	:root {
		view-transition-name: none;
	}

	#item-1 {
		view-transition-name: item-1;
		.marker {
			view-transition-name: marker-1;
		}
		&:has(input:checked) {
			& h2 {
				view-transition-name: title-1;
			}
		}
		&:not(.item:has(input:checked)) {
			& .title {
				view-transition-name: title-1;
			}
		}
	}

	#item-2 {
		view-transition-name: item-2;
		.marker {
			view-transition-name: marker-2;
		}
		&:has(input:checked) {
			& h2 {
				view-transition-name: title-2;
			}
		}
		&:not(.item:has(input:checked)) {
			& .title {
				view-transition-name: title-2;
			}
		}
	}

	#item-3 {
		view-transition-name: item-3;
		.marker {
			view-transition-name: marker-3;
		}
		&:has(input:checked) {
			& h2 {
				view-transition-name: title-3;
			}
		}
		&:not(.item:has(input:checked)) {
			& .title {
				view-transition-name: title-3;
			}
		}
	}

	#item-4 {
		view-transition-name: item-4;
		.marker {
			view-transition-name: marker-4;
		}
		&:has(input:checked) {
			& h2 {
				view-transition-name: title-4;
			}
		}
		&:not(.item:has(input:checked)) {
			& .title {
				view-transition-name: title-4;
			}
		}
	}

	#item-5 {
		view-transition-name: item-5;
		.marker {
			view-transition-name: marker-5;
		}
		&:has(input:checked) {
			& h2 {
				view-transition-name: title-5;
			}
		}
		&:not(.item:has(input:checked)) {
			& .title {
				view-transition-name: title-5;
			}
		}
	}

	@keyframes rotate-marker {
		from {
			rotate: 90deg;
		}
		to {
			rotate: 270deg;
			opacity: 0;
		}
	}
	::view-transition-group(*) {
		animation-duration: 0.5s;
	}
	::view-transition-group(item-1),
	::view-transition-group(item-2),
	::view-transition-group(item-3),
	::view-transition-group(item-4),
	::view-transition-group(item-5) {
		overflow: hidden;
	}

	::view-transition-old(marker-1):only-child,
	::view-transition-old(marker-2):only-child,
	::view-transition-old(marker-3):only-child,
	::view-transition-old(marker-4):only-child,
	::view-transition-old(marker-5):only-child {
		animation-name: rotate-marker;
	}
	::view-transition-new(marker-1):only-child,
	::view-transition-new(marker-2):only-child,
	::view-transition-new(marker-3):only-child,
	::view-transition-new(marker-4):only-child,
	::view-transition-new(marker-5):only-child {
		animation-name: rotate-marker;
		animation-direction: reverse;
	}
}

@layer layout {
	@layer general {
		body {
			background: #efeae6;
			font-family: 'Google Sans', Roboto, Arial, sans-serif;
			padding-top: 3rem;
		}
		header,
		footer {
			text-align: center;
		}
		main {
			margin: 2em auto;
			width: 90%;
			max-width: 30em;
		}
	}
	@layer accordion {
		.accordion {
			display: grid;
			grid-auto-flow: row;
			gap: 0.5em;
			border-radius: 1em;
			overflow: hidden;
			font-size: 1.25em;
		}

		.item {
			background: #f8f6f2;

			display: flex;
			flex-direction: column;

			& input {
				position: absolute;
				opacity: 0;
			}

			& label {
				flex: 1;
				cursor: pointer;
				padding: 1em;

				display: flex;
				flex-direction: row;
				gap: 1em;
				justify-content: space-between;
			}

			.marker {
				display: grid;
				place-content: center;
				height: 1.5rem;
				aspect-ratio: 1;
				border-radius: 50%;
				background-color: #fff;
				color: #5f6368;

				font-weight: 700;
				font-size: 1.5em;
				line-height: 1;
				rotate: 90deg;
			}

			& div {
				padding: 1em;

				:first-child {
					margin-top: 0;
				}
				:last-child {
					margin-bottom: 0;
				}
			}
		}

		/* Show/Hide label/content based on input being checked or not */
		.item:has(input:checked) {
			& label {
				display: none;
			}
		}
		.item:not(.item:has(input:checked)) {
			& div {
				display: none;
			}
		}
	}
}

@layer reset {
	html,
	body {
		height: 100%;
		margin: 0;
		padding: 0;
	}
}
              
            
!

JS

              
                document.querySelectorAll('.item input').forEach(($input) => {
	// @note: we listen on click because that happens *before* a change event
	$input.addEventListener('click', async (e) => {
		if (!document.startViewTransition) return;

		e.preventDefault();

		const t = document.startViewTransition(() => {
			e.target.checked = true;
		});

		await t.finished;
		console.log('done');
	});
});
              
            
!
999px

Console