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.
<div class="container">
<div data-am-fadeshow="next-prev-navigation">
<!-- Radio -->
<input type="radio" name="css-fadeshow" id="slide-1" />
<input type="radio" name="css-fadeshow" id="slide-2" />
<input type="radio" name="css-fadeshow" id="slide-3" />
<!-- Slides -->
<div class="fs-slides">
<div class="fs-slide" style="background-image: url(https://images.unsplash.com/photo-1460500063983-994d4c27756c?crop=entropy&fit=crop&fm=jpg&h=1325&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=2550);">
<!-- Add content to images (sample) -->
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-family: sans-serif; text-align: center; text-shadow: 0 0 20px rgba(0,0,0,0.5);">
<h1 style="margin-top: 0; margin-bottom: 0.8vw; font-size: 5vw; font-weight: bold;">CSS Fadeshow</h1>
<p style="font-size: 2vw; font-weight: 100; margin-top: 0;">Easy to implement and use on <strong>your</strong> site!</p>
</div>
</div>
<div class="fs-slide" style="background-image: url(https://images.unsplash.com/photo-1440557653082-e8e186733eeb?crop=entropy&fit=crop&fm=jpg&h=1325&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=2500);"></div>
<div class="fs-slide" style="background-image: url(https://images.unsplash.com/photo-1449057528837-7ca097b3520c?crop=entropy&fit=crop&fm=jpg&h=1325&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=2500);"></div>
</div>
<!-- Quick Navigation -->
<div class="fs-quick-nav">
<label class="fs-quick-btn" for="slide-1"></label>
<label class="fs-quick-btn" for="slide-2"></label>
<label class="fs-quick-btn" for="slide-3"></label>
</div>
<!-- Prev Navigation -->
<div class="fs-prev-nav">
<label class="fs-prev-btn" for="slide-1"></label>
<label class="fs-prev-btn" for="slide-2"></label>
<label class="fs-prev-btn" for="slide-3"></label>
</div>
<!-- Next Navigation -->
<div class="fs-next-nav">
<label class="fs-next-btn" for="slide-1"></label>
<label class="fs-next-btn" for="slide-2"></label>
<label class="fs-next-btn" for="slide-3"></label>
</div>
</div>
</div>
/*
* CSS Fadeshow by @alexerlandsson
* This is a fadeshow built in CSS and with customization in focus.
* Supports quick navigation, prev/next navigation and autoplay.
*
* For better documentation and implementation guide, check out the GitHub repository:
* https://github.com/alexerlandsson/css-fadeshow
*/
/*
* ===== VARIABLES =====
*
* Change these variables to match your preferences. For a more detailed
* description of what each variable do, visit https://github.com/alexerlandsson/css-fadeshow
*/
$max-slides: 5;
$prefix: true;
$responsive: true;
$breakpoint-small: 500px;
$fade-time: 1;
$prev-next-fontfamily: sans-serif;
$prev-next-icon-size: 3vw;
$prev-next-icon-color: rgba(255,255,255,0.5);
$prev-next-bg: rgba(255,255,255,0);
$prev-next-bg-hover: rgba(255,255,255,0.1);
$prev-icon: '❮';
$next-icon: '❯';
$autohide-next-prev: true;
$quick-nav-color: rgba(255,255,255,0.8);
$quick-nav-active-color: coral;
$fade-color: #fff;
$autoplay: true;
$autoplay-duration: 5;
/*
* ===== MIXINS =====
*
* This section contains mixin used
* Do not change anything here unless you know what you are doing.
*/
/* Mixins to handle prefixes */
@mixin fadeshow-transition($value...) {
@if length($value) < 1 {
$value: all 150ms linear;
}
@if $prefix == true {
-webkit-transition: $value;
}
transition: $value;
}
@mixin fadeshow-transform($value...) {
@if length($value) < 1 {
$value: all 150ms linear;
}
@if $prefix == true {
-webkit-transform: $value;
-ms-transform: $value;
}
transform: $value;
}
@mixin fadeshow-animation($value...) {
@if $prefix == true {
-webkit-animation: $value;
}
animation: $value;
}
@mixin fadeshow-animation-delay($value) {
@if $prefix == true {
-webkit-animation-delay: $value;
}
animation-delay: $value;
}
@mixin fadeshow-unselectable() {
@if $prefix == true {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
user-select: none;
}
/* Mixins to handle Quick Navigation Button states */
@mixin quickNavBtnActive() {
background-color: $quick-nav-active-color;
}
@mixin quickNavBtnInactive() {
background-color: $quick-nav-color;
}
/*
* ===== FADESHOW =====
*
* Base functionality for the fadeshow.
* Do not change anything here unless you know what you are doing.
*/
[data-am-fadeshow] {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
background-color: $fade-color;
/* Slides */
.fs-slide {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
@include fadeshow-transition(opacity #{$fade-time}s ease);
/* Display first child on load */
&:first-child {
opacity: 1;
}
}
/* Quick Navigation */
.fs-quick-nav {
position: absolute;
bottom: 15px;
left: 50%;
z-index: 1;
@include fadeshow-unselectable();
@include fadeshow-transform(translateX(-50%));
}
.fs-quick-btn {
display: inline-block;
width: 15px;
height: 15px;
margin: 0 2px;
border-radius: 50%;
cursor: pointer;
@include fadeshow-transition(opacity 200ms ease);
@include quickNavBtnInactive();
&:hover {
opacity: 0.8;
}
/* Set active state to first button on load */
&:first-child {
@include quickNavBtnActive();
}
}
/* Prev/Next Navigation */
%prev-next {
position: absolute;
display: none;
top: 0;
bottom: 0;
width: 100px;
cursor: pointer;
font-family: $prev-next-fontfamily;
background-color: $prev-next-bg;
-webkit-tap-highlight-color: rgba(0,0,0,0);
@include fadeshow-transition(all 200ms ease);
@if $responsive == true {
@media (max-width: $breakpoint-small) {
width: 50%;
}
}
&:before {
position: absolute;
top: 50%;
font-size: $prev-next-icon-size;
color: $prev-next-icon-color;
}
&:hover {
background-color: $prev-next-bg-hover;
@if $responsive == true {
@media (max-width: $breakpoint-small) {
background-color: rgba(255,255,255,0);
}
}
}
}
.fs-prev-btn {
@extend %prev-next;
left: 0;
&:before {
content: "#{$prev-icon}";
left: 50%;
@include fadeshow-transform(translate(-50%, -50%));
@if $responsive == true {
@media (max-width: $breakpoint-small) {
left: 30px;
}
}
}
@if $autohide-next-prev == true {
@include fadeshow-transform(translateX(-100%));
@if $responsive == true {
@media (max-width: $breakpoint-small) {
@include fadeshow-transform(translate(0));
}
}
}
}
.fs-next-btn {
@extend %prev-next;
right: 0;
&:before {
content: "#{$next-icon}";
right: 50%;
@include fadeshow-transform(translate(50%, -50%));
@if $responsive == true {
@media (max-width: $breakpoint-small) {
right: 30px;
}
}
}
@if $autohide-next-prev == true {
@include fadeshow-transform(translateX(100%));
@if $responsive == true {
@media (max-width: $breakpoint-small) {
@include fadeshow-transform(translate(0));
}
}
}
}
/* Base functionality */
input[type="radio"] {
position: fixed;
top: -9999px;
&:checked {
/* This loop handles the slide switching and quick navigation active state */
$i: $max-slides;
@while $i > 0 {
&:nth-of-type(#{$i}) {
/* Show slide */
~ .fs-slides {
.fs-slide {
//Cancel autoplay
opacity: 0;
@include fadeshow-animation(none !important);
}
.fs-slide:nth-child(#{$i}) {
opacity: 1;
}
}
/* Add active state to dot */
~ .fs-quick-nav {
.fs-quick-btn {
@include quickNavBtnInactive();
/* Cancel autoplay */
@include fadeshow-animation(none !important);
}
.fs-quick-btn:nth-child(#{$i}) {
background-color: $quick-nav-active-color;
&:hover {
opacity: 1;
}
}
}
}
$i: $i - 1;
}
/* Hide navigation if only one slide */
&:first-of-type:last-of-type {
~ .fs-quick-nav,
~ .fs-prev-nav,
~ .fs-next-nav {
display: none !important;
}
}
}
}
/* Autohide Prev/Next Navigation */
@if $autohide-next-prev == true {
&:hover {
.fs-prev-btn,
.fs-next-btn {
@include fadeshow-transform(translateX(0));
}
}
}
}
/*
* ===== PREV/NEXT NAVIGATION =====
*
* This section handles the prev/next navigation.
*/
/* Handle Prev/Next buttons */
[data-am-fadeshow~="next-prev-navigation"] {
input[type="radio"] {
&:checked {
$i: $max-slides;
@while $i > 0 {
&:nth-of-type(#{$i}) {
$prev: ($i - 1);
$next: ($i + 1);
/* Show previous button */
@if $prev > 0 {
~ .fs-prev-nav {
.fs-prev-btn {
display: none;
}
.fs-prev-btn:nth-child(#{$prev}) {
display: block;
}
}
}
/* Show next button */
@if $next < ($max-slides + 1) {
~ .fs-next-nav {
.fs-next-btn {
display: none;
}
.fs-next-btn:nth-child(#{$next}) {
display: block;
}
}
}
/* Show last prev button if first slide */
&:first-of-type {
~ .fs-prev-nav {
.fs-prev-btn:last-child {
display: block;
}
}
}
/* Show first next button if last slide */
&:last-of-type {
~ .fs-next-nav {
.fs-next-btn:first-child {
display: block;
}
}
}
}
$i: $i - 1;
}
}
}
/* Display first pair of Prev/Next Buttons on load */
.fs-prev-btn:last-child {
display: block;
}
.fs-next-btn:nth-child(2) {
display: block
}
}
/*
* ===== AUTOPLAY =====
*
* Functions to handle autoplay.
* If you're not going to use autoplay, set $autoplay to false.
* This part tends to compile into a lot of uneccesary CSS otherwise.
*/
@if $autoplay == true {
$i: $max-slides;
@while $i > 1 {
$total-duration: $autoplay-duration * $i;
@keyframes quickNavAnimation-#{$i} {
0% { @include quickNavBtnInactive(); }
#{100% * $fade-time / $total-duration},
#{100% * $autoplay-duration / $total-duration} { @include quickNavBtnActive(); }
#{100% * ($autoplay-duration + $fade-time) / $total-duration},
100% { @include quickNavBtnInactive(); }
}
@if $prefix == true {
@-webkit-keyframes quickNavAnimation-#{$i} {
0% { @include quickNavBtnInactive(); }
#{100% * $fade-time / $total-duration},
#{100% * $autoplay-duration / $total-duration} { @include quickNavBtnActive(); }
#{100% * ($autoplay-duration + $fade-time) / $total-duration},
100% { @include quickNavBtnInactive(); }
}
}
@keyframes slidesAnimation-#{$i} {
0% { opacity: 0; }
#{100% * $fade-time / $total-duration},
#{100% * $autoplay-duration / $total-duration} { opacity: 1; }
#{100% * ($autoplay-duration + $fade-time) / $total-duration},
100% { opacity: 0; }
}
@if $prefix == true {
@-webkit-keyframes slidesAnimation-#{$i} {
0% { opacity: 0; }
#{100% * $fade-time / $total-duration},
#{100% * $autoplay-duration / $total-duration} { opacity: 1; }
#{100% * ($autoplay-duration + $fade-time) / $total-duration},
100% { opacity: 0; }
}
}
[data-am-fadeshow~="autoplay"] {
input[type="radio"]:nth-of-type(#{$i}):last-of-type {
/* Slide animation */
~ .fs-slides {
.fs-slide {
@include fadeshow-animation(slidesAnimation-#{$i} #{$total-duration}s infinite);
}
}
/* Quick navigation animation */
~ .fs-quick-nav {
.fs-quick-btn {
@include fadeshow-animation(quickNavAnimation-#{$i} #{$total-duration}s infinite);
}
}
/* Animation Delay */
@for $j from 1 through $i {
~ .fs-slides .fs-slide:nth-child(#{$j}),
~ .fs-quick-nav .fs-quick-btn:nth-child(#{$j}) {
$animation-delay: #{($j - 1) * ($autoplay-duration) - $fade-time}s;
@include fadeshow-animation-delay(#{$animation-delay});
}
}
}
$i: $i - 1;
}
}
}
/* Base Styling */
body {
margin: 0;
}
.container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
overflow: hidden;
}
Also see: Tab Triggers