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.
<h2>What is this about?</h2>
<p>This snippet intends to demonstrate the issue with having identical styling for "checked" and "focused" styles, when there are no other visual cues. This is a rather common issue when checkboxes are restyled to not display the box itself.</p>
<h2>How to use this?</h2>
<p>Press the <kbd>Tab</kbd> key until the focus lands on the placeholder link. Now pay close attention, and press on <kbd>Tab</kbd> again. Unless you have user-defined styles in your browser, you should see... nothing.</p>
<p>Now press <kbd>Tab</kbd> again. "choice 2" in the first set should be green.</p>
<a href="#">This placeholder link is here only to provide a first tab stop</a>
<fieldset id="same">
<legend>Focus and active states look the same</legend>
<label for="1.1"><input id="1.1" type=checkbox checked /><span>choice 1</span></label>
<label for="1.2"><input id="1.2" type=checkbox /><span>choice 2</span></label>
<label for="1.3"><input id="1.3" type=checkbox /><span>choice 3</span></label>
</fieldset>
<p>Go on tabbing, until you reach the second set. You should see that the element that has focus appears in bold red.</p>
<fieldset id="different">
<legend>Focus and active states look different</legend>
<label for="2.1"><input id="2.1" type=checkbox checked /><span>choice 1</span></label>
<label for="2.2"><input id="2.2" type=checkbox /><span>choice 2</span></label>
<label for="2.3"><input id="2.3" type=checkbox /><span>choice 3</span></label>
</fieldset>
<h2>Explanations</h2>
<p>In the first set of checkboxes, "checked" and "focus" states are identical in style. If the checkbox is already checked ('Choice 1' is, here), then when it gets focus, there's no visible difference.</p>
<p>By contrast, in the second set, checkboxes are styled differently when they are checked and when they have focus. When the focus lands on 'Choice 1', there's a clear visual cue.</p>
<h2>Why bother?</h2>
<p>It's an accessibility issue. Users who navigate with the keyboard only (or similar switch-based input devices), and can see the screen, really need to know the current position of the focus, at any time. If "checked" and "focus" styles are identical, then it's like having no focused state at all.</p>
<h2>How to do it better?</h2>
<p>Best option is to keep a visible focus ring for every focusable element. That way, you lessen the risk that user-side styling (like high-contrast modes) jeopardizes the user's ability to know the current cursor position.</p>
<h2>Questions?</h2>
<p>Get in touch: <a href="https://twitter.com/OlivierNourry">I'm @OlivierNourry on Twitter</a></p>
label {
display: block;
}
input[type=checkbox] {
position:absolute;
left:-100000px;
}
input:checked + span {
color: green;
}
input:focus + span {
color: green;
}
#different input:focus + span {
color: red;
font-weight:bold;
}
/* debug
input:checked + span:after {
content: " - active";
}
input:focus + span:after {
content: " - focused";
}
}
*/
Also see: Tab Triggers