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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<header class="header">
<a class="header__logo" href="#">
<span class="logo__title">John Doe</span>
<img class="logo__image" src="https://i.imgur.com/Q4LtrpQ.png" alt="John Doe">
</a>
<nav class="header__nav">
<ul class="header__list">
<li><a class="header__link" href="#">Home</a></li>
<li><a class="header__link" href="#">About</a></li>
<li><a class="header__link" href="#">Contact</a></li>
</ul>
</nav>
<div class="burger">
<svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="ic_fluent_navigation_24_regular" fill="#ffffff" fill-rule="nonzero">
<path d="M2.75254822,18 L21.2525482,18 C21.6667618,18 22.0025482,18.3357864 22.0025482,18.75 C22.0025482,19.1296958 21.7203943,19.443491 21.3543188,19.4931534 L21.2525482,19.5 L2.75254822,19.5 C2.33833466,19.5 2.00254822,19.1642136 2.00254822,18.75 C2.00254822,18.3703042 2.2847021,18.056509 2.65077766,18.0068466 L2.75254822,18 L21.2525482,18 L2.75254822,18 Z M2.75254822,11.5030063 L21.2525482,11.5030063 C21.6667618,11.5030063 22.0025482,11.8387927 22.0025482,12.2530063 C22.0025482,12.6327021 21.7203943,12.9464972 21.3543188,12.9961597 L21.2525482,13.0030063 L2.75254822,13.0030063 C2.33833466,13.0030063 2.00254822,12.6672199 2.00254822,12.2530063 C2.00254822,11.8733105 2.2847021,11.5595153 2.65077766,11.5098529 L2.75254822,11.5030063 L21.2525482,11.5030063 L2.75254822,11.5030063 Z M2.75168905,5.0032392 L21.251689,5.0032392 C21.6659026,5.0032392 22.001689,5.33902564 22.001689,5.7532392 C22.001689,6.13293497 21.7195352,6.44673016 21.3534596,6.49639258 L21.251689,6.5032392 L2.75168905,6.5032392 C2.33747549,6.5032392 2.00168905,6.16745276 2.00168905,5.7532392 C2.00168905,5.37354343 2.28384293,5.05974824 2.64991849,5.01008582 L2.75168905,5.0032392 L21.251689,5.0032392 L2.75168905,5.0032392 Z" id="🎨-Color"></path>
</g>
</g>
</svg>
</div>
</header>
<nav class="mobile-nav hidden">
<ul class="mobile-nav__list">
<li><a class="mobile-nav__link" href="#">Home</a></li>
<li><a class="mobile-nav__link" href="#">About</a></li>
<li><a class="mobile-nav__link" href="#">Contact</a></li>
</ul>
<div class="mobile-nav__close">
<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" x="0px" y="0px" viewBox="0 0 490 490" style="enable-background:new 0 0 490 490;" xml:space="preserve">
<polygon fill="#ffffff" points="456.851,0 245,212.564 33.149,0 0.708,32.337 212.669,245.004 0.708,457.678 33.149,490 245,277.443 456.851,490 489.292,457.678 277.331,245.004 489.292,32.337 "/>
</svg>
</div>
</nav>
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,[email protected],400;0,700;1,400&display=swap');
:root {
--header-height: 50px;
--header-background: #2c2c2c;
--header-hover: #414141;
}
* {
box-sizing: border-box;
list-style: none;
margin: 0;
padding: 0;
text-decoration: none;
text-transform: none;
}
html, body {
min-height: 100vh;
height: 100%;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
}
.header {
display: flex;
width: 100%;
padding: 0 10px;
height: var(--header-height);
background: var(--header-background);
}
.header__logo {
display: flex;
align-items: center;
justify-content: center;
padding: 0 10px;
color: white;
font-weight: bold;
font-size: 1.3rem;
}
.logo__image {
width: var(--header-height);
padding: 10px;
}
.header__nav {
display: flex;
}
.header__list {
display: flex;
}
.header__link {
display: flex;
align-items: center;
padding: 0 10px;
height: var(--header-height);
color: white;
}
.header__link:hover {
background: var(--header-hover);
}
.burger {
display: flex;
justify-content: center;
align-items: center;
padding: 0 10px;
cursor: pointer;
margin-left: auto;
}
.mobile-nav {
display: flex;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--header-background);
transition: display 0.3s;
}
.mobile-nav__list {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
}
.mobile-nav__link {
display: flex;
justify-content: center;
padding: 10px 0;
color: white;
font-weight: bold;
}
.mobile-nav__close {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #212121;
height: var(--header-height);
cursor: pointer;
}
/* tablet */
@media (max-width: 768px) {
.header__nav { display: none; }
.header { position: fixed; bottom: 0; left: 0; }
}
/* desktop */
@media (min-width: 769px) {
.burger { display: none; }
}
.hidden {
display: none;
}
const burger = document.querySelector('.burger');
const mobileNavClose = document.querySelector('.mobile-nav__close');
const mobileNav = document.querySelector('.mobile-nav');
burger.addEventListener('click', (e) => {
mobileNav.classList.toggle('hidden');
});
mobileNavClose.addEventListener('click', (e) => {
mobileNav.classList.toggle('hidden');
});
Also see: Tab Triggers