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.
<!-- Made by Erik Terwan -->
<!-- 24th of November 2015 -->
<!-- MIT License -->
<nav role="navigation">
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" id="menuCheckbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<!--
We can use a label here to close upon click (when doing same page navigation), this
does require a slight bit of JS.
-->
<li>
<a href="#">
<label for="menuCheckbox" onclick="this.parentNode.click();">Home</label>
</a>
</li>
<li>
<a href="#about">
<label for="menuCheckbox" onclick="this.parentNode.click();">About</label>
</a>
</li>
<!-- These just close the menu -->
<li><label for="menuCheckbox"><a>Info</a></label></li>
<li><label for="menuCheckbox"><a>Contact</a></label></li>
<!-- Or just use regular URLs -->
<li>
<a href="https://erikterwan.com/" target="_blank">Show me more</a>
</li>
</ul>
</div>
</nav>
<main>
<h1>Pure CSS Hamburger Menu</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis massa eros, commodo in auctor eget, condimentum et velit. Curabitur sit amet rhoncus augue. Sed sed turpis at tortor hendrerit feugiat eget et enim. Curabitur velit neque, pretium eu lacinia et, euismod et diam. Nunc eget ullamcorper lectus. Ut feugiat arcu id leo elementum, eu tincidunt ex imperdiet. Etiam at volutpat enim. Donec porta velit a scelerisque congue. Vestibulum eu sem mauris. Morbi quis lacinia purus, vitae dictum mauris. Nunc elementum eget dolor at finibus. Nullam at iaculis est.</p>
<p>Curabitur tristique venenatis enim id ornare. Maecenas ultrices ex non orci dapibus, vel pharetra nisl imperdiet. Praesent venenatis odio ac tempus pretium. Curabitur interdum purus vel mi ornare, non eleifend ligula consectetur. Vestibulum lacinia nunc leo, fermentum interdum purus commodo ut. Sed auctor efficitur ullamcorper. Aenean nec neque dui. Aenean tincidunt ligula at sodales porta. Nam ultrices nulla dui, sed imperdiet nunc sollicitudin nec.</p>
<p>Aliquam hendrerit efficitur arcu ut suscipit. Etiam vel lacus at enim malesuada vulputate a at nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc interdum mollis ultrices. In eget commodo justo, in vulputate eros. In et congue enim. Etiam eleifend dolor ac lectus faucibus aliquet. Vivamus luctus libero elit, id porttitor neque scelerisque id.</p>
<p>Cras libero dolor, malesuada non porttitor at, viverra at ligula. Suspendisse eget dapibus nisl, at vulputate nisi. Vestibulum purus nisi, viverra vel tortor eget, imperdiet facilisis lectus. Maecenas vestibulum elit sit amet nibh ultricies hendrerit. Mauris convallis, purus eu pharetra viverra, lectus lacus accumsan diam, euismod sollicitudin libero eros et quam. Praesent posuere ante et erat commodo, quis rutrum odio elementum. Aliquam tempus vestibulum mi ut sollicitudin.</p>
<h2 id="about">About</h2>
<p>Pellentesque imperdiet, massa at ultricies venenatis, eros lorem ultricies felis, in dapibus est magna ut augue. Cras efficitur mi at turpis placerat pulvinar. Sed bibendum dapibus nibh vitae vulputate. In eleifend orci vitae augue tincidunt, in posuere erat gravida. Vivamus in tortor feugiat, auctor mi sed, vehicula risus. Nulla facilisi. Phasellus mi dui, scelerisque ac nulla eu, viverra vehicula velit.</p>
<p>Cras libero dolor, malesuada non porttitor at, viverra at ligula. Suspendisse eget dapibus nisl, at vulputate nisi. Vestibulum purus nisi, viverra vel tortor eget, imperdiet facilisis lectus. Maecenas vestibulum elit sit amet nibh ultricies hendrerit. Mauris convallis, purus eu pharetra viverra, lectus lacus accumsan diam, euismod sollicitudin libero eros et quam. Praesent posuere ante et erat commodo, quis rutrum odio elementum. Aliquam tempus vestibulum mi ut sollicitudin.</p>
<p>Aliquam hendrerit efficitur arcu ut suscipit. Etiam vel lacus at enim malesuada vulputate a at nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc interdum mollis ultrices. In eget commodo justo, in vulputate eros. In et congue enim. Etiam eleifend dolor ac lectus faucibus aliquet. Vivamus luctus libero elit, id porttitor neque scelerisque id.</p>
</main>
/*
* Made by Erik Terwan
* 24th of November 2015
* MIT License
*
*
* If you are thinking of using this in
* production code, beware of the browser
* prefixes.
*/
body
{
margin: 0;
padding: 0;
/* make it look decent enough */
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
}
main {
width: calc(100% - 240px);
max-width: 680px;
margin: 100px auto;
}
p {
font-size: 18px;
line-height: 28px;
}
* {
scroll-behavior: smooth;
}
/* Menu code starts here */
#menuToggle
{
display: block;
/* You can also use relative/absolute here if you want to stay on the top */
position: fixed;
top: 50px;
left: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
#menuToggle a:hover
{
color: tomato;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /* hide this */
z-index: 2; /* and place it over the hamburger */
-webkit-touch-callout: none;
}
/*
* Just a quick hamburger
*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*
* Transform all the slices of hamburger
* into a crossmark.
*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*
* But let's hide the middle one.
*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*
* Ohyeah and the last one should go the other direction
*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
transform: rotate(-45deg) translate(0, -1px);
}
/*
* Make this absolute positioned
* at the top left of the screen
*/
#menu
{
position: absolute;
max-width: 400px;
width: 100vw;
max-height: 100vh;
margin: -100px 0 0 -50px;
padding: 50px;
padding-top: 125px;
box-sizing: border-box;
overflow-y: auto;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
#menu li label
{
cursor: pointer;
}
/*
* And let's slide it in from the left
*/
#menuToggle input:checked ~ ul
{
transform: none;
}
// Nothing to see here, only html + css.
Also see: Tab Triggers