HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
: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;
}
}
$(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>'
});
});
Also see: Tab Triggers