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.
- var sections = ['home', 'about', 'blog', 'contact']
nav#nav
button.nav-icon#nav-icon: span
ul
each item in sections
li: a(href='#' + item)=item
each section in sections
section(id=section)
h2=section
p Click on the hamburger menu icon to see the vertical popout menu. Scroll down to see how it adapts to the background color. The menu icon is created using pure CSS, and the color of the menu adapts to the background color of the page by setting mix-blend-mode to "difference". The toggle animation only needs a tiny bit of JavaScript. This demo was tested in the latest versions of Chrome, Firefox and Safari. It also works on mobile.
p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis nunc tellus, tempor vitae elit ac, ornare aliquet elit. Vivamus ac tincidunt est, vehicula semper neque. Aliquam eu velit mi. Mauris vel lorem sollicitudin, sollicitudin sem vel, pulvinar risus. Pellentesque ac pulvinar erat, quis aliquet lectus. Integer diam odio, auctor non ullamcorper scelerisque, imperdiet non est. Sed vulputate porttitor lorem, sit amet feugiat tortor pretium tristique. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultrices, lectus at ultricies tempus, massa lorem tincidunt urna, at porta nulla massa ac est. Aliquam commodo auctor tempus. In molestie nisl eget diam scelerisque, vel porta metus euismod. Praesent venenatis augue dignissim, vestibulum ex eget, vestibulum sem. In varius est leo. Nam id lobortis erat. Etiam et metus sit amet justo consectetur lacinia faucibus in elit. Aenean elit lorem, pellentesque sed pellentesque at, cursus eget felis.
@import url(https://fonts.googleapis.com/css?family=EB+Garamond|Work+Sans:700)
$color-light: #fff
$color-dark: #111
$font-primary: 'Adobe Garamond Pro', 'EB Garamond', Garamond, Georgia, 'Times New Roman', serif
$font-secondary: 'Work Sans', 'Arial Black', Gadget, sans-serif
*
box-sizing: border-box
padding: 0
margin: 0
border: 0
outline: 0
-webkit-font-smoothing: antialiased
html
font-size: 10px // rem reset
body
background: $color-dark
color: $color-light
font: #{2.6rem}/1.55 $font-primary
section
padding: 12.5%
width: 100%
&:nth-of-type(even)
background: $color-light
color: $color-dark
p
margin-bottom: 2.5em
a
color: inherit
text-decoration: none
h2
font: bold 2.8rem $font-secondary
text-transform: uppercase
letter-spacing: 5px
margin-bottom: 2em
nav
mix-blend-mode: difference
z-index: 100
ul
position: fixed
top: 60px
right: 5px
height: 100vh
visibility: hidden
pointer-events: none
list-style: none
width: 35px
li
font: bold 1.5rem $font-secondary
text-transform: uppercase
letter-spacing: 2px
padding: 0.75em 0
writing-mode: vertical-lr
&.active ul
visibility: visible
pointer-events: initial
transition-delay: 0.2s
// Inspired by: https://github.com/callmenick/Animating-Hamburger-Icons
.nav-icon
appearance: none
background: transparent
cursor: pointer
display: inline-block
height: 35px
position: fixed
top: 15px
right: 15px
transition: background 0.3s
width: 35px
span
position: absolute
top: 15px
left: 5px
background: $color-light
display: block
height: 3px
right: 5px
transition: transform 0.3s
&:before,
&:after
width: 100%
height: 3px
background: $color-light
content: ''
display: block
left: 0
position: absolute
&:before
top: -8px
&:after
bottom: -8px
.active & span
transform: rotate(90deg)
var nav = document.getElementById('nav');
var navlinks = nav.getElementsByTagName('a');
function toggleNav() {
(nav.classList.contains('active')) ? nav.classList.remove('active') : nav.classList.add('active');
}
document.getElementById('nav-icon').addEventListener('click', function(e) {
e.preventDefault();
toggleNav();
});
for(var i = 0; i < navlinks.length; i++) {
navlinks[i].addEventListener('click', function() {
toggleNav();
});
}
Also see: Tab Triggers