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.
<header>
<div class="logo">LOGO</div>
<input type="checkbox" class="checkbox">
<div class="span-container">
<span></span>
<span></span>
<span></span>
</div>
<div class="nav-container">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</div>
</header>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
body{
padding: 0 5rem;
background: #222;
}
// --------BURGER MENU CODE :D
header {
width: 100%;
height: 100px;
background: #333;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding: 2rem;
position: relative;
}
.logo {
font-weight: 800;
color: white;
font-size: clamp(1.5rem, 5vw, 3rem);
}
//Set up our checkbox + Span container positioning and size
.span-container,
.checkbox {
width: 45px;
height: 45px;
position: absolute;
right: 2rem;
top: 50%;
transform: translateY(-50%);
}
//Lets make our checkbox function but dissapear. Also lets add some z-index so it's always on top [clickable]
.checkbox {
opacity: 0;
z-index: 100;
}
//Add some flex for our Three lines. Our span-container will have flex
.span-container {
display: flex;
flex-flow: row wrap;
align-items: center;
z-index: 90;
}
//Style our span (3 burger-menu lines)
.span-container span {
width: 100%;
height: 3px;
background: white;
//We need to add transition and a transform origin of 0 0 (top left).
//Try commenting bits out to see what happens and why it's important.
transition: all 250ms ease-out;
transform-origin: 0 0;
}
//Transitions [animations]
//Logic: When checkbox is checked:
//Rotate Span1 -45Deg (first child or nth-last-child(1))
//Make Span2 smaller + hide it.
//rotate Span3 45 Deg.
//The translate stuff is just for small adjustments. Try changing them and see //how the X looks like when checkbox:checked.
.checkbox:checked ~ .span-container span:nth-last-child(1) {
transform: rotate(-45deg) translate(-1px, 0px);
}
.checkbox:checked ~ .span-container span:nth-last-child(2) {
transform: rotate(0deg) scale(0.2, 0.2);
opacity: 0;
}
.checkbox:checked ~ .span-container span:nth-last-child(3) {
transform: rotate(45deg) translate(0px, -1px);
}
//style our navigation for full screen when checkbox:checked.
.nav-container{
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100vh;
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
z-index: 50;
background: #444;
transition: all 250ms ease-out;
//translate(-100%, 0%) basically hides the entire navigation to the left by 100%. [invisible.]
//This is great as all we do when we checkbox:checked is change these values to 0%, 0% and it will
//transition. Pretty good.
transform: translateX(-100%);
a {
text-decoration: none;
color: white;
font-size: clamp(1.4rem, 2.4vw, 2.2rem);
margin: 1rem auto;
}
a:hover {
color: salmon;
}
}
.checkbox:checked ~ .nav-container {
transform: translateX(0%);
}
//Now we add style for full-width screen [not mobile]
@media screen and (min-width: 1000px) {
//Lets hide our checkbox and spans, we won't need them.
.checkbox,
.span-container
{
display: none;
}
//Copy EVERYTHING from .nav-container above and then change all values.
//We must do this as our aim is to OVERWRITE everything to be exactly as we need.
.nav-container{
position: relative;
left: none;
top: none;
width: auto;
height: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
z-index: 50;
background: transparent;
transition: none;
transform: none;
a {
margin-right: 1.5rem;
}
}
}
//Try playing around with this, understand the logic and then build it yourself.
//As a first experiment create a checkbox that makes a div-square change a color. That's essentially all this is with a few more styling details.
Also see: Tab Triggers