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

Auto Save

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

              
                <h1>Data Table Accessibility Tests 2024</h1>

<p>This Codepen presents four types of tables I've tested to understand the state of data table accessibility in 2024. </p>

<ul>
  <li> <code>table</code> as it should be </li>
  <li> <code>table</code> with <code>display: grid</code> </li>
  <li> <code>div</code> with <code>role="table"</code></li>
  <li> <code>div</code> with <code>role="grid"</code></li>
</ul>

<p>Please read <a href="https://zellwk.com/blog/data-table-accessibility-2024">this article</a> for more information about the test and my findings.</p>


<h2>Normal Table</h2>

  <table>
    <thead style="">
      <tr class="bg-yellow-900 text-white">
        <th>Name</th>
        <th>Number of Shares</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <th class="bg-orange-100 col-span-2" colspan="2"> SGD </th>
      </tr>
      <tr>
        <td>Alexander</td>
        <td>500</td>
      </tr>
      <tr>
        <td>Perseus</td>
        <td>500</td>
      </tr>
    </tbody>

    <tbody>
      <tr>
        <th class="bg-orange-100 col-span-2" colspan="2"> USD </th>
      </tr>
      <tr>
        <td>Alexander</td>
        <td>500</td>
      </tr>
      <tr>
        <td>Perseus</td>
        <td>500</td>
      </tr>
    </tbody>
  </table>

  <h2>Normal Table with Display Grid</h2>

  <table class="Grid grid-cols-[1fr_1fr_auto]">
    <thead>
      <tr class="bg-yellow-900 text-white">
        <th>Name</th>
        <th>Number of Shares</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <th class="bg-orange-100 col-span-2" colspan="2"> SGD </th>
      </tr>
      <tr>
        <td>Alexander</td>
        <td>500</td>
      </tr>
      <tr>
        <td>Perseus</td>
        <td>500</td>
      </tr>
    </tbody>

    <tbody>
      <tr>
        <th class="bg-orange-100 col-span-2" colspan="2"> USD </th>
      </tr>
      <tr>
        <td>Alexander</td>
        <td>500</td>
      </tr>
      <tr>
        <td>Perseus</td>
        <td>500</td>
      </tr>
    </tbody>
  </table>

  <h2>Role=table (Without rowgroup)</h2>

  <div role="table" class="Grid grid-cols-[repeat(2,_1fr)_auto]">
    <div role="row" class="bg-yellow-900 text-white">
      <div role="columnheader">Name</div>
      <div role="columnheader">Number of Shares</div>
    </div>
    <div role="row">
      <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
        SGD
      </div>
    </div>
    <div role="row">
      <div role="cell">Alexander</div>
      <div role="cell">500</div>
    </div>
    <div role="row">
      <div role="cell">Perseus</div>
      <div role="cell">500</div>
    </div>
    <div role="row">
      <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
        USD
      </div>
    </div>
    <div role="row">
      <div role="cell">Alexander</div>
      <div role="cell">500</div>
    </div>
    <div role="row">
      <div role="cell">Perseus</div>
      <div role="cell">500</div>
    </div>
  </div>

  <h2>Role=table (With rowgroup)</h2>

  <div role="table" class="Grid grid-cols-[repeat(2,_1fr)_auto]">
    <div role="rowgroup">
      <div role="row" class="bg-yellow-900 text-white">
        <div role="columnheader">Name</div>
        <div role="columnheader">Number of Shares</div>
      </div>
    </div>

    <div role="rowgroup">
      <div role="row">
        <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
          SGD
        </div>
      </div>
      <div role="row">
        <div role="cell">Alexander</div>
        <div role="cell">500</div>
      </div>
      <div role="row">
        <div role="cell">Perseus</div>
        <div role="cell">500</div>
      </div>
    </div>
    <div role="rowgroup">
      <div role="row">
        <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
          USD
        </div>
      </div>
      <div role="row">
        <div role="cell">Alexander</div>
        <div role="cell">500</div>
      </div>
      <div role="row">
        <div role="cell">Perseus</div>
        <div role="cell">500</div>
      </div>
    </div>
  </div>

  <h2>Role=grid (Without rowgroup)</h2>

  <div role="grid" class="Grid grid-cols-[repeat(2,_1fr)_auto]">
    <div role="row" class="bg-yellow-900 text-white">
      <div role="columnheader">Name</div>
      <div role="columnheader">Number of Shares</div>
    </div>

    <div role="row">
      <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
        SGD
      </div>
    </div>
    <div role="row">
      <div role="gridcell">Alexander</div>
      <div role="gridcell">500</div>
    </div>
    <div role="row">
      <div role="gridcell">Perseus</div>
      <div role="gridcell">500</div>
    </div>
    <div role="row">
      <div role="rowheader" class="bg-orange-100 col-span-2" aria-colspan="2">
        USD
      </div>
    </div>
    <div role="row">
      <div role="gridcell">Alexander</div>
      <div role="gridcell">500</div>
    </div>
    <div role="row">
      <div role="gridcell">Perseus</div>
      <div role="gridcell">500</div>
    </div>
  </div>

              
            
!

CSS

              
                // Basic table styles
table {
  width: 100%;
  border-collapse: collapse;

  th:not([scope='row']) {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
  }

  th[scope='row'] {
    border-right: 1px solid var(--border-color);
  }

  th,
  td {
    text-align: left;
    padding: 0.375rem 0.5rem;
  }

  tr:nth-child(2n + 3) {
    background-color: var(--alt-row-color);
  }
}

// Table with CSS Grid
// Grid Template Columns is a MUST-PROVIDE property
:where(.Grid:is([role='table'], [role='grid'], table)) {
  display: grid;
  width: 100%;
}

// Thead, Tbody, Tfoot
:where(.Grid :is([role='rowgroup'], thead, tbody, tfoot)) {
  display: contents;
}

// Tr
:where(.Grid :is([role='row'], tr)) {
  grid-column: 1/-1;
  display: grid;
  grid-template-columns: subgrid;
  grid-template-rows: subgrid;

  &:nth-child(2n + 3) {
    background-color: var(--alt-row-color);
  }
}

// Th
:where(.Grid :is([role='columnheader'], th)) {
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  font-weight: bold;
}

// Th
// Maybe border-right is a bit too much
:where(.Grid :is([role='rowheader'], th[scope='row'])) {
  // border-right: 1px solid var(--border-color);
  font-weight: bold;
}

// Td
:where(.Grid :is([role='cell'], [role='gridcell'], td)) {
  display: grid;
  align-items: center;
}

// Both Th and Td
:where(
    .Grid
      :is(
        [role='columnheader'],
        [role='rowheader'],
        [role='cell'],
        [role='gridcell'],
        th,
        td
      )
  ) {
  padding: 0.25rem 0.5rem;
}

// Presentational purposes for this Codepen
// Just using !important to quickly override some Tailwind default values here 🙃
body {
  padding: 0.5rem;
}

h1 {
  font-weight: bold !important; 
  font-size: 3em !important;
  margin-bottom: 1rem ;
  margin-top: 1.5rem ;
}

h2 {
  font-weight: bold !important; 
  font-size: 2em !important;
  margin-bottom: 1rem ;
  margin-top: 1.5rem ;
}

p + *, 
* + p{
  margin-top: 1em !important;
}

a {
  color: blue;
  text-decoration: underline;
}

ul li {
  padding-left: 1rem;
  list-style: disc;
  list-style-position: inside;
}

code {
  background-color: #eaeaea;
}
              
            
!

JS

              
                
              
            
!
999px

Console