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>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Dancing+Script">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
</head>
<body>
<div class="container">
<header>
<div class="menu-toggle" data-js="menu-toggle">
<span class="menu-toggle-grippy">Toggle</span>
<span class="menu-toggle-label">Menu</span>
</div>
</header>
<section class="banner" role="banner">
<h1>Hello there</h1>
<h2>This is an experimental CodePen which utilises an absolutely positioned hidden panel which can be triggered by clicking a toggle.</h2>
</section>
<div class="hidden-panel">
<span class="hidden-panel-close" data-js="hidden-panel-close">Close</span>
<div class="hidden-panel-content">
<nav class="hidden-panel-nav">
<h3>Quick Look</h3>
<ul>
<li><a href="#" title="Home">Home</a></li>
<li><a href="#" title="About">About</a></li>
<li><a href="#" title="Blog">Blog</a></li>
<li><a href="#" title="Work">Work</a></li>
<li><a href="#" title="Contact">Contact</a></li>
</ul>
</nav>
<div class="hidden-panel-text">
<p>This is an experimental CodePen which utilises an absolutely positioned hidden panel which can be triggered by clicking a toggle.</p>
</div>
<div class="hidden-panel-credits">
<span>Coded by <a href="https://twitter.com/darrenhuskie" title="Darren Huskie">Darren Huskie</a>.</span>
<span>Powered by <a href="#" title="some framework">some framework</a>.</span>
<span>Hosted by a <a href="#" title="web host">web host</a>.</span>
</div>
</div>
</div>
</div>
</body>
</html>
body
color: #878787
font-family: Roboto, sans-serif
left: 0
line-height: 1.35
margin: 0
overflow: hidden
position: relative
text-rendering: optimizeLegibility
-webkit-font-smoothing: antialiased
transition: left 0.3s ease-in-out
&.panel-open
left: -250px
.container
@extend %cf
min-height: 1000px
a
outline: 0
text-decoration: none
h1, h2, h3, h4, h5, h6
margin: 0
padding: 0
header
@extend %cf
color: #fff
padding: 3em 5%
position: relative
width: 90%
z-index: 2
.menu-toggle
@extend %cf
cursor: pointer
float: right
font-size: 0.875rem
transition: all 0.3s ease-in-out
&.open
opacity: 0.5
.menu-toggle-grippy
border-bottom: 5px solid #fff
border-top: 5px solid #fff
float: left
line-height: 0
margin-right: 1em
padding: 5px 0
text-indent: -999em
width: 35px
&:after
background: #fff
content: ''
display: block
height: 5px
.menu-toggle-label
float: left
font-weight: 700
height: 25px
letter-spacing: 1px
line-height: 25px
text-transform: uppercase
.hidden-panel
background: #333
color: #666
font-size: 0.875rem
height: 100%
position: absolute
right: -250px
top: 0
width: 250px
a
color: #999
transition: color 0.3s ease-out
&:hover
color: #fff
.hidden-panel-close
color: #666
cursor: pointer
position: absolute
right: 20px
top: 3.7em
transition: color 0.3s ease-in-out
&:hover
color: #fff
.hidden-panel-content
padding: 3.65em 10%
.hidden-panel-nav
border-bottom: 1px solid #666
border-bottom: 1px solid rgba(#666, 0.25)
margin-bottom: 1.5em
padding-bottom: 1.5em
text-transform: uppercase
h3
letter-spacing: 1px
margin-bottom: 1em
ul
list-style: none
font-weight: 600
margin: 0
padding: 0
li
padding: 0.25em 0
.hidden-panel-text
line-height: 1.5
p
margin-bottom: 1.5em
&:last-child
margin-bottom: 0
.hidden-panel-credits
font-size: 12px
font-size: 0.75rem
line-height: 1.5
span
display: block
margin-bottom: 0.15em
.banner
background: #f5756c
background: linear-gradient(#f5756c,#fd5480),#f5756c
box-sizing: border-box
height: 100%
left: 0
padding: 5em 0
position: absolute
text-align: center
top: 0
width: 100%
z-index: 1
h1
color: #fff
font-family: 'Dancing Script'
font-size: 4.375rem
margin-bottom: 1em
h2
color: #fff
font-size: 2rem
font-weight: 300
line-height: 1.5
margin: 0 auto
width: 50%
%cf:before, %cf:after
content: ''
display: table
%cf:after
clear: both
var menuToggle = document.querySelector('[data-js="menu-toggle"]');
// Remove this setInterval to trigger the open/close manually through the UI
var interval = setInterval(function() {
menuToggle.click();
}, 2000);
// Clear the interval on any click
document.body.addEventListener('click', function () {
clearInterval(interval);
});
menuToggle.addEventListener('click', function () {
document.body.classList.toggle('panel-open');
menuToggle.classList.toggle('open');
});
var closePanel = document.querySelector('[data-js="hidden-panel-close"]');
closePanel.addEventListener('click', function () {
document.body.classList.remove('panel-open');
menuToggle.classList.remove('open');
});
Also see: Tab Triggers