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>Non-Table Mark-up Using ARIA Table Roles</h1>
<p>
If it is impossible to use table mark-up for some reason, ARIA roles can insert the semantic structure for screen readers. Some important notes:
</p>
<ul>
<li>You must still create valid nesting structures with an overall wrapper, a wrapper for each visible row, and a wrapper for each data cell and column header.</li>
<li>The author must still style the layout as browsers will not assign styles based on ARIA roles. I use CSS Grid below.</li>
<li>If you can edit elements to include the needed ARIA roles, then it may be more efficient to re-write the original elements as table elements instead.</li>
<li>Using native table elements will also reduce compatbility issues across browsers, assistive technology, and versions.</li>
</ul>
<h2>Standard ARIA Table</h2>
<p>
This uses CSS Grid to approximate the layout that comes with native tables. This works back to IE11 (with JAWS as well) but will require changing the column widths on a per-table basis to prevent overlap. Avoid hiding the text when it overflows.
</p>
<div role="table" class="table" aria-labelledby="Caption01">
<div class="caption" id="Caption01">Books I May or May Not Have Read</div>
<div role="row">
<div role="columnheader">Author</div>
<div role="columnheader">Title</div>
<div role="columnheader">Year</div>
<div role="columnheader">ISBN-13</div>
<div role="columnheader">ISBN-10</div>
</div>
<div role="row">
<div role="cell">Miguel De Cervantes</div>
<div role="cell">The Ingenious Gentleman Don Quixote of La Mancha</div>
<div role="cell">1605</div>
<div role="cell">9783125798502</div>
<div role="cell">3125798507</div>
</div>
<div role="row">
<div role="cell">Mary Shelley</div>
<div role="cell">Frankenstein; or, The Modern Prometheus</div>
<div role="cell">1818</div>
<div role="cell">9781530278442</div>
<div role="cell">1530278449</div>
</div>
<div role="row">
<div role="cell">Herman Melville</div>
<div role="cell">Moby-Dick; or, The Whale</div>
<div role="cell">1851</div>
<div role="cell">9781530697908</div>
<div role="cell">1530697905</div>
</div>
<div role="row">
<div role="cell">Emma Dorothy Eliza Nevitte Southworth</div>
<div role="cell">The Hidden Hand</div>
<div role="cell">1888</div>
<div role="cell">9780813512969</div>
<div role="cell">0813512964</div>
</div>
<div role="row">
<div role="cell">F. Scott Fitzgerald</div>
<div role="cell">The Great Gatsby</div>
<div role="cell">1925</div>
<div role="cell">9780743273565</div>
<div role="cell">0743273567</div>
</div>
<div role="row">
<div role="cell">George Orwell</div>
<div role="cell">Nineteen Eighty-Four</div>
<div role="cell">1948</div>
<div role="cell">9780451524935</div>
<div role="cell">0451524934</div>
</div>
</div>
<h2>ARIA Table with a Spanning Header</h2>
<p>
HTML tables natively support associating spanning headers with their associated rows and/or columns. This feature is not supported by other elements, so ARIA must be used to mimic some of these features.
</p>
<ul>
<li>There is no replacement ARIA to create a relationship between spanning column headers (nor rows).</li>
<li>The <code><div></code> element does not allow the <code>headers</code> attribute that is a feature of <code><td></code>.</li>
<li>JAWS/IE11 will announce the spanning header with the first column it spans only.</li>
<li>Adding <code>aria-labelledby</code> to each header-spanned cell results in double announcing in JAWS/IE11.</li>
<li>You must add <code>aria-labelledby</code> to each <code><th></code> replacement that is not in the same starting column as the spanning <code><th></code> replacement, and its value must match the <code>id</code> of the spanning <code><th></code> replacement for JAWS/IE11 to read the fake header spans.</li>
</ul>
<div role="table" class="table" aria-labelledby="Caption02">
<div class="caption" id="Caption02">(Column Spans) Books I May or May Not Have Read</div>
<div role="row">
<div role="columnheader"></div>
<div role="columnheader"></div>
<div role="columnheader"></div>
<div role="columnheader" data-colspan="2" id="SpanHeader">ISBN Numbers</div>
</div>
<div role="row">
<div role="columnheader">Author</div>
<div role="columnheader">Title</div>
<div role="columnheader">Year</div>
<div role="columnheader">13</div>
<div role="columnheader" aria-labelledby="SpanHeader">10</div>
</div>
<div role="row">
<div role="cell">Miguel De Cervantes</div>
<div role="cell">The Ingenious Gentleman Don Quixote of La Mancha</div>
<div role="cell">1605</div>
<div role="cell">9783125798502</div>
<div role="cell">3125798507</div>
</div>
<div role="row">
<div role="cell">Mary Shelley</div>
<div role="cell">Frankenstein; or, The Modern Prometheus</div>
<div role="cell">1818</div>
<div role="cell">9781530278442</div>
<div role="cell">1530278449</div>
</div>
<div role="row">
<div role="cell">Herman Melville</div>
<div role="cell">Moby-Dick; or, The Whale</div>
<div role="cell">1851</div>
<div role="cell">9781530697908</div>
<div role="cell">1530697905</div>
</div>
<div role="row">
<div role="cell">Emma Dorothy Eliza Nevitte Southworth</div>
<div role="cell">The Hidden Hand</div>
<div role="cell">1888</div>
<div role="cell">9780813512969</div>
<div role="cell">0813512964</div>
</div>
<div role="row">
<div role="cell">F. Scott Fitzgerald</div>
<div role="cell">The Great Gatsby</div>
<div role="cell">1925</div>
<div role="cell">9780743273565</div>
<div role="cell">0743273567</div>
</div>
<div role="row">
<div role="cell">George Orwell</div>
<div role="cell">Nineteen Eighty-Four</div>
<div role="cell">1948</div>
<div role="cell">9780451524935</div>
<div role="cell">0451524934</div>
</div>
</div>
<h2>Standard ARIA Table Made from List</h2>
<p>
You may assume that each list will have a column header and then all the data in that column. That is not how it works, so tis may seem a bit counter-intuitive.
</p>
<ul>
<li>Each row must be its own list.</li>
<li>It won't live in another list item, though they all live under a single list item.</li>
<li>The first list makes up the column headers.</li>
<li>If each list represented a single column then you would have effectively rotated the table 90° to put its axis on the side instead of across the top.</li>
<li>This approach works in JAWS/IE11, but not other screen readers, so there is a chance over time JAWS support will wane.</li>
</ul>
<ul role="table" class="table" aria-labelledby="Caption03">
<li class="caption" id="Caption03" role="presentation">(From List) Books I May or May Not Have Read</li>
<li role="presentation">
<ol role="row">
<li role="columnheader">Author</li>
<li role="columnheader">Title</li>
<li role="columnheader">Year</li>
<li role="columnheader">ISBN-13</li>
<li role="columnheader">ISBN-10</li>
</ol>
<ol role="row">
<li role="cell">Miguel De Cervantes</li>
<li role="cell">The Ingenious Gentleman Don Quixote of La Mancha</li>
<li role="cell">1605</li>
<li role="cell">9783125798502</li>
<li role="cell">3125798507</li>
</ol>
<ol role="row">
<li role="cell">Mary Shelley</li>
<li role="cell">Frankenstein; or, The Modern Prometheus</li>
<li role="cell">1818</li>
<li role="cell">9781530278442</li>
<li role="cell">1530278449</li>
</ol>
<ol role="row">
<li role="cell">Herman Melville</li>
<li role="cell">Moby-Dick; or, The Whale</li>
<li role="cell">1851</li>
<li role="cell">9781530697908</li>
<li role="cell">1530697905</li>
</ol>
<ol role="row">
<li role="cell">Emma Dorothy Eliza Nevitte Southworth</li>
<li role="cell">The Hidden Hand</li>
<li role="cell">1888</li>
<li role="cell">9780813512969</li>
<li role="cell">0813512964</li>
</ol>
<ol role="row">
<li role="cell">F. Scott Fitzgerald</li>
<li role="cell">The Great Gatsby</li>
<li role="cell">1925</li>
<li role="cell">9780743273565</li>
<li role="cell">0743273567</li>
</ol>
<ol role="row">
<li role="cell">George Orwell</li>
<li role="cell">Nineteen Eighty-Four</li>
<li role="cell">1948</li>
<li role="cell">9780451524935</li>
<li role="cell">0451524934</li>
</ol>
</li>
</ul>
<h2>Standard ARIA Table with No Styles</h2>
<p>
This demonstrates how the semenatics are assigned even when styles are not. You can still navigate the table with the JAWS table navigation keyboard commands regardless of its appearance. This replacement table is coded using <code><div></code>s.
</p>
<div role="table" aria-labelledby="Caption04">
<div class="caption" id="Caption04">(No Styles) Books I May or May Not Have Read</div>
<div role="row">
<div role="columnheader">Author</div>
<div role="columnheader">Title</div>
<div role="columnheader">Year</div>
<div role="columnheader">ISBN-13</div>
<div role="columnheader">ISBN-10</div>
</div>
<div role="row">
<div role="cell">Miguel De Cervantes</div>
<div role="cell">The Ingenious Gentleman Don Quixote of La Mancha</div>
<div role="cell">1605</div>
<div role="cell">9783125798502</div>
<div role="cell">3125798507</div>
</div>
<div role="row">
<div role="cell">Mary Shelley</div>
<div role="cell">Frankenstein; or, The Modern Prometheus</div>
<div role="cell">1818</div>
<div role="cell">9781530278442</div>
<div role="cell">1530278449</div>
</div>
<div role="row">
<div role="cell">Herman Melville</div>
<div role="cell">Moby-Dick; or, The Whale</div>
<div role="cell">1851</div>
<div role="cell">9781530697908</div>
<div role="cell">1530697905</div>
</div>
<div role="row">
<div role="cell">Emma Dorothy Eliza Nevitte Southworth</div>
<div role="cell">The Hidden Hand</div>
<div role="cell">1888</div>
<div role="cell">9780813512969</div>
<div role="cell">0813512964</div>
</div>
<div role="row">
<div role="cell">F. Scott Fitzgerald</div>
<div role="cell">The Great Gatsby</div>
<div role="cell">1925</div>
<div role="cell">9780743273565</div>
<div role="cell">0743273567</div>
</div>
<div role="row">
<div role="cell">George Orwell</div>
<div role="cell">Nineteen Eighty-Four</div>
<div role="cell">1948</div>
<div role="cell">9780451524935</div>
<div role="cell">0451524934</div>
</div>
</div>
</main>
@import url("https://fonts.googleapis.com/css?family=Lato:400,400i,700");
body {
background-color: #eeeeee;
font-size: 100%;
color: #333;
font-family: Lato, Arial, sans-serif;
padding: 0;
margin: 0;
line-height: 1.4;
}
main {
display: block;
box-sizing: border-box;
width: auto;
padding: 1em 1vw;
margin: 1em 1vw;
color: #000;
}
ul.table, .table ol, .table li {
list-style-type: none;
margin: 0;
padding: 0;
}
.table {
margin: 1em 0;
border-collapse: collapse;
}
.table .caption {
text-align: left;
font-style: italic;
padding: 0.25em 0.5em 0.5em 0.5em;
}
.table *[role="columnheader"],
.table *[role="cell"] {
padding: 0.25em 0.5em 0.25em 1em;
vertical-align: text-top;
text-align: left;
text-indent: -0.5em;
}
.table *[role="columnheader"] {
vertical-align: bottom;
background-color: rgba(0, 0, 0, 0.75);
color: #fff;
font-weight: bold;
}
.table *[role="row"]:nth-child(n + 2) {
border-bottom: 0.01em solid rgba(0,0,0,.5);
}
.table *[role="cell"]:nth-of-type(2) {
font-style: italic;
}
.table *[role="columnheader"]:nth-of-type(3),
.table *[role="cell"]:nth-of-type(3),
.table *[role="columnheader"]:nth-of-type(4),
.table *[role="cell"]:nth-of-type(4),
.table *[role="columnheader"]:nth-of-type(5),
.table *[role="cell"]:nth-of-type(5) {
text-align: right;
}
/* CSS Grid Layout */
.table *[role="row"] {
display: -ms-grid;
display: grid;
-ms-grid-columns: 20% 30% 10% 20% 20%;
grid-template-columns: 20% 30% 10% 20% 20%;
}
.table *[role="columnheader"]:nth-child(1),
.table *[role="cell"]:nth-child(1) {
-ms-grid-column: 1;
}
.table *[role="columnheader"]:nth-child(2),
.table *[role="cell"]:nth-child(2) {
-ms-grid-column: 2;
}
.table *[role="columnheader"]:nth-child(3),
.table *[role="cell"]:nth-child(3) {
-ms-grid-column: 3;
}
.table *[role="columnheader"]:nth-child(4),
.table *[role="cell"]:nth-child(4) {
-ms-grid-column: 4;
}
.table *[role="columnheader"]:nth-child(5),
.table *[role="cell"]:nth-child(5) {
-ms-grid-column: 5;
}
.table *[role="columnheader"]:nth-child(4)[data-colspan="2"] {
background-color: rgba(0,0,0,.7);
text-align: center;
grid-column: 4 / span 2;
-ms-grid-column-span: 2;
}
Also see: Tab Triggers