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.
<main>
<h1>Links with Marginalia Notes</h1>
<p>
<strong>Correction (2 January 2016):</strong>
There is no <code>role="aside"</code>.
There is either the HTML <code><aside></code> element, or there is the ARIA <code>complementary</code> role. Since the HTML parser doesn't allow <code><aside></code> inside a paragraph, <code>complementary</code> it is!
</p>
<p>An attempt to create an accessible and more fully-responsive version of the link style used in <a href="https://thecorrespondent.com/5575/our-fate-was-sealed-long-before-november-8-and-not-because-the-elections-rigged/1576889402275-7591b019"><span class="link-main"><cite>The Correspondent</cite>.</span> <span role="complementary" class="link-note article">The Sarah Kendzior article I was reading is also recommended, separate from the web design.</span></a> Each link in the main text has an associated marginalia note, describing the linked resource. Hover styles highlight the note when you mouse over the text and vice versa.
</p>
<p>
In <cite>The Correspondent</cite>, there are actually two versions of the link in the markup: a regular link, displayed on narrower screens, or the linked marginalia note plus a plain text span for wider screens. The switch was done with media queries, however, and the <a href="https://w3c.github.io/aria/aria/aria.html#aria-hidden"><span class="link-main"><code>aria-hidden</code> attribute</span> <span role="complementary" class="link-note book">The official definition of <code>aria-hidden</code> warns against overuse.</span></a> that hides the duplication is never removed when the plain link is hidden with <code>display: none</code>. In addition to ensuring that a basic link is always accessible, I wanted to make the text of the note accessible, for screen reader users and also for mobile users.
</p>
<p>My markup therefore includes both the link text and the note inside a single, always displayed link, and uses transforms to slide it into view on narrow screens. The note has a role of <code>complementary</code>. I'd be interested in other suggestions for how best to indicate that this is a parenthetical note, interrupting the main text, while still being part of the link. I'd also be interested in feedback from regular touchscreen users on the narrow-screen design. <strong>Update:</strong> I created an <a href="https://codepen.io/AmeliaBR/pen/jyNjRP/" target="_blank">alternative version</a> of the pen that I hope is more mobile-friendly.
</p>
<p>Printer's latin follows with two more sample links (that don't actually link anywhere):</p>
<p>Magni optio, ab tempore id cum excepturi ea possimus distinctio dolore eos <a href="#a"><span class="link-main">nulla consequatur</span> <span role="complementary" class="link-note article">No consequences? That was disputed in this article.</span></a> autem ex ducimus aperiam a repudiandae iusto perspiciatis odit obcaecati culpa, in voluptas. Voluptate, provident fuga.</p>
<p>Ea accusamus, <a href="#b"><span class="link-main">blanditiis rerum</span> <span role="complementary" class="link-note book">An entire chapter on the blandest rerum of all.</span></a> voluptatum itaque quam suscipit nam, at ullam alias! Ea, eum quia beatae sequi quidem iure voluptas, qui totam, ullam, assumenda mollitia perferendis temporibus a! Quasi, tempora!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias, suscipit ea quod reiciendis eaque tenetur quis, numquam eum laborum ipsum ipsam similique obcaecati nulla dicta laboriosam omnis provident dolorem voluptates!</p>
</main>
body {
font-family: Georgia, sans-serif;
background-color: lightGray;
color: #004;
margin: 0.5rem;
padding-right: 10.5rem;
hyphens: auto;
}
main {
background-color: #fec;
padding: 0.5rem;
padding-right: 1rem;
max-width: 50em;
margin: auto;
}
p {
line-height: 1.4;
}
a {
color: inherit;
text-decoration: none;
background: gray;
background: linear-gradient(currentColor, currentColor) 0 1em / calc(100% - 0.2ch) 1px no-repeat;
}
a .link-note {
display: block;
float: right;
clear: right;
position: relative;
width: 11rem;
box-sizing: border-box;
margin-right: -12rem;
padding: 0.5rem;
margin-bottom: 0.5rem;
background: lightgray;
font-size: 90%;
line-height: 1.1;
}
a .link-note::before {
content: " ";
display: block;
margin: 0 0.2rem 0.2rem 0.6rem;
}
a .link-note.book::before {
content: "📖";
}
a .link-note.article::before {
content: "📰";
}
a .link-note.picture::before {
content: "🖼️";
}
a .link-note::after {
content: "";
display: block;
box-sizing: border-box;
width: 1.2rem; height: 1.2rem;
top: 0.25rem;
left: -0.5rem;
background-color: #fec;
border: solid 0.4rem lightgray;
border-radius: 50%;
position: absolute;
}
a:hover, a:focus {
color: #c21;
outline: none;
}
a:hover .link-main:hover, a:hover .link-note:hover {
color: #004;
}
a:hover .link-note:not(:hover)::after, a:focus .link-note::after {
background-color: currentColor;
}
@media (max-width: 40em) {
body {
padding-right: 0.5em;
margin: 0;
}
a .link-note {
margin-top: 1.4rem;
clear: none;
transition: transform 0.2s ease-out;
}
a .link-note::after {
top: 0;
left: -1rem;
width: 2.1em;
height: 2.1em;
border-width: 0.7em;
}
a:hover .link-note, a:focus .link-note {
transition-timing-function: ease-in;
transform: translateX(-10rem);
color: #004;
}
a:hover .link-note::after, a:focus .link-note::after {
background-color: currentColor;
}
}
Also see: Tab Triggers