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.
<h1>Table of Contents</h1>
<div id="table-of-contents"></div>
<h2>Cat O'Nine Tails</h2>
<p>Cat o'nine tails Pieces of Eight swab carouser tackle. Pink hornswaggle gabion Sea Legs Davy Jones' Locker.</p>
<p>Hang the jib Nelsons folly trysail ahoy prow. Transom strike colors scallywag aft league.</p>
<h3 id="the-brig">The Brig</h3>
<p>Dead men tell no tales topmast Sail ho Davy Jones' Locker chantey. Wherry fluke pillage rope's end brig.</p>
<h4>Privateer</h4>
<p>Tack topgallant draft line flogging. Maroon overhaul grog blossom Privateer main sheet.</p>
<p>Provost me cackle fruit Corsair Cat o'nine tails. Hempen halter Davy Jones' Locker clipper bring a spring upon her cable run a shot across the bow.</p>
<h2>Ahoy</h2>
<p>Booty squiffy wench overhaul ahoy. Parrel Pirate Round long clothes long boat come about.</p>
<p>Squiffy jack crow's nest bilged on her anchor barkadeer. Snow bucko mizzen six pounders tack.</p>
<h3 id="man-of-war">Man-of-War</h3>
<p>Lee lad nipperkin avast pressgang. Man-of-war prow ho Sail ho landlubber or just lubber.</p>
<p>Ho no prey, no pay fire ship salmagundi capstan. Hail-shot doubloon wherry loaded to the gunwalls cutlass.</p>
<h2 id="corsair">Corsair</h2>
<p>Corsair chantey hardtack ahoy snow. Maroon cog galleon topmast tender.</p>
<h3 id="shiver-me-timbers">Shiver Me Timbers</h3>
<p>Galleon nipper Shiver me timbers lugger Nelsons folly. Wench ballast scurvy man-of-war hearties.</p>
<p>Poop deck clap of thunder Corsair grog hornswaggle. Dead men tell no tales brigantine long clothes black spot sutler.</p>
<h4 id="scurvy-dog">Scurvy Dog</h4>
<p>Jury mast Letter of Marque boatswain scurvy sheet. Jolly boat plunder jack starboard Pirate Round.</p>
<p>Holystone bring a spring upon her cable grog blossom deadlights league. Lanyard gabion reef sails booty gaff.</p>
<h4>Sea Legs</h4>
<p>Sea Legs to go on account skysail Yellow Jack heave down. Spanker heave down yawl starboard barque.</p>
<p>To go on account hulk swing the lead heave to tack. Fore fire in the hole prow run a rig Jack Ketch.</p>
<h2 id="quarterdeck">On the Quarterdeck</h2>
<p>Tack chase red ensign league pinnace. Holystone quarterdeck me boatswain rope's end.</p>
<p>Sink me lanyard Pieces of Eight starboard black spot. Blimey heave down crimp mutiny matey.</p>
<h3 id="jolly-roger">Jolly Roger</h3>
<p>Belay piracy come about jolly boat transom. Heave to gally snow Arr wherry.</p>
<p>Sutler Davy Jones' Locker ahoy walk the plank lugger. Jolly Roger matey hornswaggle Privateer marooned.</p>
<h2>Davy Jones' Locker</h2>
<p>Davy Jones' Locker jib trysail bowsprit heave down. Transom square-rigged clipper Jack Ketch chandler.</p>
<p>Square-rigged yawl execution dock sloop American Main. Six pounders red ensign lugger heave to dead men tell no tales.</p>
<h3 id="sloop">Sloop</h3>
<p>Spanker rutters Arr sloop pinnace. List crimp swab Blimey grog.</p>
<p>Shiver me timbers hulk black jack Pirate Round clap of thunder. Scuppers six pounders carouser spirits jib.</p>
<footer>
<p>
<small>Text provided by <a href="https://pirateipsum.me">Pirate Ipsum</a>. ☠️</small>
</p>
</footer>
*, *::before {
box-sizing: border-box;
}
:root {
scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
:root {
scroll-behavior: auto;
}
}
body {
width: 88%;
max-width: 34rem;
margin: 1rem auto;
line-height: 1.5;
font-family: Georgia, 'Times New Roman', Times, serif;
}
:target::before {
content: '👉 ';
}
;(function () {
// Opt into strict mode
'use strict';
//
// Variables
//
// Get the #table-of-contents element
const tableOfContents = document.querySelector('#table-of-contents');
// Get all h2 elements as an array
const headings = [...document.querySelectorAll('h2')];
//
// Functions
//
/**
* Create a skip link for a heading
* @param {HTMLHeadingElement} heading The heading
* @returns {String} An HTML string
*/
function createSkipLink (heading) {
// If the heading doesn't have an ID, create one
if (!heading.id) {
heading.id = heading.textContent.replace(/\s+/g, '-');
}
// Return the HTML string
return `
<li>
<a href="#${heading.id}">
${heading.textContent}
</a>
</li>
`;
}
/**
* Render the table of contents
*/
function render () {
// If there aren't any headings, just bail
if (headings.length < 1) return;
// Build and insert the table of contents
tableOfContents.innerHTML = `
<ol>
${headings.map(createSkipLink).join('')}
</ol>
`;
}
//
// Inits & Event Listeners
//
// Render the table of contents
render();
})();
Also see: Tab Triggers