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.
section.Grid
- for (var i=0; i<3; i++)
.Grid-row
- for (var j=0; j<3; j++)
- var id = (i*3 + j + 1)
a.Card(onClick="openGallery("+id+")", id="card-"+id)
.Card-thumb
.Card-shadow
.Card-shadow
.Card-shadow
.Card-image(style="background-image: url(https://robohash.org/"+id+")")
.Card-title
span Super interesting card
.Card-explore
span Explore 50 more
button.Card-button view more
- for (var i=1; i<=9; i++)
section.Gallery(id="gallery-"+i)
.Gallery-header
a.Gallery-close(onclick="closeAll()") ×
.Gallery-images
.Gallery-left
.Gallery-image
.Gallery-image
.Gallery-image.Gallery-image--primary(style="background-image: url(https://robohash.org/"+i+")")
- for (var j=1; j<=4; j++)
.Gallery-images
.Gallery-image
.Gallery-image
.Gallery-image
color-grey-1 = #F5F5F5
color-grey-9 = #212121
color-purple-1 = #673AB7
color-purple-2 = #3F51B5
color-purple-3 = #2196F3
color-card-bg = #607D8B
color-bg = #FFF
color-header = #eee
body
background: color-grey-1
font-family: 'Libre Franklin', sans-serif
.Grid
width: 50rem
margin: 5rem auto
&-row
display: flex
justify-content: space-between
margin-bottom: 2.5rem
.Card
position: relative
flex: 0 1 15rem
background-color: white
padding-bottom: 5rem
transition: background-color .2s cubic-bezier(0.5, 0.3, 0.8, 0.06)
color: #000
&-thumb
position: relative
width: 15rem
height: 10rem
perspective-origin: 50% 0%;
perspective: 600px
z-index: 1
&-image,
&-shadow
position: absolute
display: block
width: 15rem
height: 10rem
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0)
&-shadow
opacity: .8
&:nth-child(1)
opacity: .6
background-color: color-purple-1
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0) .07s
&:nth-child(2)
opacity: .7
background-color: color-purple-2
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0) .05s
&:nth-child(3)
background-color: color-purple-3
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0) .03s
&-image
position: relative
background-size: auto 100%
background-position: center
background-repeat: no-repeat
background-color: color-card-bg
&::before
position: absolute
top: 0
right: 0
bottom: 0
left: 0
background-color: color-purple-2
content: ''
opacity: 0
transition: opacity .1s
&-title,
&-explore
position: absolute
bottom: 0
display: flex
align-items: center
width: 100%
height: 5rem
text-align: center
transition: all .2s cubic-bezier(0.5, 0.3, 0.8, 0.06)
span
padding: .5rem
flex: 1 1 auto
text-align: center
&-explore
opacity: 0
transform: translate(0, -1rem)
font-size: 0.75rem
text-transform: uppercase
letter-spacing: 1px
color: color-purple-1
&-button
position: absolute
left: 50%
top: 5rem
padding: .5rem 1rem
background-color: #fff
border-radius: 2rem
border: 2px solid color-purple-2
color: #fff
font-size: .75rem
font-weight: 600
transform: translate(-50%, 2rem)
cursor: pointer
transition: all .2s
opacity: 0
outline: none
z-index: 4
.Card:hover,
.Card--active
background-color: color-grey-1
cursor: pointer
.Card
&-thumb
z-index: 3
&-title
opacity: 0
&-explore
opacity: 1
transform: translate(0, 1rem)
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0) .1s
&-image
transform: scale(1.05) translate(0, -1rem) rotateX(25deg)
&::before
opacity: .4
&-shadow:nth-child(3)
transform: scale(1.02) translate(0, -.3rem) rotateX(15deg)
&-shadow:nth-child(2)
transform: scale(.9) translate(0, 1rem) rotateX(15deg)
&-shadow:nth-child(1)
transform: scale(.82) translate(0, 2.4rem) rotateX(5deg)
&-button
opacity: 1
color: color-purple-2
transform: translate(-50%, 0)
&:hover
color: #fff
background-color: color-purple-2
.Card--active, .Card--active:hover
background: none
.Card
&-explore
opacity: 0
transform: translate(0, 3rem)
transition: all .5s cubic-bezier(0.42, 0.0, 0.58, 1.0)
&-image
opacity: 0
transition: all .4s cubic-bezier(0.42, 0.0, 0.58, 1.0)
transform: scale(1.05) translate(0, -2.5rem) rotateX(50deg)
&::before
opacity: .4
&-button
opacity: 0
transition: all .35s cubic-bezier(0.42, 0.0, 0.58, 1.0)
transform: translate(-50%, -2rem) scale(1, 0.4)
for r in (1..3)
.Grid-row:nth-child({r})
dRow = r - 2
for num in (1..3)
.Card:nth-child({num})
dCol = num - 2
&.Card--active, .Card--active:hover
.Card
&-shadow:nth-child(3)
transition: all .2s cubic-bezier(0.7, 0.0, 0.78, 1.0)
transform: scale(1) translate(-108% + (dCol * -114%), -55% + (dRow * -168%))
&-shadow:nth-child(2)
transition: all .2s cubic-bezier(0.7, 0.0, 0.78, 1.0) .1s
transform: scale(1) translate(-108% + (dCol * -114%), 55% + (dRow * -168%))
&-shadow:nth-child(1)
transition: all .2s cubic-bezier(0.7, 0.0, 0.78, 1.0) .2s
transform: scale(2.1) translate(26% + (dCol * -55%), (dRow * -80%))
.Gallery
display: block
position: fixed
top: 0
right: 0
bottom: 0
left: 0
background: color-grey-1
opacity: 0
transform: scale(1.2)
transition: none
padding: 18rem 0
overflow-y: scroll
&-header
position: absolute
left: 0
right: 0
top: 0
background-color: color-header
padding-bottom: 5rem
&-close
position: absolute
right: 1rem
top: 1rem
font-size: 3rem
opacity: .5
cursor: pointer
&:hover
opacity: .8
&-images
display: flex
width: 47rem
margin: 0 auto
justify-content: space-between
margin-bottom: 1rem
for r in (3..6)
&:nth-child({r})
transition: all 0.2s cubic-bezier(0.7, 0.0, 0.78, 1.0) (.11s * r)
opacity: 0
transform: translate(0, 3rem) scale(1.1)
&-left
flex: 1 auto
display: flex
justify-content: space-between
flex-direction: column
&-image
display: block
width: 15rem
height: 9.5rem
transition: all .2s cubic-bezier(0.42, 0.0, 0.58, 1.0)
background: lighten(color-card-bg, 50%)
background-size: auto 100%
background-position: center
background-repeat: no-repeat
&--primary
width: 31rem
height: 20rem
background-color: color-purple-1
.Gallery--active
z-index: 100
background: color-bg
transform: scale(1)
opacity: 1
transition: all 0.5s cubic-bezier(0.7, 0.0, 0.78, 1.0) .1s
.Gallery
&-close
display: block
&-images
opacity: 1
transform: none
function openGallery(id) {
closeAll();
const gallery = document.getElementById('gallery-'+id);
const card = document.getElementById('card-'+id);
gallery.classList.add('Gallery--active');
card.classList.add('Card--active');
}
function closeAll() {
const galleryActv = document.querySelector('.Gallery--active');
const cardActv = document.querySelector('.Card--active');
if (galleryActv) {
galleryActv.classList.remove('Gallery--active');
}
if (cardActv) {
cardActv.classList.remove('Card--active');
}
}
Also see: Tab Triggers