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.
<div class="container">
<main class="main" role="main">
<div class="mask"></div>
<header>
<h1>Off-Canvas Menu</h1>
</header>
<section class="content">
<p>Ullamcorper inceptos in magna vestibulum penatibus aliquet tellus suspendisse nascetur convallis a id diam netus a a parturient posuere nam orci fermentum duis habitasse nam. Iaculis eros hendrerit rhoncus et enim commodo nulla vivamus consequat id rhoncus vestibulum a maecenas justo vestibulum mi vel purus id ullamcorper mus a. Potenti mattis placerat ligula a suspendisse ipsum mus elementum a himenaeos et aliquam inceptos euismod ad placerat sociosqu mauris vestibulum conubia condimentum semper penatibus ridiculus. Dictumst diam eros fames a elementum eros mus fusce feugiat vestibulum a dui parturient ad ullamcorper suspendisse eleifend vestibulum facilisi ridiculus. Condimentum felis sed laoreet aliquam proin dignissim eu mi ad vestibulum ut suspendisse volutpat nibh cras mi praesent morbi ad. Est libero facilisis vestibulum suspendisse rutrum fames a facilisi semper interdum consectetur consectetur a scelerisque parturient volutpat ad eros torquent tincidunt senectus risus adipiscing donec parturient. Maecenas mus suspendisse laoreet non morbi vestibulum eros dolor nam nullam nec parturient nascetur suspendisse tincidunt suspendisse convallis blandit.</p>
<p>Quam hendrerit id a netus porta dictumst eu sem adipiscing eleifend curae id euismod malesuada rhoncus ac vel. Conubia elit eleifend condimentum adipiscing volutpat diam in eget consectetur nascetur convallis est lorem adipiscing scelerisque. Id consequat adipiscing eros a eleifend lobortis nullam aliquet suscipit a nam malesuada accumsan risus ipsum curabitur a elit viverra adipiscing nam dictumst aliquam torquent non sociosqu venenatis. Ullamcorper vestibulum metus ullamcorper consectetur velit quisque hac a ac fermentum adipiscing mus mauris ac himenaeos scelerisque. Mi lorem mus euismod nunc erat turpis vel cum mi elementum proin venenatis ipsum dui placerat commodo interdum ipsum eu.</p>
<p>Scelerisque condimentum pulvinar accumsan eget at nibh aliquet a maecenas lectus magnis per metus a mattis. Non ullamcorper dapibus in nostra a vitae scelerisque fusce ullamcorper lacinia cum magna vestibulum malesuada eros mus a phasellus a egestas pulvinar pretium aliquet. Adipiscing.</p>
</section>
</main>
<aside class="sidebar">
<nav class="nav">
<ul class="nav-items">
<li class="nav-title">Pages</li>
<li><a href="#" class="nav-link">Home</a></li>
<li><a href="#" class="nav-link">Products</a></li>
<li><a href="#" class="nav-link">Services</a></li>
<li><a href="#" class="nav-link">About</a></li>
<li><a href="#" class="nav-link">News</a></li>
</ul>
<div class="sidebar-separator"></div>
<ul class="nav-items">
<li class="nav-title">More</li>
<li><a href="#" class="nav-link">Contact</a></li>
<li><a href="#" class="nav-link">Support</a></li>
<li><a href="#" class="nav-link">Careers</a></li>
</ul>
</nav>
</aside>
<div class="hamburger">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
</div>
/* Page */
html {
box-sizing: border-box;
overflow: hidden;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html, body {
height: 100%;
}
body {
background: #fff;
font-family: 'Roboto', sans-serif;
line-height: 1.5em;
color: #888;
}
.container {
position: relative;
overflow-x: hidden;
height: 100%;
width: 100%;
}
/* Main */
.main {
display: table;
height: 100%;
position: relative;
transition-property: transform;
}
.mask {
display: table-row;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
opacity: 0;
pointer-events: none;
transition-property: opacity;
}
header {
background-color: #3498db;
background-image: -webkit-linear-gradient(top, #3498db 0%, #217dbb 100%);
background-image: linear-gradient(to bottom, #3498db 0%, #217dbb 100%);
padding: 100px 50px;
text-align: center;
}
header h1 {
color: #fff;
font-size: 3em;
line-height: 1;
text-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
}
.content {
margin: 50px 50px;
}
/* Sidebar */
.sidebar {
position: fixed;
z-index: 5;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: #1d2127;
border-right: 3px solid #0f1114;
overflow: hidden;
-webkit-transform: translate3d(-260px, 0, 0);
transform: translate3d(-260px, 0, 0);
transition-property: transform;
will-change: transform, -webkit-transform;
}
.sidebar, .sidebar a {
color: #abb4be;
}
.nav {
margin-top: 100px;
}
.nav-items {
margin: 0;
padding: 0;
list-style: none;
}
.nav-title {
display: block;
padding: 10px 50px;
text-transform: uppercase;
font-weight: 600;
color: #465162;
}
.nav-link {
display: block;
padding: 10px 50px;
text-decoration: none;
transition: background-color 0.3s ease;
}
.nav-link:hover {
background-color: #282d36;
}
.sidebar-separator {
margin: 30px;
height: 2px;
background-color: #000;
border-bottom: 1px solid #2b313a;
}
/* Hamburger Icon */
.hamburger {
display: block;
position: fixed;
left: 50px;
top: 20px;
cursor: pointer;
z-index: 10;
border-radius: 5px;
background-color: #3498db;
border: 2px solid #ddd;
padding: 10px 7px;
width: 50px;
height: 46px;
transition-property: background-color, border-color;
}
.bar {
display: block;
position: relative;
background-color: #ddd;
width: 100%;
height: 4px;
border-radius: 2px;
margin: 0 auto;
transition-property: transform, opacity, background-color, width;
}
.bar:first-child {
top: 0;
}
.bar:nth-child(2) {
opacity: 1;
}
.bar:last-child {
bottom: 0;
}
.hamburger:hover {
border-color: #fff;
}
.hamburger:hover .bar {
background-color: #fff;
}
.bar + .bar {
margin-top: 5px;
}
/* Animation */
.main, .sidebar, .mask, .hamburger, .bar {
transition-duration: 0.3s;
transition-timing-function: cubic-bezier(.694, .0482, .335, 1);
}
/* Show Sidebar */
.show-sidebar .main {
-webkit-transform: translate3d(260px, 0, 0);
transform: translate3d(260px, 0, 0);
}
.show-sidebar .sidebar {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.show-sidebar .mask {
opacity: 1;
pointer-events: auto;
}
.show-sidebar .hamburger {
background-color: #282d36;
border-color: #0f1114;
}
.show-sidebar .bar {
background-color: #abb4be;
}
.show-sidebar .bar:first-child {
width: 120%;
-webkit-transform: rotate(45deg) translate(5px, 8px);
transform: rotate(45deg) translate(5px, 8px);
}
.show-sidebar .bar:nth-child(2) {
opacity: 0;
}
.show-sidebar .bar:last-child {
width: 120%;
-webkit-transform: rotate(-45deg) translate(4px, -8px);
transform: rotate(-45deg) translate(4px, -8px);
}
var container = document.querySelector('.container');
var main = document.querySelector('.main');
function toggleSidebar(){
isShowingSidebar() ? hideSidebar() : showSidebar();
}
function showSidebar(){
container.classList.add('show-sidebar');
}
function hideSidebar(){
container.classList.remove('show-sidebar');
}
function isShowingSidebar(){
return container.classList.contains('show-sidebar');
}
document.querySelector('.hamburger').addEventListener('click', toggleSidebar, false);
container.addEventListener('click', function(e){
if(isShowingSidebar() && main.contains(e.target)){
e.preventDefault();
hideSidebar();
}
}, true);
Also see: Tab Triggers