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

              
                

		<h1>Pure CSS carousel</h1>

		<section class="carousel carousel-2x1" id="carousel2">
			<div class="carousel-toggle__wrap opacity manual-play">
				<input type="radio" name="carousel" id="carouselRadio1" class="carousel-toggle" checked="checked" />
				<article class="carousel-block">
					<label for="carouselRadio4" class="previous-next previous-next__previous"><span class="label-str">Previous</span> &lt; </label>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Headlands_sunset__16-9__430x242.jpg" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Headlands_sunset__16-9__1200x675.jpg 1200w, https://s3-us-west-2.amzonaws.com/s.cdpn.io/691293/Headlands_sunset__16-9__992x558.jpg 992w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Headlands_sunset__16-9__768x432.jpg 768w" />
					<div class="carousel-block__sub">
						<h1><label for="carouselRadio1">carousel 1 (radio)</label></h1>
						<p>This is some carousel stuff</p>
						<p><a href="#">this is a link (1)</a></p>
					</div>
					<label for="carouselRadio2" class="previous-next previous-next__next"><span class="label-str">Next</span> &gt; </label>
				</article>

				<input type="radio" name="carousel" id="carouselRadio2" class="carousel-toggle" />
				<article class="carousel-block">
					<label for="carouselRadio1" class="previous-next previous-next__previous"><span class="label-str">Previous</span> &lt; </label>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/iAccellerate_sunset__16-9__430x242.jpg" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/iAccellerate_sunset__16-9__1200x765.jpg 1200w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/iAccellerate_sunset__16-9__992x558.jpg 992w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/iAccellerate_sunset__16-9__768x432.jpg 768w" />
					<div class="carousel-block__sub">
						<h1><label for="carouselRadio2">carousel 2 (radio)</label></h1>
						<p>This is some carousel stuff</p>
						<p><a href="#">this is a link (2)</a></p>
					</div>
					<label for="carouselRadio3" class="previous-next previous-next__next"><span class="label-str">Next</span> &gt; </label>
				</article>

				<input type="radio" name="carousel" id="carouselRadio3" class="carousel-toggle" />
				<article class="carousel-block">
					<label for="carouselRadio2" class="previous-next previous-next__previous"><span class="label-str">Previous</span> &lt; </label>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Thirroul-Sunrise__16-9__430x242.jpg" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Thirroul-Sunrise__16-9__1200x675.jpg 1200w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Thirroul-Sunrise__16-9__992x558.jpg 992w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/Thirroul-Sunrise__16-9__768x432.jpg 768w" />
					<div class="carousel-block__sub">
						<h1><label for="carouselRadio3">carousel 3 (radio)</label></h1>
						<p>This is some carousel stuff</p>
						<p><a href="#">this is a link (3)</a></p>
					</div>
					<label for="carouselRadio4" class="previous-next previous-next__next"><span class="label-str">Next</span> &gt; </label>
				</article>

				<input type="radio" name="carousel" id="carouselRadio4" class="carousel-toggle" />
				<article class="carousel-block">
					<label for="carouselRadio3" class="previous-next previous-next__previous"><span class="label-str">Previous</span> &lt; </label>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/National-Folk-festival_sunrise__16-9__430x242.jpg" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/National-Folk-festival_sunrise__16-9__1200x675.jpg 1200w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/National-Folk-festival_sunrise__16-9__992x558.jpg 992w, https://s3-us-west-2.amazonaws.com/s.cdpn.io/691293/National-Folk-festival_sunrise__16-9__768x432.jpg 768w                                                                                                                            " />
					<div class="carousel-block__sub">
						<h1><label for="carouselRadio4">carousel 4 (radio)</label></h1>
						<p>This is some carousel stuff</p>
						<p><a href="#">this is a link (4)</a></p>
					</div>
					<label for="carouselRadio1" class="previous-next previous-next__next"><span class="label-str">Next</span> &gt; </label>
				</article>
				<input type="checkbox" name="playPause" id="playPause" class="playPause carousel-play" title="play/pause" />
			</div>
		</section>

		<p>See these pens for more ideas:</p>
		<h2>User initiated</h2>
		<ul>
			<li><a href="https://codepen.io/keithclark/pen/pjwvm">A pure CSS carousel</a> [<a href="https://codepen.io/keithclark/">Keith Clark</a>] (user triggered)</li>
			<li><a href="https://codepen.io/calebdwilliams/pen/tLnzb">Responsive CSS-only carousel</a> [<a href="https://codepen.io/calebdwilliams/">Caleb Williams</a>]</li>
			<li><a href="https://codepen.io/robmazan/pen/wBrObJ">CSS only carousel</a> [<a href="https://codepen.io/robmazan">Robert Mazan </a>]</li>
			<li><a href="https://codepen.io/vas3a/pen/xbvOPo">CSS only carousel</a> [<a href="https://codepen.io/vas3a/">vas3a</a>]</li>
			<li><a href="https://codepen.io/CharlieHawker/pen/emwpxq">Variable height CSS only carousel</a> [<a href="https://codepen.io/CharlieHawker/">Charlie Hawker</a>]</li>
		</ul>
		<h2>No user interaction</h2>
		<ul>
			<li><a href="https://codepen.io/j_mes/pen/jPELQK">CSS only carousel</a> [<a href="https://codepen.io/j_mes/">James Loveridge</a>]</li>
			<li><a href="https://codepen.io/floatingboxes/pen/chrGb">Silly simple CSS-only carousel</a> [<a href="https://codepen.io/floatingboxes/">Dan Sweeney</a>]</li>
			<li><a href="https:/codepen.io/epainter/pen/jdLvG">CSS only carousel</a> [<a href="https://codepen.io/epainter">Emily Painter</a>]</li>
			<li><a href="https://codepen.io/ssantee/pen/eiabB">CSS only carousel</a> [<a href="https://codepen.io/ssantee">Steven Santee </a>]</li>
		</ul>
              
            
