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

Save Automatically?

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

              
                <main>
  <div class="hero-slider">
    <div>
      <div class="overlay" style="top: 130px; left: 20px">
        <h2>Coco Oil body oil</h2>
        <p>Bacon ipsum dolor amet porchetta sausage tenderloin cupim, meatloaf beef ribs flank swine prosciutto frankfurter. </p>
        <a href="https://github.com/Accessible360/accessible-slick" target="_blank" class="btn">Learn more</a>
      </div>

      <img src="https://assets.codepen.io/3609497/deanna-alys-6LBBOwkPzyQ-unsplash.jpg" alt="" class="background-image">
    </div>

    <div>
      <div class="overlay" style="top: 50px; left: 20px">
        <h2>Fancy generic wristwatch</h2>
        <p>Sausage shank shoulder ball tip doner. Ground round meatball tongue corned beef doner cow frankfurter.</p>
        <a href="https://github.com/Accessible360/accessible-slick" target="_blank" class="btn">Learn more</a>
      </div>

      <img src="https://assets.codepen.io/3609497/rachit-tank-2cFZ_FB08UM-unsplash.jpg" alt="" class="background-image">
    </div>

    <div>
      <div class="overlay" style="text-align: right; bottom: 15px; right: 20px">
        <h2>Curology lotion</h2>
        <p>Beef ribs drumstick leberkas ball tip picanha, bresaola ground round. Ham hock beef ham filet mignon.</p>
        <a href="https://github.com/Accessible360/accessible-slick" target="_blank" class="btn">Learn more</a>
      </div>

      <img src="https://assets.codepen.io/3609497/curology-wK0h-mlvfuc-unsplash.jpg" alt="" class="background-image">
    </div>
  </div>

  <div class="content">
    <h1>Hero banner carousel with custom controls using accessible-slick</h1>

    <p>Who doesn't love hero banner carousels? Ok, <a href="http://shouldiuseacarousel.com">lots of people</a>. But still, if you have to build one, here's an example of how you can do it in an accessible way using <a href="https://github.com/Accessible360/accessible-slick">accessible-slick</a>!</p>

    <p>This demo shows a few of the accessibility features of accessible-slick, along with some relevant tips that you can use for any carousel. In particular:</p>

    <ol>
      <li>Autoplay is enabled, which now automatically comes with a customizable pause/play button to comply with <a href="https://www.w3.org/WAI/WCAG21/Understanding/pause-stop-hide.html">WCAG 2.2.2</a>.</li>
      <li>The default pause/play icons are replaced with icons from <a href="https://icons8.com/line-awesome">LineAwesome</a> using the new <code>pauseIcon</code> and <code>playIcon</code> settings to give a modern look-and-feel.
      <li>Custom previous and next buttons are also provided (using the existing <code>prevArrow</code> and <code>nextArrow</code> settings) to better match the modern look-and-feel of the imagery.</li>
      <li>The previous and next buttons are placed before the slide content (but after the autoplay toggle button) using the new <code>arrowsPlacement</code> setting in order to maintain a logical tab sequence and meet <a href="https://www.w3.org/WAI/WCAG21/Understanding/focus-order.html">WCAG 2.4.3</a> and <a href="https://www.w3.org/WAI/WCAG21/Understanding/meaningful-sequence.html">1.3.2</a>.
      <li>Text is overlaid on each slide, but is carefully positioned to "safe" areas to ensure good color contrast. Be careful with your background images and text choices - these are common sources of <a href="https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html">WCAG 1.4.3</a> violations!</li>
    </ol>

    <p><a href="https://github.com/Accessible360/accessible-slick" class="btn">Learn more about <u>accessible-slick</u>!</a></p>
  </div>
</main>
              
            
!

CSS

              
                :root {
  --primary-color: black;
  --secondary-color: white;
}

body {
  background-color: rgba(0,0,0,.2);
  padding: 20px;
  padding-bottom: 60px;
}

