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 class="container">
	<h1>🐛 Firefox Bug: CSS Scroll Snap "Jump"</h1>
	<p>In Firefox 77, trying to smooth scroll an element with <code>.scroll({ behavior: 'smooth' })</code> that also has CSS Scroll Snap applied to it can cause an unwanted "jump" and fail to scroll to the correct destination.</p>
	<p>For example, in the demo below you should be able to click on the edges of the slides peeking in from the side of the page.</p>
	<p>In all other major browsers, this works as expected (even in Safari, which requires a polyfill for smooth scrolling but supports CSS Scroll Snap natively).</p>

	<h2>Demo</h2>
</div>

<ul class="demo demo--center">
	<li class="demo__slide" tabindex="-1">Slide 1</li>
	<li class="demo__slide" tabindex="-1">Slide 2</li>
	<li class="demo__slide" tabindex="-1">Slide 3</li>
</ul>

<div class="container">
	<h2>Browser Support <small>(as of 2020-06-03)</small></h2>
	<small class="note">All links open in new tabs.</small>
	<table class="support-table">
		<thead>
			<tr>
				<th>🖥 Browser</th>
				<th>📋 Behavior</th>
				<th>🎬 Screencast</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>Chrome 83+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Chrome+83.mp4" target="_blank" rel="noopener" title="Watch screencast of Chrome 83">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Chrome for Android 8+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Chrome+for+Android+8.mp4" target="_blank" rel="noopener" title="Watch screencast of Chrome for Android 8">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Edge 83+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Edge+83.mp4" target="_blank" rel="noopener" title="Watch screencast of Edge 83">Watch screencast</a></td>
			</tr>
			<tr class="error">
				<td>Firefox 77 </td>
				<td>❌</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Firefox+77.mp4" target="_blank" rel="noopener" title="Watch screencast of Firefox 77">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Firefox for Android 8+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Firefox+for+Android+8.mp4" target="_blank" rel="noopener" title="Watch screencast of Firefox for Android 8">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Opera 68+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Opera+68.mp4" target="_blank" rel="noopener" title="Watch screencast of Opera 68">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Safari 13+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Safari+13.mp4" target="_blank" rel="noopener" title="Watch screencast of Safari 13">Watch screencast</a></td>
			</tr>
			<tr>
				<td>Safari for iOS 13+</td>
				<td>✅</td>
				<td><a href="https://assets.codepen.io/146527/2020-06-03+CSS+Scroll+Snap+Bug+-+Safari+for+iOS+13.mp4" target="_blank" rel="noopener" title="Watch screencast of Safari for iOS 13">Watch screencast</a></td>
			</tr>
		</tbody>
	</table>

	<h2>References</h2>
	<ul>
		<li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1643217" target="_blank" rel="noopener">Bugzilla: CSS Scroll Snap conflicts with JS scroll behavior smooth</a></li>
		<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap" target="_blank" rel="noopener">MDN: CSS Scroll Snap</a></li>
		<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll" target="_blank" rel="noopener">MDN: Element.scroll()</a></li>
	</ul>
</div>

              
            
!

CSS

              
                /* ------------------------------ */
/* Base                           */
/* ------------------------------ */

html {
	line-height: 1.5;
	tab-size: 4;
	box-sizing: border-box;
}

*,
::after,
::before {
	box-sizing: inherit;
}

body {
	margin: 0;
	padding-bottom: 10rem;
}

.container {
	max-width: 40rem;
	margin: auto;
	padding-right: 1rem;
	padding-left: 1rem;
}



/* ------------------------------ */
/* Demo                           */
/* ------------------------------ */

.demo {
	--peek: 5rem;
	--gutter: 1.5rem;
	display: block;
	position: relative;
	margin: 0 auto;
	padding: 0;
	overflow: scroll;
	font-size: 0;
	list-style: none;
	white-space: nowrap;
	scroll-snap-type: x mandatory; /* ⚠️ */
}

.demo__slide {
	display: inline-block;
	width: calc(100% - var(--peek) * 2);
	height: 10rem;
	margin: 0 calc(var(--gutter) / 2);
	padding: 1rem;
	border: 2px solid black;
	font-size: 1rem;
	white-space: normal;
	scroll-snap-align: center; /* ⚠️ */
}

.demo__slide:first-child {
	margin-left: var(--peek);
}

.demo__slide:last-child {
	margin-right: var(--peek);
}

.demo__slide:nth-child(even) {
	background: #fff;
}

.demo__slide:nth-child(odd) {
	background: #eee;
}



/* ------------------------------ */
/* Browser Support                */
/* ------------------------------ */

.support-table {
	border-collapse: collapse;
	border: 1px solid #ccc;
	text-align: left;
}

.support-table thead {
	background: #eee;
}

.support-table th,
.support-table td {
	padding: 0.5rem 1rem;
	border-bottom: 1px solid #ccc;
}

.support-table .error {
	background: #fee;
}

.note {
	display: block;
	margin-bottom: 0.5rem;
	font-style: italic;
}

              
            
!

JS

              
                // Includes smooth scroll polyfill for Safari
// https://github.com/iamdustan/smoothscroll#readme

const slider = document.querySelector('.demo');

// When someone focuses on a slide, smooth scroll to it.
slider.addEventListener('focusin', function (event) {
	const slide = event.target.closest('.demo__slide');

	if (!slide) {
		return;
	}

	// Calculate the center position for the slide relative to its container.
	const top = slide.offsetTop + slide.offsetHeight / 2 - slider.offsetHeight / 2;
	const left = slide.offsetLeft + slide.offsetWidth / 2 - slider.offsetWidth / 2;

	// Smooth scroll to the slide's center position.
	slider.scroll({ top, left, behavior: 'smooth' });
});

              
            
!
999px

Console