!

CSS

              
                $xs-min: 0;
$xs-max: 429px;
$sm-min: $xs-max + 1;
$sm-max: 767px;
$md-min: $sm-max + 1;
$md-max: 991px;
$lg-min: $md-max + 1;
$lg-max: 1119px;
$xl-min: $lg-max + 1;
$xl-max: 100000px;
$ln-height: 150%;
body {
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
  line-height: $ln-height;
  padding-top: 2em;
}

@mixin proportional-height($x, $y, $input , $offset: 4.3) {
	$padTop: ((( $input / $x ) * $y ) - $offset );
	padding-top: #{$padTop}em;
}

.carousel {
  border: 0.1em solid #ccc;
  margin-bottom: 1em;
  position: relative;
  width: 100%;
  height: 2.7em;
  z-index: 0;
  text-align: center;
  border-style: double;
  border-spacing: 0.1em;
  border-width: 0.2em;
  @for $i from 5 through 25 {
    &-height-#{$i} {
      height: #{$i}em;
    }
  }
  @for $i from 200 through 10 {
    @media screen and (max-width: #{$i}em) {
      &-1x1 {
        @include proportional-height(1, 1, $i);
      }
      &-3x2 {
        @include proportional-height(3, 2, $i);
      }
      &-4x3 {
        @include proportional-height(4, 3, $i);
      }
      &-5x3 {
        @include proportional-height(5, 3, $i);
      }
      &-16x9 {
        @include proportional-height(16, 9, $i);
      }
      &-2x1 {
        @include proportional-height(2, 1, $i);
      }
    }
  }
  &-toggle__wrap {
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 0.4em 0.5em 0.25em;
    display: inline;
    border-radius: 0.3em;
    &.manual-play .playPause {
      display: none;
    }
    &.auto-play .playPause {
      display: inline;
    }
  }
  &-block {
    display: block;
    padding: 1.5em 1em 1em;
    position: absolute;
    top: 0%;
    right: 0%;
    bottom: 0%;
    left: 0%;
    transition: opacity 0.75s ease-in;
    overflow: hidden;
    img {
      position: absolute;
      top: 0%;
      right: 0%;
      left: 0%;
      z-index: -1;
      width: 100%;
    }
    &__sub {
      background-color: rgba(0, 0, 0, 0.7);
      padding: 0.75em 1em;
      position: absolute;
      bottom: -10em;
      left: 1em;
      color: #fff;
      transition: bottom 0.5s ease-out 0.3s;
      text-align: left;
      a {
        color: #ff0;
      }
      h1 {
        margin: 0 0 0.5em;
      }
      p {
        margin: 0.5em 0 0;
      }
    }
  }
}

input.carousel-toggle {
  + .carousel-block {
    z-index: -100;
    opacity: 0;
  }
  &:checked + .carousel-block {
    z-index: -1;
    opacity: 1;
    .carousel-block__sub {
      bottom: 1em;
    }
  }
}

.previous-next {
  position: absolute;
  top: 0%;
  bottom: 0%;
  width: 2.25em;
  font-weight: bold;
  padding-top: 20%;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  &:hover {
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    opacity: 1;
    z-index: 1000;
  }
  .label-str {
    display: block;
    text-indent: -1000em;
  }
  &__previous {
    left: 0%;
  }
  &__next {
    right: 0%;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console