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.
<ul class="nav site-nav">
<li><a href=#>Lorem</a></li><!--
--><li><a href=#>Ipsum</a></li><!--
--><li class=flyout>
<a href=#>Dolor</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li><a href=#>Foo Bar</a></li>
<li><a href=#>Bar Baz</a></li>
<li class="flyout-alt">
<a href=#>Baz Foo</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li><a href=#>Foo Bar</a></li>
<li><a href=#>Bar Baz</a></li>
<li class="flyout-alt">
<a href=#>Baz Foo</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li class="flyout-alt">
<a href=#>Foo Bar</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li><a href=#>Bar Baz</a></li>
<li class="flyout-alt">
<a href=#>Baz Foo</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li><a href=#>Bar Baz</a></li>
<li><a href=#>Baz Foo</a></li>
<li><a href=#>Foo Bar</a></li>
</ul>
</li>
<li><a href=#>Foo Bar</a></li>
</ul>
</li>
<li><a href=#>Bar Baz</a></li>
<li class="flyout-alt">
<a href=#>Baz Foo</a>
<!-- Flyout -->
<ul class="flyout-content nav stacked">
<li><a href=#>Bar Baz</a></li>
<li><a href=#>Baz Foo</a></li>
<li><a href=#>Foo Bar</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li><!--
--><li><a href=#>Sit</a></li><!--
--><li><a href=#>Amet</a></li>
</ul>
/*------------------------------------*\
$HOUSEKEEPING
\*------------------------------------*/
*{ margin:0; padding:0; }
html{
padding:5%;
font:1em/1.5 Georgia, serif;
overflow-y:scroll;
}
ul{
margin-bottom:1.5em;
margin-left:1.5em;
}
a{
text-decoration:none;
}
/*------------------------------------*\
$NAV
\*------------------------------------*/
/**
* Throw any `ul` or `ol` into horizontal mode, as per csswizardry.com/2011/09/the-nav-abstraction.
<ul class=nav>
<li><a href=/>Home</a></li>
<li><a href=/about>About</a></li>
<li><a href=/portfolio>Portfolio</a></li>
<li><a href=/contact>Contact</a></li>
</ul>
*/
.nav{
list-style:none;
margin-left:0;
}
.nav > li,
.nav > li > a{
display:inline-block;
*display:inline;
zoom:1;
}
/**
* Create a vertically stacked nav by extending `.nav` with `.stacked`.
<ul class="nav stacked">
<li><a href=/>Home</a></li>
<li><a href=/about>About</a></li>
<li><a href=/portfolio>Portfolio</a></li>
<li><a href=/contact>Contact</a></li>
</ul>
*/
.stacked > li{
display:list-item;
}
.stacked > li > a{
display:block;
}
/*------------------------------------*\
$FLYOUT
\*------------------------------------*/
/**
* Flyouts are pieces of content that fly out of a parent when said parent is hovered.
* They typically appear bottom-left of the parent.
<div class=flyout>
Foo
<div class=flyout-content>
<h1>Lorem</h1>
<p>Ipsum</p>
</div>
</div>
*/
.flyout,
.flyout-alt{
position:relative;
}
.flyout-content{
/* Position the flyouts off-screen. This is typically better than `display:none;`. */
position:absolute;
top:100%;
left:-99999px;
/**
* Even though they are out of document flow, lots of nested flyouts can
* eventually force scroll bars to appear as they become taller than the viewport.
* We can undo this effect by giving them zero height.
*/
height:0;
overflow:hidden;
}
/**
* Bring the flyouts into view when you hover their parents.
* Two different types of flyout; ‘regular’ (`.flyout`) and ‘alternative’ (`.flyout-alt`).
*/
/* Regular flyouts sit all the way from the top, flush left. */
.flyout:hover > .flyout-content{
left:0;
}
/* Alternative flyouts sit all the way from the left, flush top. */
.flyout-alt:hover > .flyout-content{
top:0;
left:100%;
}
.flyout:hover > .flyout-content,
.flyout-alt:hover > .flyout-content{
/* Give the flyouts their height back once they come into view. */
height:auto;
overflow:visible;
}
/*------------------------------------*\
$SITE-NAV
\*------------------------------------*/
/**
* Site nav specific styling.
* Extends `.nav{}`
*/
.site-nav{
font-size:0.75em;
font-family:sans-serif;
}
.site-nav a{
line-height:1;
padding:1em;
background-color:#09f;
color:#fff;
white-space:nowrap;
}
/*--- SITE-NAV FLYOUTS ---*/
/**
* Site nav specific flyouts, extension of `.flyout`.
* Set up some styles to apply and persist when we hover things in the site nav.
* This allows us to keep parents highlighted as we hover their contained flyouts [1].
*/
.site-nav .flyout:hover > a /* [1] */,
.site-nav .flyout-alt:hover > a /* [1] */,
.site-nav a:hover{
color:#435704;
background-color:#BADA55;
}
/**
* Add an indicator to any flyout parents in the site nav to show there’s a flyout.
*/
.site-nav .flyout-alt > a:after{
content:" »";
}
/**
* Here we set up a load of shared borders on the site-nav specific flyouts.
* The code looks a little scattered but it allows us to cleverly share declarations:
* We set up a non-existent [1] solid [2] border on all sides of the relevant elements.
* We can now also change the style [2] and colour [3] of all borders in one go.
* Now we have set up border colours and styles, we need to just turn the desired borders ‘on’ [4].
*/
.site-nav a,
.site-nav .flyout-content{
border:0 /* [1] */
solid /* [2] */
#fff /* [3] */;
}
.site-nav > li > a{
border-left-width:1px; /* [4] */
}
/* The first link in the site-nav doesn’t require a border at all. */
.site-nav > li:first-child > a{
border:none;
}
.site-nav .flyout-content{
border-width:1px 0 0 1px; /* [4] */
}
.site-nav .flyout-content a{
border-bottom-width:1px; /* [4] */
}
.site-nav .flyout-alt:hover > .flyout-content{
/**
* To account for the 1px top border on the flyout containers, we need to
* bring the flyouts back up by 1px in this special instance.
*/
top:-1px;
}
Also see: Tab Triggers