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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<!-- Slider 1 -->
<div class="slider" id="slider1">
<!-- Slides -->
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_110627-8240-Myst.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/Gif-pont-lueur-600.gif)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_Sharpened-version.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/jungle.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_bodie-11.jpg)"></div>
<!-- The Arrows -->
<i class="left" class="arrows" style="z-index:2; position:absolute;"><svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z"></path>
</svg></i>
<i class="right" class="arrows" style="z-index:2; position:absolute;"><svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z" transform="translate(100, 100) rotate(180) "></path>
</svg></i>
<!-- Title Bar -->
<span class="titleBar">
<h1>This Slider has all default settings.</h1>
</span>
</div>
<br>
<div class="row2Wrap">
<!-- Slider 2 -->
<div class="slider" id="slider2">
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/blurredBeachGrassCloseup.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_110627-8240-Myst.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_bodie-11.jpg)"></div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/jungle.jpg)"></div>
<i class="left" class="arrows" style="z-index:2; position:absolute;">
<svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z"></path>
</svg>
</i>
<i class="right" class="arrows" style="z-index:2; position:absolute;">
<svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z" transform="translate(100, 100) rotate(180) "></path>
</svg>
</i>
<!-- Title Bar -->
<!--
<span class="titleBar">
<h1>I am like a leaf in the wind.</h1>
<p>Watch me soar!</p>
</span>
-->
</div>
<!-- <h3>Individual slide text</h3> -->
<!-- Slider 3 -->
<div class="slider" id="slider3">
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/jungle.jpg)">
<span>
<h2>I'm a title for Slide #1</h2>
</span>
</div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_110627-8240-Myst.jpg)">
<span>
<h2>I'm a title for Slide #2</h2>
</span>
</div>
<div style="background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30256/1200_bodie-11.jpg)">
<span>
<h2>I'm a title for Slide #3</h2>
</span>
</div>
<!-- The Arrows -->
<i class="left" class="arrows" style="z-index:2; position:absolute;"><svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z"></path>
</svg></i>
<i class="right" class="arrows" style="z-index:2; position:absolute;">
<svg viewBox="0 0 100 100">
<path d="M 10,50 L 60,100 L 70,90 L 30,50 L 70,10 L 60,0 Z" transform="translate(100, 100) rotate(180) "></path>
</svg></i>
<!-- Title Bar -->
<!-- <span class="titleBar">
<h1>I am like a leaf in the wind.</h1>
<p>Watch me soar!</p>
</span> -->
</div>
</div>
<div class="content">
<h2> Responsive. Modular: can be more than one on the page. Defaults to 100% container width, 500px height. Pauses slideshow on hover.</h2>
<h2>Images are Background-images. Filling the container div regardless of the image size.</h2>
<h3>Behavior you can change:
<ul>
<li>autoPlay: "off"</li>
<li>showArrows: "off"</li>
<li>hideDots: "on"</li>
<li>hoverZoom: "off"</li>
<li>titleBarTop: "on"</li>
<li>Change slide pauses and fade speeds</li>
</ul>
</h3>
</div>
.slider,
.slider > div {
/* Images default to Center Center. Maybe try 'center top'? */
background-position: center center;
display: block;
width: 100%;
height: 500px;
/* height: 100vh; *//* If you want fullscreen */
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-color: #000;
overflow: hidden;
-moz-transition: transform .4s;
-o-transition: transform .4s;
-webkit-transition: transform .4s;
transition: transform .4s;
}
.slider > div {
position: absolute;
}
.slider > i {
color: #5bbd72;
position: absolute;
font-size: 60px;
margin: 20px;
top: 40%;
text-shadow: 0 10px 2px #223422;
transition: .3s;
width: 30px;
padding: 10px 13px;
background: #fff;
background: rgba(255, 255, 255, .3);
cursor: pointer;
line-height: 0;
box-sizing: content-box;
border-radius: 3px;
z-index: 4;
}
.slider > i svg {
margin-top: 3px;
}
.slider > .left {
left: -100px;
}
.slider > .right {
right: -100px;
}
.slider:hover > .left {
left: 0;
}
.slider:hover > .right {
right: 0;
}
.slider > i:hover {
background:#fff;
background: rgba(255, 255, 255, .8);
transform: translateX(-2px);
}
.slider > i.right:hover {
transform: translateX(2px);
}
.slider > i.right:active,
.slider > i.left:active {
transform: translateY(1px);
}
.slider:hover > div {
transform: scale(1.01);
}
.hoverZoomOff:hover > div {
transform: scale(1);
}
/* The Dots */
.slider > ul {
position: absolute;
bottom: 10px;
left: 50%;
z-index: 4;
padding: 0;
margin: 0;
transform: translateX(-50%);
}
.slider > ul > li {
padding: 0;
width: 20px;
height: 20px;
border-radius: 50%;
list-style: none;
float: left;
margin: 10px 10px 0;
cursor: pointer;
border: 1px solid #fff;
-moz-transition: .3s;
-o-transition: .3s;
-webkit-transition: .3s;
transition: .3s;
}
.slider > ul > .showli {
background-color: #7EC03D;
-moz-animation: boing .5s forwards;
-o-animation: boing .5s forwards;
-webkit-animation: boing .5s forwards;
animation: boing .5s forwards;
}
.slider > ul > li:hover {
background-color: #7EC03D;
}
.slider > .show {
z-index: 1;
}
.hideDots > ul {
display: none;
}
.showArrows > .left {
left: 0;
}
.showArrows > .right {
right: 0;
}
.titleBar {
z-index: 2;
display: inline-block;
background: rgba(0,0,0,.5);
position: absolute;
width: 100%;
bottom: 0;
transform: translateY(100%);
padding: 20px 30px;
transition: .3s;
color: #fff;
}
.titleBar * {
transform: translate(-20px, 30px);
transition: all 700ms cubic-bezier(0.37, 0.31, 0.2, 0.85) 200ms;
opacity: 0;
}
.titleBarTop .titleBar * {
transform: translate(-20px, -30px);
}
.slider:hover .titleBar,
.slider:hover .titleBar * {
transform: translate(0);
opacity: 1;
}
.titleBarTop .titleBar {
top: 0;
bottom: initial;
transform: translateY(-100%);
}
.slider > div span {
display: block;
background: rgba(0,0,0,.5);
position: absolute;
bottom: 0;
color: #fff;
text-align: center;
padding: 0;
width: 100%;
}
@keyframes boing {
0% {
transform: scale(1.2);
}
40% {
transform: scale(.6);
}
60% {
transform: scale(1.2);
}
80% {
transform: scale(.8);
}
100% {
transform: scale(1);
}
}
/* -------------------------------------- */
#slider2 {
max-width: 30%;
margin-right: 20px;
}
.row2Wrap {
display: flex;
}
.content {
padding: 50px;
margin-bottom: 100px;
}
html {
height: 100%;
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
h1, h2, h3 {
font-family: 'Crimson Text', sans-serif;
font-weight: 100;
}
body {
font: 15px 'Titillium Web', Arial, sans-serif;
background: radial-gradient(#121212, #000);
height: 100%;
color: #aaa;
margin: 0;
padding: 0;
}
.content {
padding: 10px 15vw;
}
(function($) {
"use strict";
$.fn.sliderResponsive = function(settings) {
var set = $.extend(
{
slidePause: 5000,
fadeSpeed: 800,
autoPlay: "on",
showArrows: "off",
hideDots: "off",
hoverZoom: "on",
titleBarTop: "off"
},
settings
);
var $slider = $(this);
var size = $slider.find("> div").length; //number of slides
var position = 0; // current position of carousal
var sliderIntervalID; // used to clear autoplay
// Add a Dot for each slide
$slider.append("<ul></ul>");
$slider.find("> div").each(function(){
$slider.find("> ul").append('<li></li>');
});
// Put .show on the first Slide
$slider.find("div:first-of-type").addClass("show");
// Put .showLi on the first dot
$slider.find("li:first-of-type").addClass("showli")
//fadeout all items except .show
$slider.find("> div").not(".show").fadeOut();
// If Autoplay is set to 'on' than start it
if (set.autoPlay === "on") {
startSlider();
}
// If showarrows is set to 'on' then don't hide them
if (set.showArrows === "on") {
$slider.addClass('showArrows');
}
// If hideDots is set to 'on' then hide them
if (set.hideDots === "on") {
$slider.addClass('hideDots');
}
// If hoverZoom is set to 'off' then stop it
if (set.hoverZoom === "off") {
$slider.addClass('hoverZoomOff');
}
// If titleBarTop is set to 'on' then move it up
if (set.titleBarTop === "on") {
$slider.addClass('titleBarTop');
}
// function to start auto play
function startSlider() {
sliderIntervalID = setInterval(function() {
nextSlide();
}, set.slidePause);
}
// on mouseover stop the autoplay and clear interval
$slider.mouseover(function() {
clearInterval(sliderIntervalID);
});
// on mouseout starts the autoplay by calling startSlider
$slider.mouseout(function() {
startSlider();
});
//on right arrow click
$slider.find("> .right").click(nextSlide)
//on left arrow click
$slider.find("> .left").click(prevSlide);
// Go to next slide
function nextSlide() {
position = $slider.find(".show").index() + 1;
if (position > size - 1) position = 0;
changeCarousel(position);
}
// Go to previous slide
function prevSlide() {
position = $slider.find(".show").index() - 1;
if (position < 0) position = size - 1;
changeCarousel(position);
}
//when user clicks slider button
$slider.find(" > ul > li").click(function() {
position = $(this).index();
changeCarousel($(this).index());
});
//this changes the image and button selection
function changeCarousel() {
$slider.find(".show").removeClass("show").fadeOut();
$slider
.find("> div")
.eq(position)
.fadeIn(set.fadeSpeed)
.addClass("show");
// The Dots
$slider.find("> ul").find(".showli").removeClass("showli");
$slider.find("> ul > li").eq(position).addClass("showli");
}
return $slider;
};
})(jQuery);
//////////////////////////////////////////////
// Activate each slider - change options
//////////////////////////////////////////////
$(document).ready(function() {
$("#slider1").sliderResponsive({
// Using default everything
// slidePause: 5000,
// fadeSpeed: 800,
// autoPlay: "on",
// showArrows: "off",
// hideDots: "off",
// hoverZoom: "on",
// titleBarTop: "off"
});
$("#slider2").sliderResponsive({
fadeSpeed: 300,
autoPlay: "off",
showArrows: "on",
hideDots: "on"
});
$("#slider3").sliderResponsive({
hoverZoom: "off",
hideDots: "on"
});
});
Also see: Tab Triggers