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

              
                <div class="table-wrapper">
  <table id="js-contacts">
        <caption><h1>Your contacts</h1></caption>
    <thead>
      <tr>
        <th>Name</th>
        <th>Category</th>
        <th>Email</th>
        <th>Phone</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>
          <img src="https://100k-faces.glitch.me/random-image?id=1" />
          Longname Longsurname
        </td>
        <td>
          Family
        </td>
        <td>
          johndoe@email.nonexistent.com
        </td>
        <td>
          (999) 123 - 4567
        </td>
      </tr>
      <tr>
        <td>
          <img src="https://100k-faces.glitch.me/random-image?id=2" />
          John Middlename Doe
        </td>
        <td>
          Family
        </td>
        <td>
          johndoe@email.nonexistent.com
        </td>
        <td>
          (999) 123 - 4567
        </td>
      </tr>
      <tr>
        <td>
          <img src="https://100k-faces.glitch.me/random-image?id=3" />
          Longername Doe
        </td>
        <td>
          Friends
        </td>
        <td>
          johndoe@email.nonexistent.com
        </td>
        <td>
          (999) 123 - 4567
        </td>
      </tr>
      <tr>
        <td>
          <img src="https://100k-faces.glitch.me/random-image?id=4" />
          Longname Doe
        </td>
        <td>
          Work
        </td>
        <td>
          johndoe@email.nonexistent.com
        </td>
        <td>
          (999) 123 - 4567
        </td>
      </tr>
      <tr>
        <td>
          <img src="https://100k-faces.glitch.me/random-image?id=5" />
          John Longsurename
        </td>
        </td>
        <td>
          Contact
        </td>
        <td>
          johndoe@email.nonexistent.com
        </td>
        <td>
          (999) 123 - 4567
      </tr>
    </tbody>
  </table>
</div>
              
            
!

CSS

              
                /* @link https://utopia.fyi/type/calculator?c=920,16,1.2,1500,24,1.25,5,2,568&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l */

:root {
  --step--2: clamp(0.69rem, calc(0.27rem + 0.73vw), 0.96rem);
  --step--1: clamp(0.83rem, calc(0.25rem + 1.01vw), 1.2rem);
  --step-0: clamp(1rem, calc(0.21rem + 1.38vw), 1.5rem);
  --step-1: clamp(1.2rem, calc(0.13rem + 1.86vw), 1.88rem);
  --step-2: clamp(1.44rem, calc(0.01rem + 2.49vw), 2.34rem);
  --step-3: clamp(1.73rem, calc(-0.18rem + 3.32vw), 2.93rem);
  --step-4: clamp(2.07rem, calc(-0.45rem + 4.38vw), 3.66rem);
  --step-5: clamp(2.49rem, calc(-0.83rem + 5.76vw), 4.58rem);
}

:root {
  --color-primary: #1c1e0b;
  --color-secondary: #f5d13a;
  --color-tertiary: rgba(0, 0, 0, 0.25);

  --font-body: "General Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

caption {
  text-align: left;
}

h1 {
  font-size: var(--step-3);
  line-height: var(--step-3);
  font-weight: bold;
  list-style: none;
  margin-top: 0;
  margin-bottom: var(--step-2);
}

table {
  text-align: left;
  border-collapse: collapse;
  width: 100%;
  border: 2px solid var(--color-tertiary);
  background-color: rgba(255, 255, 255, 0.2);
}

thead th {
  padding-bottom: var(--step--2);
  font-weight: bold;
  vertical-align: top;
}

thead th,
tbody td {
  padding: var(--step-1) var(--step-0) var(--step--2) var(--step-0);
}

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

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

tr > * + * {
  padding-left: var(--step-2);
}

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

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

tbody td::before {
  display: none;
}

img {
  border-radius: 100%;
  width: 4rem;
  aspect-ratio: 1;
  border: 3px solid var(--color-tertiary);
  display: inline-block;
  vertical-align: middle;
  margin-right: 1rem;
}

@media screen and (max-width: 880px) {
  thead {
    display: none;
  }

  table,
  tbody,
  tbody tr,
  tbody td,
  caption {
    display: flex;
    flex-directioN: column;
    width: 100%;
    word-break: break-all;
  }
  
  table {
    background-color: transparent;
    border-width: 0;
  }
  
  tbody {
  border: 2px solid var(--color-tertiary);
  background-color: rgba(255, 255, 255, 0.2);
  }

  table tr {
    padding-bottom: 1rem;
  }
  
    table tr td:first-child {
      margin-bottom: calc(-1 * var(--step-0));
      flex-direction: row;
      align-items: center;
  }


  table tr td:not(:first-child) {
    padding-left: calc(6rem);
    padding-top: 0;
  }

  .table-wrapper {
    max-width: 568px;
  }

  tbody tr td:not(:first-child)::before {
    font-weight: 600;
    font-size: var(--step--1);
    display: block;
  }
}

              
            
!

JS

              
                // Thanks to Adrian Roselli for this really useful snippet https://adrianroselli.com/2017/11/a-responsive-accessible-table.html

function ResponsiveCellHeaders(elmID) {
  try {
    var THarray = [];
    var table = document.getElementById(elmID);
    var ths = table.getElementsByTagName("th");
    for (var i = 0; i < ths.length; i++) {
      var headingText = ths[i].innerHTML;
      THarray.push(headingText);
    }
    var styleElm = document.createElement("style"),
      styleSheet;
    document.head.appendChild(styleElm);
    styleSheet = styleElm.sheet;
    for (var i = 0; i < THarray.length; i++) {
      styleSheet.insertRule(
        "#" +
          elmID +
          " td:nth-child(" +
          (i + 1) +
          ')::before {content:"' +
          THarray[i] +
          ': ";}',
        styleSheet.cssRules.length
      );
    }
  } catch (e) {
    console.log("ResponsiveCellHeaders(): " + e);
  }
}

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

ResponsiveCellHeaders("js-contacts");
AddTableARIA();
              
            
!
999px

Console