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.
h3 Pure CSS carousels
.carousel-container
h2 fade in/out
ul.carousel.my-carousel
- var panels = ['A', 'B', 'C', 'D', 'E']
each val in panels
input.carousel__activator(type="radio", id=val, name='activator' checked=(val == panels[0]))
each val, idx in panels
.carousel__controls
label.carousel__control.carousel__control--backward(for=`${(idx == 0) ? panels[panels.length - 1] : panels[idx - 1]}` )
label.carousel__control.carousel__control--forward(for= `${(idx == panels.length - 1) ? panels[0] : panels[idx + 1]}`)
each val in panels
li.carousel__slide
h1= val
.carousel__indicators
each val in panels
label.carousel__indicator(for=val)
.carousel-container
h2 slider
.carousel.my-carousel.carousel--translate
- var panels = ['F', 'G', 'H', 'I', 'J']
each val in panels
input.carousel__activator(type="radio", name="carousel", id=val, checked=(val == panels[0]))
each val, idx in panels
.carousel__controls
label.carousel__control.carousel__control--backward(for=`${(idx == 0) ? panels[panels.length - 1] : panels[idx - 1]}` )
label.carousel__control.carousel__control--forward(for= `${(idx == panels.length - 1) ? panels[0] : panels[idx + 1]}`)
.carousel__track
each val in panels
li.carousel__slide
h1= val
.carousel__indicators
each val in panels
label.carousel__indicator(for=val)
.carousel-container
h2 thumbnail indicators
ul.carousel.my-carousel.carousel--thumb
- var panels = ['K', 'L', 'M', 'N', 'O']
each val in panels
input.carousel__activator(type="radio", id=val, name='thumb' checked=(val == panels[0]))
each val, idx in panels
.carousel__controls
label.carousel__control.carousel__control--backward(for=`${(idx == 0) ? panels[panels.length - 1] : panels[idx - 1]}` )
label.carousel__control.carousel__control--forward(for= `${(idx == panels.length - 1) ? panels[0] : panels[idx + 1]}`)
each val in panels
li.carousel__slide
h1= val
.carousel__indicators
each val in panels
label.carousel__indicator(for=val)
.carousel-container
h2 scale
ul.carousel.my-carousel.carousel--scale
- var panels = ['P', 'Q', 'R', 'S', 'T']
each val in panels
input.carousel__activator(type="radio", id=val, name='scale' checked=(val == panels[0]))
each val, idx in panels
.carousel__controls
label.carousel__control.carousel__control--backward(for=`${(idx == 0) ? panels[panels.length - 1] : panels[idx - 1]}` )
label.carousel__control.carousel__control--forward(for= `${(idx == panels.length - 1) ? panels[0] : panels[idx + 1]}`)
each val in panels
li.carousel__slide
h1= val
.carousel__indicators
each val in panels
label.carousel__indicator(for=val)
@import url('https://fonts.googleapis.com/css?family=Roboto:900');
/**
* style variables
*/
$noOfSlides = 5
$carouselHeight = 300px
$carouselWidth = 400px
$carouselIndicatorSize = 15px
$carouselControlSize = 30px
$slideTransition = .5s
/**
* Control & indicator mixin
*/
.carousel
height $carouselHeight
width $carouselWidth
overflow hidden
text-align center
position relative
padding 0
list-style none
// &__slide
&__controls
&__activator
display none
/**
* Where the magic happens
*/
for num in 1..$noOfSlides
&__activator:nth-of-type({num})
&:checked ~ .carousel__track
transform translateX(-((num - 1) * 100%))
&:checked ~ .carousel__slide:nth-of-type({num})
transition opacity $slideTransition, transform $slideTransition
top 0
left 0
right 0
opacity 1
transform scale(1)
&:checked ~ .carousel__controls:nth-of-type({num})
display block
opacity 1
&:checked ~ .carousel__indicators .carousel__indicator:nth-of-type({num})
opacity 1
/**
* Control element - right/left arrows
*/
&__control
height $carouselControlSize
width $carouselControlSize
margin-top -($carouselControlSize / 2)
top 50%
position absolute
display block
cursor pointer
border-width 5px 5px 0 0
border-style solid
border-color #fafafa
opacity .35
outline 0
z-index 3
&:hover
opacity 1
&--backward
left 10px
transform rotate(-135deg)
&--forward
right 10px
transform rotate(45deg)
/**
* Element for holding slide indicators
*/
&__indicators
position absolute
bottom 20px
width 100%
text-align center
/**
* Indicator for indicating active slide
*/
&__indicator
height $carouselIndicatorSize
width $carouselIndicatorSize
border-radius 100%
display inline-block
z-index 2
cursor pointer
opacity .35
margin 0 2.5px 0 2.5px
&:hover
opacity .75
/**
* Create rules for when slides are contained within a track
*/
&__track
position absolute
top 0
right 0
bottom 0
left 0
padding 0
margin 0
transition transform $slideTransition ease 0s
.carousel__slide
display block
top 0
left 0
right 0
opacity 1
for num in (1..$noOfSlides)
&:nth-of-type({num})
transform translateX((num - 1) * 100%)
&--scale
.carousel__slide
transform scale(0)
&__slide
height 100%
position absolute
overflow-y auto
opacity 0
/**
* Theming
*/
*
box-sizing border-box
html
body
background-color #111
font-family 'Roboto', sans-serif
text-align center
color white
.carousel-container
display inline-block
.my-carousel
border-radius 5px
margin 30px
.carousel__slide
overflow hidden
.carousel
&--thumb .carousel__indicator
height 30px
width 30px
h1
font-size 50px
line-height 50px
color #fafafa
position absolute
top 50%
width 100%
text-align center
margin-top -25px
h2
h3
color #fafafa
h3
font-size 50px
.carousel__indicator
background-color #fafafa
for num in (1..$noOfSlides)
.carousel__slide:nth-of-type({num})
.carousel--thumb .carousel__indicators .carousel__indicator:nth-of-type({num})
// multiply to get better quality pics
background-image url('https://unsplash.it/' + (num * 3) + '00?random')
background-size cover
background-position center
Also see: Tab Triggers