Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>Accessible Cart Tables?</h1>
  
  <p>
    Used in the post <cite><a href="https://adrianroselli.com/2022/01/accessible-cart-tables.html" target="_top">Accessible Cart Tables?</a></cite>.
  </p>

    <h2 id="T1">1. Just Spanning, No <code>headers</code> Attribute</h2>

    <table>
      <caption>Basic Shopping Cart</caption>
      <tr>
        <th>SKU</th>
        <th>Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
      <tr>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row">Sub-Total</th>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row">Shipping</th>
        <td>FREE</td>
      </tr>
      <tr>
        <th colspan="4" scope="row">Grand Total</th>
        <td>$ 1,525.00</td>
      </tr>
    </table>

    <h2 id="T2">2. Description Column with a <code>headers</code> Attribute</h2>

    <table>
      <caption>Description Column</caption>
      <tr>
        <th>SKU</th>
        <th id="dh1">Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
      <tr>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="dh1">Sub-Total</th>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="dh1">Shipping</th>
        <td>FREE</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="dh1">Grand Total</th>
        <td>$ 1,525.00</td>
      </tr>
    </table>

    <h2 id="T3">3. Blank Column with a <code>headers</code> Attribute</h2>

    <table class="blank">
      <caption>Blank Column</caption>
      <tr>
        <th id="bh1"><span class="visually-hidden">&nbsp;</span></th>
        <th>SKU</th>
        <th>Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
      <tr>
        <td></td>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td></td>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td></td>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="bh1">Sub-Total</th>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="bh1">Shipping</th>
        <td>FREE</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="bh1">Grand Total</th>
        <td>$ 1,525.00</td>
      </tr>
    </table>

    <h2 id="T4">4. Using a <code>headers</code> Attribute to Point to a Header It Does Not Span</h2>

    <table>
      <caption>Header It Does Not Span</caption>
      <tr>
        <th>SKU</th>
        <th>Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th id="sh1">Total</th>
      </tr>
      <tr>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="sh1">Sub-Total</th>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="sh1">Shipping</th>
        <td>FREE</td>
      </tr>
      <tr>
        <th colspan="4" scope="row" headers="sh1">Grand Total</th>
        <td>$ 1,525.00</td>
      </tr>
    </table>

  <h2 id="T5">5. Using <code>&lt;tfoot&gt;</code> and <code>aria-labelledby</code> for Last 3 Rows</h2>

    <table class="tfoot">
      <caption>A <code>&lt;tfoot&gt;</code> Effort</caption>
      <thead>
        <tr>
          <th>SKU</th>
          <th>Description</th>
          <th>Unit Price</th>
          <th>Quantity</th>
          <th id="tf1">Total</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>123456</td>
          <th>Pudding</th>
          <td>$1.00</td>
          <td>240</td>
          <td>$ 240.00</td>
        </tr>
        <tr>
          <td>987654</td>
          <th>A new set of steak knives</th>
          <td>$90.00</td>
          <td>½</td>
          <td>$ 45.00</td>
        </tr>
        <tr>
          <td>456789</td>
          <th>Sand</th>
          <td>$5.00</td>
          <td>200</td>
          <td>$ 1,000.00</td>
        </tr>
      </tbody>
      <tfoot >
        <tr>
          <th colspan="4" scope="row" aria-labelledby="tf1">Sub-Total</th>
          <td>$ 1,525.00</td>
        </tr>
        <tr>
          <th colspan="4" scope="row" aria-labelledby="tf1">Shipping</th>
          <td>FREE</td>
        </tr>
        <tr>
          <th colspan="4" scope="row" aria-labelledby="tf1">Grand Total</th>
          <td>$ 1,525.00</td>
        </tr>
      </tfoot>
    </table>
  
    <h2 id="T6">6. Restructure the Table</h2>

    <table>
      <caption>Restructured Shopping Cart</caption>
      <tr>
        <th>SKU</th>
        <th>Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th id="rh1">Sub-Total</th>
        <th>Total</th>
      </tr>
      <tr>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="rh1">Sub-Total</th>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="rh1">Shipping</th>
        <td>FREE</td>
      </tr>
      <tr>
        <th colspan="5" scope="row" headers="rh1">Grand Total</th>
        <td>$ 1,525.00</td>
      </tr>
    </table>
  
    <h2 id="T7">7. Dump All Spans</h2>

    <table class="despan">
      <caption>No Spans</caption>
      <tr>
        <th>SKU</th>
        <th>Description</th>
        <th>Unit Price</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
      <tr>
        <td>123456</td>
        <th>Pudding</th>
        <td>$1.00</td>
        <td>240</td>
        <td>$ 240.00</td>
      </tr>
      <tr>
        <td>987654</td>
        <th>A new set of steak knives</th>
        <td>$90.00</td>
        <td>½</td>
        <td>$ 45.00</td>
      </tr>
      <tr>
        <td>456789</td>
        <th>Sand</th>
        <td>$5.00</td>
        <td>200</td>
        <td>$ 1,000.00</td>
      </tr>
      <tr>
        <td></td>
        <th>Sub-Total</th>
        <td>$1,525.00</td>
        <td>1</td>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <td></td>
        <th>Shipping</th>
        <td>FREE</td>
        <td>1</td>
        <td>$ 1,525.00</td>
      </tr>
      <tr>
        <td></td>
        <th>Grand Total</th>
        <td></td>
        <td>1</td>
        <td>$ 1,525.00</td>
      </tr>
    </table>

