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>Automated ARIA Role Assignment</h1>
<p>
  These examples are not responsive. They exist solely to demonstrate the function.
</p>

<h2>Standard Table</h2>
<div role="region" aria-labelledby="Cap" tabindex="0">
  <table>
    <caption id="Cap">Books I May or May Not Have Read</caption>
    <thead>
      <tr>
        <th>Author</th>
        <th>Title</th>
        <th>Year</th>
        <th>ISBN-13</th>
        <th>ISBN-10</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Miguel De Cervantes</td>
        <td>The Ingenious Gentleman Don Quixote of La Mancha</td>
        <td>1605</td>
        <td role="cell">9783125798502</td>
        <td>3125798507</td>
      </tr>
      <tr>
        <td>Mary Shelley</td>
        <td>Frankenstein; or, The Modern Prometheus</td>
        <td>1818</td>
        <td>9781530278442</td>
        <td>1530278449</td>
      </tr>
      <tr>
        <td>Herman Melville</td>
        <td>Moby-Dick; or, The Whale</td>
        <td>1851</td>
        <td>9781530697908</td>
        <td>1530697905</td>
      </tr>
      <tr>
        <td>Emma Dorothy Eliza Nevitte Southworth</td>
        <td>The Hidden Hand</td>
        <td>1888</td>
        <td>9780813512969</td>
        <td>0813512964</td>
      </tr>
      <tr>
        <td>F. Scott Fitzgerald</td>
        <td>The Great Gatsby</td>
        <td>1925</td>
        <td>9780743273565</td>
        <td>0743273567</td>
      </tr>
      <tr>
        <td>George Orwell</td>
        <td>Nineteen Eighty-Four</td>
        <td>1948</td>
        <td>9780451524935</td>
        <td>0451524934</td>
      </tr>
    </tbody>
  </table>
</div>

<h2>Complexity 1</h2>
<div role="region" aria-labelledby="Cap1" tabindex="0">
  <table>
    <caption id="Cap1">Contact Information</caption>
    <tr>
      <td></td>
      <th scope="col">Name</th>
      <th scope="col">Phone#</th>
      <th scope="col">Fax#</th>
      <th scope="col">City</th>
    </tr>
    <tr>
      <td>1.</td>
      <th scope="row">Joel Garner</th>
      <td>412-212-5421</td>
      <td>412-212-5400</td>
      <td>Pittsburgh</td>
    </tr>
    <tr>
      <td>2.</td>
      <th scope="row">Clive Lloyd</th>
      <td>410-306-1420</td>
      <td>410-306-5400</td>
      <td>Baltimore</td>
    </tr>
    <tr>
      <td>3.</td>
      <th scope="row">Gordon Greenidge</th>
      <td>281-564-6720</td>
      <td>281-511-6600</td>
      <td>Houston</td>
    </tr>
  </table>
</div>

<h2>Complexity 2</h2>
<div role="region" aria-labelledby="Cap2" tabindex="0">
  <table>
    <caption id="Cap2">Grade Calculation</caption>
    <tr>
      <th rowspan="2" id="h">Homework</th>
      <th colspan="3" id="e">Exams</th>
      <th colspan="3" id="p">Projects</th>
    </tr>
    <tr>
      <th id="e1" headers="e">1</th>
      <th id="e2" headers="e">2</th>
      <th id="ef" headers="e">Final</th>
      <th id="p1" headers="p">1</th>
      <th id="p2" headers="p">2</th>
      <th id="pf" headers="p">Final</th>
    </tr>
    <tr>
      <td headers="h">15%</td>
      <td headers="e e1">15%</td>
      <td headers="e e2">15%</td>
      <td headers="e ef">20%</td>
      <td headers="p p1">10%</td>
      <td headers="p p2">10%</td>
      <td headers="p pf">15%</td>
    </tr>
  </table>
</div>
              
            
!

CSS

              
                body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
}

table {
  margin: 1em 0;
  border-collapse: collapse;
/*   width: 100%; */
}

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;
}

th {
  vertical-align: bottom;
  background-color: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-weight: bold;
}

td::before {
  display: none;
}

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

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

td:nth-of-type(2) {
  font-style: italic;
}

th:nth-of-type(3),
td:nth-of-type(3) {
  text-align: right;
}

div {
  overflow: auto;
}
              
            
!

JS

              
                function AddTableARIA() {
  try {
    var allTables = document.querySelectorAll('table');
    for (var i = 0; i < allTables.length; i++) {
      allTables[i].setAttribute('role','table');
    }
    var allCaptions = document.querySelectorAll('caption');
    for (var i = 0; i < allCaptions.length; i++) {
      allCaptions[i].setAttribute('role','caption');
    }
    var allRowGroups = document.querySelectorAll('thead, tbody, tfoot');
    for (var i = 0; i < allRowGroups.length; i++) {
      allRowGroups[i].setAttribute('role','rowgroup');
    }
    var allRows = document.querySelectorAll('tr');
    for (var i = 0; i < allRows.length; i++) {
      allRows[i].setAttribute('role','row');
    }
    var allCells = document.querySelectorAll('td');
    for (var i = 0; i < allCells.length; i++) {
      allCells[i].setAttribute('role','cell');
    }
    var allHeaders = document.querySelectorAll('th');
    for (var i = 0; i < allHeaders.length; i++) {
      allHeaders[i].setAttribute('role','columnheader');
    }
    // this accounts for scoped row headers
    var allRowHeaders = document.querySelectorAll('th[scope=row]');
    for (var i = 0; i < allRowHeaders.length; i++) {
      allRowHeaders[i].setAttribute('role','rowheader');
    }
  } catch (e) {
    console.log("AddTableARIA(): " + e);
  }
}

AddTableARIA();
              
            
!
999px

Console