.hero-slider {
  margin: 0 !important;
  padding: 2px;
  
  /** Autoplay toggle button in the top left corner */
  .slick-autoplay-toggle-button {
    position: absolute;
    top: 10px;
    left: 10px;
    bottom: auto;
    background: none;
    border: 0;
    z-index: 10;
    font-size: 32px;
    opacity: 1;
    cursor: pointer;
    color: black;
    
    &:hover {
      background-color: rgba(0,0,0,.05);
    }

    &:focus {
      background-color: rgba(0,0,0,.7);
      color: white;
    }
  }
  
  /** Custom previous and next arrows in the top right corner */
  .custom-prev-button,
  .custom-next-button {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1;

    display: block;
    float: left;
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    font-size: 32px;
    cursor: pointer;
    
    &:hover {
      background-color: rgba(0,0,0,.05);
    }

    &:focus {
      background-color: rgba(0,0,0,.7);
      color: white;
    }
  }

    .custom-prev-button {
      right: 30px;
    }
  
  /** Default slide navigation dots */
  .slick-dots {
    bottom: 20px;
  }
  
  /** Slide content */
  .slick-slide {
    position: relative;
    height: 400px;
    display: flex;
    align-items: center;
    
    /** Float text overlay */
    .overlay {
      position: absolute;
      width: 30%;
      padding: 20px;
      
      @media screen and (max-width: 768px) {
        width: 80%;
        left: 0 !important;
        top: 100px !important;
        text-align: left;
      }
      
      h2 {
        padding: 0;
        margin: 0;
        font-size: 28px;
      }
      
      p {
        font-size: 14px;
      }
      
      .primary-link {
        display: inline-block;
        color: black;
        text-decoration: none;
        margin-top: 20px;
        padding: 10px 15px;
        border: 2px solid black;
        font-weight: bold;
        transition: outline .1s linear;
        
        &:hover,
        &:focus {
          text-decoration: underline;
          background-color: black;
          color: white;
        }
        
        &:focus {
          outline: 4px dashed black;
          outline-offset: 3px;
        }
      }
    }
    
    .background-image {
      width: 100%;
      height: auto;
      background-size: cover;
      
      @media screen and (max-width: 768px) {
        width: auto;
        height: 400px;
        margin: 0 auto;
      }
    }
  }
}

main {
  background-color: white;
  max-width: 960px;
  margin: 0 auto;
  padding-bottom: 30px;
  position: relative;
  
  /** Documentation under carousel */
  .content {
    padding: 20px 15%;
    color: rgba(0,0,0,.9);
    line-height: 26px;
    
    h1 {
      line-height: 36px;
    }
    
    a {
      color: black;
      font-weight: bold;
      
      &:hover,
      &:focus {
        color: royalblue;
      }
    }
    
    li {
      margin-bottom: 15px;
      padding-left: 5px;
    }
    
    code {
      background-color: rgba(0,0,0,.05);
      color: red;
      padding: 2px 8px;
    }
    
    .btn {
      margin-top: 30px;
      font-size: 18px;
      padding: 10px 20px;
    }
  }
}

/** Generic ghost button styles */
.btn {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 15px;
  font-weight: bold;
  font-size: 14px;
  color: black;
  border: 2px solid black;
  box-shadow: 3px 3px 0 0 black;
  text-decoration: none;
  transition: all .1s linear;
  
  &:hover,
  &:focus {
    background-color: black;
    color: white !important;
    text-decoration: underline;
    box-shadow: none;
  }
  
  &:focus {
    box-shadow: none;
    outline: 4px dashed black;
    outline-offset: 2px;
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  $('.hero-slider').slick({
    autoplay: true,
    autoplaySpeed: 5000,
    dots: true,
    arrows: true,
    arrowsPlacement: 'beforeSlides',
    prevArrow: '<button type="button" class="custom-prev-button">'
               + '  <span class="las la-angle-left" aria-hidden="true"></span>'
               + '  <span class="sr-only">Previous slide</span>'
               + '</button>',
    nextArrow: '<button type="button" class="custom-next-button">'
               + '  <span class="las la-angle-right" aria-hidden="true"></span>'
               + '  <span class="sr-only">Next slide</span>'
               + '</button>',
    pauseIcon: '<span class="la la-pause" aria-hidden="true"></span>',
    playIcon: '<span class="la la-play" aria-hidden="true"></span>'
  });
});
              
            
!
999px

Console