</main>
              
            
!

CSS

              
                :root {
  --page-bg: #fff;
  --text-color: #000;
  --link-color: #00f;
  --vlink-color: #909;
  --flink-color: #00f;
}

/* @media screen and (prefers-color-scheme: dark) {
  :root {
    --page-bg: #000;
    --text-color: #fff;
    --link-color: #99f;
    --vlink-color: #c6c;
    --flink-color: #99f;
  }
} */

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  color: var(--text-color);
  background-color: var(--page-bg);
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
  margin: 0 2vw;
}

a, a:link {
  color: var(--link-color);
}

a:visited {
  color: var(--vlink-color);
}

a:focus, a:hover {
  text-decoration: none;
  color: var(--flink-color);
}

h1, h2 {
  line-height: 1;
}

/* Standard Tables */


table {
  margin: 1em 0;
  border-collapse: collapse;
}

caption {
  text-align: left;
  font-style: italic;
  padding: 0.25em 0.5em 0.5em 0.5em;
}

th,
td {
  padding: 0.25em 0.5em 0.25em 1em;
  vertical-align: text-top;
  text-align: left;
  text-indent: -0.5em;
  border: .01em solid #666;
  font-variant-numeric: tabular-nums;
}

td:empty {
  border: none;
}

th, thead tr:first-child th {
  vertical-align: bottom;
  background-color: #666;
  color: #fff;
}

thead th:nth-child(-n+2) {
  text-align: left;
}

tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.05);
}

tr:nth-child(odd) {
  background-color: rgba(255, 255, 255, 0.1);
}

tr td + th, tr:nth-last-child(-n + 3) th {
  background-color: transparent;
  color: initial;
  color: var(--text-color);
}

tr *:nth-last-child(1),
tr *:nth-last-child(2),
tr *:nth-last-child(3),
tr:nth-last-child(-n + 3) * {
  text-align: right;
  white-space: nowrap;
}

tr:nth-last-child(-n + 3) th, .despan tr:nth-last-child(-n + 3) td:empty {
  background-color: var(--page-bg);
  border: none;
}

.tfoot tbody tr:nth-last-child(-n + 3) th {
  background-color: transparent;
  text-align: unset;
  border: 0.01em solid #666;
}

.visually-hidden:not(:focus):not(:active) {
  position: absolute;
  overflow: hidden;
  clip: rect(0 0 0 0); 
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  white-space: nowrap; 
}

.blank tr:not(:nth-last-child(1)):not(:nth-last-child(2)):not(:nth-last-child(3)) *:first-child {
  padding: 0;
}
              
            
!

JS

              
                
              
            
!
999px

Console