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

              
                <form>
  <p>Show or hide table columns</p>
  <ul>

    <li>
      <input checked onclick="toggleRow(2)" type="checkbox" id="cbx-1" /><label for="cbx-1">Format</label>
    </li>
    <li>
      <input checked onclick="toggleRow(3)" type="checkbox" id="cbx-2" /><label for="cbx-2">Release Year</label>
    </li>
    <li>
      <input checked onclick="toggleRow(4)" type="checkbox" id="cbx-3" /><label for="cbx-3">Country / Region</label>
    </li>
    <li>
      <input checked onclick="toggleRow(5)" type="checkbox" id="cbx-4" /><label for="cbx-4">Genre</label>
    </li>
    <li>
      <input checked onclick="toggleRow(6)" type="checkbox" id="cbx-5" /><label for="cbx-5">Rating</label>
    </li>
  </ul>
</form>

  <div class="table-wrapper" tabindex="0" role="group" aria-labelledby="caption">
  <table>
    <caption id="caption"><h1>Your music collection</h1></caption>
    <thead>
      <tr>
        <th>Artist</th>
        <th>Album</th>
        <th>Format</th>
        <th>Release year</th>
        <th>Country / region</th>
        <th>Genre</th>
        <th>Rating</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>AC/DC</td>
        <td>Back In Black</td>
        <td>Vinyl</td>
        <td>1980</td>
        <td>Germany</td>
        <td>Hard rock</td>
        <td>4.42 / 5</td>
      </tr>

      <tr>
        <td>Accept</td>
        <td>Breaker</td>
        <td>Vinyl</td>
        <td>1981</td>
        <td>Germany</td>
        <td>Heavy metal</td>
        <td>4.25 / 5</td>
      </tr>

      <tr>
        <td>Alice Cooper</td>
        <td>Raise Your First And Yell</td>
        <td>Vinyl</td>
        <td>1987</td>
        <td>Europe</td>
        <td>Heavy metal</td>
        <td>3.80 / 5</td>
      </tr>

      <tr>
        <td>Anthem</td>
        <td>Burning Oath</td>
        <td>SHM-CD</td>
        <td>2012</td>
        <td>Japan</td>
        <td>Heavy metal</td>
        <td>3.45 / 5</td>
      </tr>

      <tr>
        <td>Black Sabbath</td>
        <td>Mob Rules</td>
        <td>Vinyl</td>
        <td>1981</td>
        <td>Japan</td>
        <td>Heavy metal</td>
        <td>4.66 / 5</td>
      </tr>

      <tr>
        <td>Bryan May + Friends</td>
        <td>Star Fleet Project</td>
        <td>Vinyl</td>
        <td>1983</td>
        <td>Europe</td>
        <td>Hard Rock</td>
        <td>4.02 / 5</td>
      </tr>

      <tr>
        <td>Concerto Moon</td>
        <td>From Father To Son</td>
        <td>CD</td>
        <td>1998</td>
        <td>Japan</td>
        <td>Heavy Metal</td>
        <td>4.25 / 5</td>
      </tr>

      <tr>
        <td>Dunsmuir</td>
        <td>Dunsmuir</td>
        <td>Vinyl</td>
        <td>2016</td>
        <td>US</td>
        <td>Heavy Metal</td>
        <td>4.69 / 5</td>
      </tr>
    </tbody>
  </table>
</div>
              
            
!

CSS

              
                /* @link https://utopia.fyi/type/calculator?c=1280,18,1.333,1700,26,1.333,5,2,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l */

:root {
  --step--2: clamp(0.63rem, calc(-0.22rem + 1.07vw), 0.91rem);
  --step--1: clamp(0.84rem, calc(-0.3rem + 1.43vw), 1.22rem);
  --step-0: clamp(1.13rem, calc(-0.4rem + 1.9vw), 1.63rem);
  --step-1: clamp(1.5rem, calc(-0.53rem + 2.54vw), 2.17rem);
  --step-2: clamp(2rem, calc(-0.71rem + 3.39vw), 2.89rem);
  --step-3: clamp(2.66rem, calc(-0.95rem + 4.51vw), 3.85rem);
  --step-4: clamp(3.55rem, calc(-1.26rem + 6.01vw), 5.13rem);
  --step-5: clamp(4.74rem, calc(-1.68rem + 8.02vw), 6.84rem);
}

