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.
<p>
CSSWG issues
<a href="https://github.com/w3c/csswg-drafts/issues/865#issuecomment-350585274"><b>#865</b> (comment)</a>
and
<a href="https://github.com/w3c/csswg-drafts/issues/8286"><b>#8286</b></a>
</p>
<p>Mauris egestas lacinia lacinia. Cras in diam in nisl auctor suscipit. Fusce maximus quam nec ante commodo commodo. Maecenas condimentum arcu faucibus leo sollicitudin accumsan. Integer dictum tempor metus. In vitae porta nisl. Praesent ullamcorper faucibus mi, nec mattis libero auctor non. Duis volutpat leo non ornare aliquam. Curabitur non varius nisi. Aliquam blandit lorem dui, nec dictum ligula consequat ac. Quisque quis nunc dolor. In interdum purus nibh. Donec congue vulputate ornare.</p>
<div class="table-wrapper">
<table>
<tr>
<th>Donec faucibus</th>
<th>Proin ante</th>
<th>Mauris</th>
</tr>
<tr>
<td>lacinia sem vestibulum consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
<tr>
<td>lacinia sem vestibulum, consectetur lacus</td>
<td>phasellus eu semper nibh</td>
<td>nulla elementum viverra malesuada</td>
</tr>
</table>
</div>
<p>
<label>
<input class="scroll-toggle" type="checkbox" checked>
Horizontally scrollable
</label>
</p>
<p>Donec faucibus volutpat eros eget dignissim. Mauris lorem sem, dapibus sit amet molestie quis, ultricies sed erat. Fusce ut velit sit amet odio ornare tempor id non leo. Pellentesque euismod mattis metus, ac feugiat urna elementum non. Curabitur in dui vitae elit vulputate sagittis non at lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam ligula orci, rutrum in lorem eu, vehicula dictum diam. Duis semper at urna at mattis. Donec molestie auctor enim. Nullam sem est, egestas vel iaculis eleifend, ornare sed felis. Suspendisse potenti. Nunc a velit non tellus laoreet porta at id nibh. Proin vehicula bibendum lorem vel pretium.</p>
<p>Vivamus in lectus vel purus rhoncus ornare. Fusce pulvinar vehicula velit, vel hendrerit odio iaculis ut. Nunc malesuada est ac erat egestas mattis. Duis consequat ut mauris eget lobortis. In quam ipsum, ultrices at enim nec, hendrerit tincidunt magna. Cras nec neque ut neque facilisis consectetur. Nunc sit amet pulvinar justo, ac venenatis purus. Maecenas congue nisi sit amet nisi lacinia eleifend. Quisque convallis ex in mauris efficitur, in convallis risus rutrum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed cursus ex rutrum est tempor, in facilisis massa pulvinar. Proin sit amet consequat dolor, non consequat purus. Aenean pellentesque viverra libero, bibendum dictum arcu facilisis convallis. Fusce molestie tempus neque vitae sodales. Aliquam suscipit convallis ultricies. Proin volutpat magna orci, condimentum dictum nisl cursus ut. Quisque at lectus eget sem semper molestie eget id libero.</p>
<p>Proin sed ante ornare, lacinia sem vestibulum, consectetur lacus. Phasellus eu semper nibh, at lacinia sapien. Nulla elementum viverra malesuada. Aliquam sodales vestibulum auctor. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent maximus mi tincidunt, ultricies nisl sit amet, fermentum est. Etiam sollicitudin suscipit mauris, vitae euismod sem mollis sit amet. Donec in mattis justo.</p>
<p>Mauris egestas lacinia lacinia. Cras in diam in nisl auctor suscipit. Fusce maximus quam nec ante commodo commodo. Maecenas condimentum arcu faucibus leo sollicitudin accumsan. Integer dictum tempor metus. In vitae porta nisl. Praesent ullamcorper faucibus mi, nec mattis libero auctor non. Duis volutpat leo non ornare aliquam. Curabitur non varius nisi. Aliquam blandit lorem dui, nec dictum ligula consequat ac. Quisque quis nunc dolor. In interdum purus nibh. Donec congue vulputate ornare.</p>
.table-wrapper {
overflow-x: auto;
}
th {
position: -webkit-sticky;
position: sticky;
top: 0;
}
/* Unrelated */
html {
font: 110%/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
background: black;
}
body {
max-width: 35rem;
margin: 0 auto;
padding: 1rem;
background: white;
}
p {
margin: 1rem 0;
}
a {
color: blue;
}
a:not(:hover, :active, :focus) {
text-decoration-color: #00f7;
}
table {
line-height: 1.3;
background: white;
border-collapse: collapse;
outline: 1px solid white;
}
th, td {
padding: 0.5em 1em;
border: 1px solid black;
}
th {
text-align: start;
background: pink;
}
label {
display: flex;
align-items: center;
padding: 0.5em 0.5em;
border: 2px dashed blue;
border-radius: 0.3em;
}
label:hover {
background: hsl(240 100% 97%);
}
input {
margin-right: 0.5rem;
}
'use strict';
const toggle = document.querySelector('.scroll-toggle');
const wrapper = document.querySelector('.table-wrapper');
toggle.addEventListener('change', (event) => {
wrapper.classList.toggle('table-wrapper', event.target.checked);
});
Also see: Tab Triggers