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 id="sequence" class="seq">
<ul class="seq-canvas">
<li class="step1 valign seq-in">
<div class="vcenter">
<img data-seq class="feature" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/bananas.png" alt="A cartoon illustration of a bunch of bananas" width="389" height="300" />
<h2 data-seq class="title">Bananas</h2>
</div>
</li>
<li class="step2 valign">
<div class="vcenter">
<img data-seq class="feature" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/coconut.png" alt="A cartoon illustration of half a coconut" width="325" height="300" />
<h2 data-seq class="title">Coconut</h2>
</div>
</li>
<li class="step3 valign">
<div class="vcenter">
<img data-seq class="feature" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/orange.png" alt="A cartoon illustration of a round orange" width="350" height="300" />
<h2 data-seq class="title">Orange</h2>
</div>
</li>
</ul>
<fieldset class="nav" aria-label="Slider buttons" aria-controls="sequence">
<button type="button" class="seq-prev" aria-label="Previous"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/prev.svg" alt="Previous" /></button>
<ul role="navigation" aria-label="Pagination" class="seq-pagination">
<li class="seq-current">
<a href="#step1" rel="step1" title="Go to bananas">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/tn-bananas@2x.png" alt="Bananas" width="50" height="40" />
</a>
</li>
<li>
<a href="#step2" rel="step2" title="Go to coconut">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/tn-coconut@2x.png" alt="Coconut" width="50" height="40" />
</a>
</li>
<li>
<a href="#step3" rel="step3" title="Go to orange">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/tn-orange@2x.png" alt="Orange" width="50" height="40" />
</a>
</li>
</ul>
<button type="button" class="seq-next" aria-label="Next"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154/next.svg" alt="Next" /></button>
</fieldset>
</div>
/*
* Styles: Body, HTML, and container
* 1: Make the application fullscreen
* 2: Basic reset styles
*/
body,
html,
.seq {
/* #1 */
width: 100%;
height: 100%;
/* #2 */
margin: 0;
padding: 0;
}
/*
* Styles: Container
* 1: Canvas, steps, and content should be positioned relative to the container
* 2: Hide anything that goes beyond the boundaries of the Sequence container
* 3: Some basic styles
* 4: Set the initial background color
* 5: Make the background color transition when navigating between steps
*/
.seq {
/* #1 */
position: relative;
/* #2 */
overflow: hidden;
/* #3 */
font-family: sans-serif;
color: white;
text-align: center;
/* #4 */
background-color: #2A93BC;
/* #5 */
transition-duration: .5s;
transition-property: background-color;
}
/*
* Styles: Canvas and steps
* 1: Make the width/height of the screen, canvas, and steps the same size as the Sequence element
* 2: Reset the canvas and steps for better browser consistency
*/
.seq-canvas,
.seq-canvas > * {
/* #1 */
height: 100%;
width: 100%;
/* #2 */
margin: 0;
padding: 0;
list-style: none;
}
/*
* Styles: steps
* 1: Position steps all in the same place
* 2: Add whitespace around each step
* 3: Make space for the pagination
*/
.seq-canvas > * {
/* #1 */
position: absolute;
/* #2 */
padding: 32px;
box-sizing: border-box;
/* #3 */
height: auto;
top: 0;
bottom: 80px;
}
.seq-step1 {
background-color: #2A93BC;
}
.seq-step2 {
background-color: #6BC85E;
}
.seq-step3 {
background-color: #45367E;
}
.feature {
width: 70%;
max-width: 100%;
height: auto;
}
@media only screen and (min-width: 460px) and (min-height: 520px) {
.feature {
width: 100%;
}
}
/* Ghost element */
.valign:before {
content: "";
height: 100%;
}
/* Vertically align the ghost and desired elements */
.valign:before,
.valign > .vcenter {
display: inline-block;
vertical-align: middle;
}
/* Remove 4px gap to allow consistent valign */
.valign {
font-size: 0;
}
/* Reset font-size on valigned elements */
.valign > .vcenter {
font-size: 16px;
}
/*
* 1: Reset
* 2: Titles should start as transparent
* 3: When a change in opacity occurs, transition over .5s
*/
.title {
/* #1 */
margin: 0;
/* #2 */
opacity: 0;
transform: translateX(50px) translateZ(0);
/* #3 */
transition-duration: .5s;
transition-property: opacity, transform;
}
/*
* When a step is active, fade in to opaque and slide to the center
*/
.seq-in .title {
opacity: 1;
transform: translateX(0) translateZ(0);
}
/*
* When a step becomes inactive, fade out and slide to the left
*/
.seq-out .title {
opacity: 0;
transform: translateX(-50px) translateZ(0);
}
/*
* Scale an image to 0 (so it can't be seen) when in its start position
*/
.feature {
transform: translateZ(0) scale(0);
transition-duration: .5s;
transition-property: transform, opacity;
}
/*
* When a step is active, make the image scale in
*/
.seq-in .feature {
transform: translateZ(0) scale(1);
}
/*
* When a step becomes inactive, make the image fade out but maintain full scale
*/
.seq-out .feature {
transform: translateZ(0) scale(1);
opacity: 0;
}
/*
* Styles: element holding navigation UI
* 1: Position the nav 40px from the bottom and make it full-width
* 2: Reset styles for the <fieldset> element
*/
.nav {
/* #1 */
position: absolute;
z-index: 100;
left: 0;
right: 0;
bottom: 2.5em;
max-width: 640px;
width: 100%;
/* #2 */
border: none;
margin: 0 auto;
padding: 0;
}
/*
* Styles: previous/next buttons
* 1: Reset styles
* 2: General styles
* 3: Set up the `opacity` so that it will transition from 70% transparency to opaque when hovered over
*/
.seq-next,
.seq-prev {
/* #1 */
padding: 0;
background: transparent;
border: none;
/* #2 */
padding: .75em;
cursor: pointer;
color: white;
font-size: .75em;
text-transform: uppercase;
/* #3 */
opacity: .7;
transition-duration: .25s;
transition-property: opacity;
}
.seq-next:hover,
.seq-prev:hover {
opacity: 1;
}
/*
* Styles: next/previous buttons and pagination container
*/
.seq-next,
.seq-prev,
.seq-pagination {
position: relative;
display: inline-block;
vertical-align: middle;
margin-top: 0;
}
/*
* Add some space to sides of pagination
*/
.seq-pagination {
margin: 0 1em;
padding: 0;
}
/*
* Styles: pagination links
* 1: Make the links relative so their active indicator dot can be position: absolute
* 2: Reset styles
* 3: Make the links sit side-by-side
* 4: General styles
*/
.seq-pagination li {
/* #1 */
position: relative;
/* #2 */
list-style: none;
/* #3 */
display: inline-block;
vertical-align: middle;
/* #4 */
width: 50px;
height: 40px;
margin: 0 .25em;
}
/*
* Styles: A small dot that appears when a pagination link is active
* 1: position the dot under the image and centered
* 2: Make the dot transparent when not active and set up a transition for when it becomes active
*/
.seq-pagination li:before {
/* #1 */
content: "";
display: block;
position: absolute;
top: 100%;
left: 50%;
width: 6px;
height: 6px;
margin-left: -3px;
margin-top: .5em;
border-radius: 50%;
background: white;
/* #2 */
opacity: 0;
transition-duration: .25s;
transition-property: opacity;
}
/*
* Show the indicator dot for the current link
*/
.seq-pagination .seq-current:before {
opacity: .7;
}
/*
* Reset styles
*/
.seq-pagination img,
.seq-pagination a {
display: block;
border: none;
}
// imagesLoaded.js, Hammer.js, and Sequence.js loaded as external assets
var sequenceElement = document.getElementById("sequence");
var options = {
keyNavigation: true,
animateCanvas: false,
phaseThreshold: false,
reverseWhenNavigatingBackwards: true
}
var mySequence = sequence(sequenceElement, options);
Also see: Tab Triggers