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 class="hero">
	<svg class="hero__ratio" viewBox="0 0 16 9" aria-hidden="true"></svg>
	<img class="hero__bg"
		src="https://images.unsplash.com/photo-1629312257596-5cd5fc3e48ef?crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDk0MDQ2OA&ixlib=rb-1.2.1&q=85"
		alt=""
		elementtiming="hero-image">
	<div class="hero__content">
		<h1 class="hero__heading"
			elementtiming="hero-text">
			Element Timing Demo
		</h1>
		<div style="width: 100%; max-width: 18rem; margin: 0; padding: 1rem; border-radius: 1rem; background: white; text-align: left;">
			<h2>Hero Image</h2>
			<dl data-time="hero-image">
				<dt>loadTime:</dt><dd>…</dd>
				<dt>renderTime:</dt><dd>…</dd>
			</dl>
			<h2>Hero Text</h2>
			<dl data-time="hero-text">
				<dt>loadTime:</dt><dd>…</dd>
				<dt>renderTime:</dt><dd>…</dd>
			</dl>
		</div>
	</div>
</header>

<div class="container">
	<p>Fun Fact: On repeat views, the "Hero Image" entry never fires. 🤔</p>
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap');

body {
	margin: 0;
}

.hero {
	position: relative;
  display: grid;
	background: lightgray;
}

.hero > * {
  grid-area: 1 / 1 / 2 / 2;
}

.hero__ratio {
	max-height: 80vh;
}

.hero__bg {
	position: absolute;
	top: 0;
	left: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.hero__content {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	text-align: center;
}

.hero__heading {
	margin: 0 auto 1rem;
	font-family: 'Bebas Neue', sans-serif;
	font-size: min(10vw, 5rem);
	text-shadow: 0.1rem 0.1rem 0.2rem rgb(255, 255, 255);
}

dl[data-time] {
	display: grid;
	grid-gap: 0.5rem;
	grid-template-columns: min-content 1fr;
}

.container {
	max-width: 75ch;
	margin: 0 auto;
	padding: 1rem;
}

              
            
!

JS

              
                // https://developer.mozilla.org/en-US/docs/Web/API/Element_timing_API
const observer = new PerformanceObserver((list) => {
  let entries = list.getEntries().forEach(function (entry) {
		const dd = document.querySelector(`[data-time="${entry.identifier}"]`);
		if (dd) {
      dd.innerHTML = `
				<dt>loadTime:</dt><dd>${entry.loadTime}</dd>
				<dt>renderTime:</dt><dd>${entry.renderTime}</dd>
			`;
		}
		console.log(entry);
  });
});
observer.observe({ entryTypes: ['element'] });

              
            
!
999px

Console