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, Take 2</h1>
<p>Another 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" class="link-main" aria-describedby="note-1"><cite>The Correspondent</cite>.</a> <span id="note-1" role="complementary" class="link-note article">The Sarah Kendzior article I was reading is also recommended, separate from the web design.</span> Each link in the main text has an associated marginalia note, describing the linked resource. </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" class="link-main" aria-describedby="note-2"><code>aria-hidden</code> attribute</a> <span id="note-2" role="complementary" class="link-note book">The official definition of <code>aria-hidden</code> warns against overuse.</span> 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>
I included both the link text and the note inside a single, always displayed link in my <a href="https://codepen.io/AmeliaBR/pen/QGNPWb?editors=1100" target="_blank" class="link-main" aria-describedby="note-5">original pen</a>. <span id="note-5" role="complementary" class="link-note picture">The original should look mostly the same on wide screens, but it has additional hover effects I couldn't re-create here.</span> In this version, the note is a separate element inserted after the link. Both versions use transforms to slide the note into view on narrow screens when it is touched/hovered. The main reason for the markup change was to allow the note to be tapped into view on a mobile touch screen, without activating the link. On wide screens, a transparent overlay (that is actually a psuedo-element for the link) is used to make the top of each note clickable. I'd also be interested in feedback from regular touchscreen users on whether this improves usability—and also feedback from desktop & mouse users on whether it noticeably detracts from usability!
</p>
<p>
Another usability question: on narrow screens, I'm currently letting the off-screen notes create a horizontal scrollbar. Easy to prevent with hidden overflow, but should I? Is it nice to be able to swipe the screen and see all the notes at once? Or does that interfere with browser/OS swipe gestures?
<p>
<p>For screen-readers, the note has a <a href="https://w3c.github.io/aria/aria/aria.html#complementary" class="link-main" aria-describedby="note-6">role of <code>complementary</code></a>. <span id="note-6" role="complementary" class="link-note article">A complementary item in ARIA should be exposed similar to an HTML <code><aside></code> element, but try not to get mixed up, like I originally did, and use <code>aside</code> as the role name!</span> Since it is no longer actually part of the link text, I've indicated the connection via the <code>aria-describedby</code> attribute. 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.
</p>
<p>
One extra benefit of this structure is reduced markup: the inline link is just an <code><a></code> element, there is no extra <code><span></code>. You could probably even drop the class on the link; it is only used to trigger the creation of the transparent touch target that hovers over the note in the margin. I don't think it would be a big problem if a target was created even for links without notes.
</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" class="link-main" aria-describedby="note-3">nulla consequatur</a> <span id="note-3" role="complementary" class="link-note article">No consequences? That was disputed in this article.</span> autem ex ducimus aperiam a repudiandae iusto perspiciatis odit obcaecati culpa, in voluptas. Voluptate, provident fuga.</p>
<p>Ea accusamus, <a href="#b" class="link-main" aria-describedby="note-4">blanditiis rerum</a> <span id="note-4" role="complementary" class="link-note book">An entire chapter on the blandest rerum of all.</span> 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 / 100% 1px no-repeat;
}
a.link-main::after,
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-main::after{
/* positioned above the icon-line in the note,
as a click-grabber */
content: "";
z-index: 100;
height: 1.5rem;
margin-bottom: -1.5rem;
left: -1rem;
border-radius: 0.75rem;
background: transparent;
//background: green;
}
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-note::after,
a:focus + .link-note::after {
background-color: currentColor;
}
a:hover + .link-note::before,
a:focus + .link-note::before {
color: #fec; /* provide contrast if emoji aren't substituted */
text-shadow: 0.2em 0.15em 0 #004;
}
@media (max-width: 40em) {
body {
padding-right: 0.5em;
margin: 0;
}
a + .link-note {
z-index: 200;
}
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.link-main::after {
content: normal;
/* don't try to have a touch target over top of a moving note */
}
.link-note:hover,
a:focus + .link-note {
transition-timing-function: ease-in;
transform: translateX(-10rem);
color: #004;
z-index: auto;
}
}
Also see: Tab Triggers