Pen Settings



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


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


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.


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.


                <div class="wrapper">
  <div class="carousel-container">
    <div class="carousel">
      <div id="skyline" class="carousel__item">
        <img src="" alt="Skyline of Wai Tan, Shanghai" class="carousel__image">
      <div id="great-wall-of-china" class="carousel__item">
        <img src="" alt="Great wall of China." class="carousel__image">
      <div id="sunset-on-the-li-river" class="carousel__item">
        <img src="" alt="Sunset on the Li River as the few remaining cormorant fisherman pack their." class="carousel__image">
    <div id="controls" class="controls">
      <a href="#skyline" class="controls__dot">
        <span class="visuallyhidden">Skyline of Wai Tan, Shanghai</span>
      <a href="#great-wall-of-china" class="controls__dot">
        <span class="visuallyhidden">Great wall of China</span>
      <a href="#sunset-on-the-li-river" class="controls__dot">
        <span class="visuallyhidden">Sunset on the Li River</span>
  <div class="intro">
    <h1>Carousel with CSS Scroll Snap</h1>
    <p>Recently, when I was reminded of the existence of the CSS property `scroll-snap`, I thought it should be easy to create a simple carousel component with it. After outlining a quick proof of concept in a simple HTML file, my assumption was confirmed.</p>


                .carousel-container {
  position: relative;

.carousel {
  display: flex;
  scroll-snap-type: x mandatory;
  overflow-x: scroll;
  scroll-behavior: smooth;

.carousel__item {
  width: 100%;
  flex-shrink: 0;
  scroll-snap-align: start;

.carousel__image {
  display: block;

.controls {
  position: absolute;
  right: 0;
  bottom: 1em;
  left: 0;
  text-align: center;

.controls__dot {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 50%;
  outline: none;
  background-color: #fff;
  opacity: 0.8;
  cursor: pointer;
  transition: opacity 0.2s;
  &:not(:first-child) {
    margin-left: 0.25em;

  &:focus {
    opacity: 1;

// Other styles
p {
  line-height: 1.5;

.wrapper {
  margin-right: auto;
  margin-left: auto;
  max-width: 60em;
  min-height: 100vh;
  box-shadow: 0 0 1em 1em rgba(0, 0, 0, 0.1);
  padding-bottom: 6em;

.visuallyhidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;

.intro {
  margin-top: 3.5em;
  max-width: 42em;
  margin-right: auto;
  margin-left: auto;
  text-align: center;