:root {
  --color-primary: #f5ee58;
  --color-secondary: #4d3053;
  --color-tertiary: rgba(0, 0, 0, 0.2);
  --color-quaternary: rgba(0, 0, 0, 0.4);

  --font-body: "Nunito", sans-serif;
  --font-headings: "Bebas Neue", sans-serif;
}

html {
  background-color: var(--color-secondary);
}

body {
  max-width: 1600px;
  color: var(--color-primary);
  font-family: var(--font-body);
  font-size: var(--step-0);
  padding: var(--step-2);
  line-height: 1.5;
  margin: 0 auto;
}

table {
  text-align: left;
  border-collapse: collapse;
  white-space: nowrap;
  margin-bottom: 2rem;
}

thead th {
  padding-bottom: var(--step--2);
  line-height: 1;
  font-family: var(--font-headings);
  vertical-align: top;
  font-weight: 400;
}

tbody td {
  padding-top: var(--step-0);
  padding-bottom: var(--step--2);
  vertical-align: top;
}

tr > * {
  padding-left: var(--step-0);
  padding-right: var(--step-0);
}

thead {
  border-bottom: 1px solid var(--color-primary);
  font-size: var(--step-1);
}

tbody tr {
  border-bottom: 1px solid var(--color-tertiary);
}

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

.table-wrapper {
  overflow: auto;
}

::-webkit-scrollbar {
  height: 1rem;
  z-index: 100;
  position: relative;
  border-radius: 1rem;
}

::-webkit-scrollbar-thumb {
  background: var(--color-primary);
  border-radius: 1rem;
}

::-webkit-scrollbar-track {
  background: var(--color-quaternary);
  border-radius: 1rem;
}

form {
  padding: var(--step-1);
  background-color: var(--color-tertiary);
  margin-bottom: var(--step-2);
  overflow: auto;
  user-select: none;
  white-space: nowrap;
}

input {
  accent-color: var(--color-primary);
  width: var(--step--1);
  aspect-ratio: 1;
}

label {
  font-size: var(--step--1);
}

form li {
  display: flex;
  align-items: center;
  gap: calc(var(--step--1) / 2);
}

form ul {
  display: flex;
  gap: var(--step-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.hidden {
  display: none !important;
}

p {
  margin-top: 0;
}

caption {
  text-align: left;
}

h1 {
  font-family: var(--font-headings);
  font-size: var(--step-3);
  margin-top: 0;
  margin-bottom: var(--step-1);
  font-weight: 400;
}

input, label {
  cursor: pointer;
}
              
            
!

JS

              
                // Thanks to Adrian Roselli for this really useful snippet https://adrianroselli.com/2017/11/a-responsive-accessible-table.html
// https://adrianroselli.com/2018/02/tables-css-display-properties-and-aria.html
// https://adrianroselli.com/2018/05/functions-to-add-aria-to-tables-and-lists.html
function AddTableARIA() {
  try {
    var allTables = document.querySelectorAll("table");
    for (var i = 0; i < allTables.length; i++) {
      allTables[i].setAttribute("role", "table");
    }
    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");
    }
    // caption role not needed as it is not a real role and
    // browsers do not dump their own role with display block
  } catch (e) {
    console.log("AddTableARIA(): " + e);
  }
}

AddTableARIA();

const allBodyRows = document.querySelectorAll("tbody > tr");
const allHeadCols = document.querySelectorAll("thead > tr > th");

function toggleRow(index) {
  allBodyRows.forEach(function (row) {
    const cell = row.querySelector(`td:nth-child(${index + 1})`);
    cell.classList.toggle("hidden");
    const ariaValue = cell.classList.contains("hidden") ? "true" : "false";
    cell.setAttribute("aria-hidden", ariaValue);
  });

  allHeadCols[index].classList.toggle("hidden");
  const ariaValue = allHeadCols[index].classList.contains("hidden")
    ? "true"
    : "false";
  allHeadCols[index].setAttribute("aria-hidden", ariaValue);
}
              
            
!
999px

Console