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.
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mr. CSS Lion</title>
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
</head>
<body>
<div class="lion">
<span class="mane">
<span class="head">
<span class="eye left"></span>
<span class="eye right"></span>
<span class="nose"></span>
</span>
<span class="ear left">
<span class="inner"></span>
</span>
<span class="ear right">
<span class="inner"></span>
</span>
</span>
<span class="body">
<span class="paw left"></span>
<span class="paw right"></span>
<span class="leg left"></span>
<span class="leg right"></span>
</span>
<span class="tail">s</span>
</div>
</body>
</html>
@import compass
// ============== { ('_') } ==============
// Let's make a lion with CSS and then animate him. Why? BECAUSE REASONS.
// I also thought I'd use Mr.Lion to show a few examples of why I love using Sass to write CSS (http://sass-lang.com/)
// I'm also using Compass (http://compass-style.org/) which goes along with Sass really well and saves you from writing all of the required vendor prefixes out. For example, instead of writing all the prefixes for border-radius you can just do @include border-radius(amount). Yay!
@import compass/reset
@import compass/css3
// ======================================
// Sass rocks because VARIABLES { ('_') }
// ======================================
// Let's define some colours for Mr. Lion. Sass is AWESOME for this, since you can re-use these colour names all over and not have to change them in a bunch of places if Mr.Lion decides he wants to dye his fur pink one day.
$tan: #f5cd88
$mane: #ed8641
$dkbrown: #604f31
// You can also use variables for other things, anything that you might want to repeat a lot or refer to in a way that's easy to see why you're using it. I'll use one for a common border style.
$border-oval: 50%
// ============================================
// Sass rocks because COLOUR FUNCTIONS { ('_') }
// ============================================
// Mr. Lion also has a few highlights and shaded areas. Sass has this very cool inbuilt function to lighten or darken colours to create new colours based on our existing colour variables. Shiny.
$tan-highlight: lighten($tan, 15%)
$mane-shade: darken($mane, 5%)
// ===================================
// Sass rocks because MIXINS { ('_') }
// ===================================
// If we find ourselves repeating a bunch of properties on multiple elements, we can put these in a mixin to save ourselves repetition when using them over and over. Mixins can also be passed arguments if we need to customise them further!
// For example, a good way to center absolutely positioned elements regardless of their width is to give them the below properties which we'll reuse as mixins.
@mixin center-element-x
left: 50%
@include transform(translateX(-50%))
@mixin center-element
left: 50%
top: 50%
@include transform(translateX(-50%) translateY(-50%))
// ===================================
// Sass rocks because NESTING { ('_') }
// ===================================
// We can avoid so much of the usual repetition we get with writing CSS. W00t.
body
font-family: 'Lato', sans-serif
padding: 50px 0
.lion
width: 250px
height: 300px
position: relative
margin: 0 auto
span
position: absolute
.head
width: 140px
height: 105px
top: 50px
z-index: 2
background-color: $tan
@include border-radius($border-oval)
@include center-element-x
.eye
width: 15px
height: 22px
top: 30px
z-index: 2
background-color: $dkbrown
border: solid 10px $tan-highlight
@include border-radius($border-oval)
// &.left in Sass is the equivalent of doing .eye.left to chain classes in CSS. Less to write! Yay!
&.left
left: 10px
&.right
right: 10px
-webkit-animation: blink 8s infinite
.nose
width: 18px
height: 12px
top: 70px
z-index: 2
background-color: $dkbrown
@include border-radius($border-oval)
@include center-element-x
.mane
width: 219px
height: 180px
top: 0
z-index: 1
background-color: $mane
@include border-radius($border-oval)
@include center-element-x
-webkit-animation: head-tilt 6s infinite
//Bottom of mane
&:before
content: ''
display: block
position: absolute
width: 0
height: 0
bottom: -54px
left: 60px
color: $mane
// You can also indent within properties in Sass to make things like
// border sides easier to write!
border: 50px solid transparent
top: 100px solid $mane
bottom: 0
@include transform(scaleX(1.9))
//Mane shading
&:after
content: ''
display: block
position: absolute
width: 140px
height: 105px
bottom: 15px
left: 40px
background-color: $mane-shade
@include border-radius($border-oval)
.ear
// You can use variables within selectors too, where you might find yourself
// repeating a value multiple times.
$ear: 60px
width: $ear
height: $ear
top: 18px
z-index: 2
background-color: $tan
@include border-radius($ear)
&.left
left: -15px
&:before
left: 60px
@include transform(scaleX(1.5) rotate(-20deg))
&.right
right: -15px
&:before
right: 120px
top: -35px
@include transform(scaleX(1.5) rotate(20deg))
.inner
// Another super-useful thing that Sass can do is calculations! :D
// To make sure that Mr. Lion's inner ear always stays in proportion
// with his outer ear, we could do this:
$inner-ear: $ear * 0.66
width: $inner-ear
height: $inner-ear
background-color: $tan-highlight
@include border-radius($inner-ear)
@include center-element
// Mane fluff
&:before
content: ''
position: absolute
width: 0
height: 0
top: -30px
color: $mane
border: 15px solid transparent
bottom: 30px solid $mane
top: 0
@include transform(scaleX(1.5))
.body
width: 120px
height: 260px
top: 30px
background-color: $tan
@include border-radius(40px)
@include center-element-x
// Belly
&:after
content: ''
position: absolute
width: 80px
height: 200px
left: 20px
top: 40px
background-color: $tan-highlight
@include border-radius(40px)
.tail
font-size: 150px
right: 0
top: 160px
color: $tan
@include transform(rotate(20deg))
-webkit-animation: sway 2s linear alternate infinite
-webkit-transform-origin: 20px 80px
&:after
content: 'w'
position: absolute
top: 49px
left: 43px
font:
size: 40px
weight: 700
color: $mane
@include transform(rotate(110deg))
.leg
width: 50px
height: 100px
bottom: -30px
z-index: -1
background-color: $tan
@include border-radius(15px)
&.left
left: 0
&.right
right: 0
&:after
content: 'm'
display: block
position: absolute
font-size: 30px
bottom: -3px
color: $tan-highlight
@include center-element-x
.paw
width: 60px
height: 35px
top: 133px
background-color: $tan
@include border-radius(15px)
&.left
left: -35px
&:after
left: 5px
&.right
right: -35px
&:after
right: 5px
-webkit-animation: wave 0.5s 5s linear 3
//inner paw
&:after
$paw: 20px
content: ''
display: block
position: absolute
top: 7px
width: $paw
height: $paw
background-color: $tan-highlight
@include border-radius($paw)
// ============================================
// Animations for Mr. Lion { ('_') }
// ============================================
@-webkit-keyframes sway
from
@include transform(rotate(20deg))
to
@include transform(rotate(40deg))
@-webkit-keyframes head-tilt
0%
@include transform(translateX(-50%) rotate(0deg))
50%
@include transform(translateX(-50%) rotate(-5deg))
0%
@include transform(translateX(-50%) rotate(0deg))
@-webkit-keyframes blink
0%
@include transform(scaleY(1))
50%
@include transform(scaleY(1))
51%
@include transform(scaleY(0.1))
52%
@include transform(scaleY(1))
100%
@include transform(scaleY(1))
@-webkit-keyframes wave
0%
@include transform(rotate(0deg))
50%
@include transform(rotate(-30deg))
100%
@include transform(rotate(0deg))
Also see: Tab Triggers