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

              
                <h2>Tables</h2>

<!-- Start tables -->
<h3>Small</h3>
<table class="m-table m-table--responsive-small">
  <caption>This is a placeholder caption to show where it is displayed.</caption>
  <thead>
    <tr>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
  </tbody>
</table>

<h3>Medium</h3>
<table class="m-table m-table--responsive-medium">
  <caption>This is a placeholder caption to show where it is displayed.</caption>
  <thead>
    <tr>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
  </tbody>
</table>

<h3>Large</h3>
<table class="m-table m-table--responsive-large">
  <caption>This is a placeholder caption to show where it is displayed.</caption>
  <thead>
    <tr>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
      <th>Header Title</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
    <tr>
      <th data-th="Header Title" scope="row">Cell content</th>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
      <td data-th="Header Title">Cell content</td>
    </tr>
  </tbody>
</table>
              
            
!

CSS

              
                /* https://unpkg.com/@umich-lib/web@1/umich-lib.css */

table.m-table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}
.m-table caption,
.m-table th {
  text-align: left;
}
.m-table caption {
  color: var(--color-neutral-300);
}
.m-table tr > * {
  border-bottom: solid 1px var(--color-neutral-100);
  padding: var(--space-medium) 0;
  vertical-align: top;
}
.m-table tr > *:not(:last-child) {
  padding-right: var(--space-x-large);
}
.m-table th {
  font-size: var(--text-xxx-small);
  font-weight: var(--extrabold);
  letter-spacing: 1.25px;
  text-transform: uppercase;
  vertical-align: middle;
}
.m-table th:not([scope^='row']) {
  border-bottom: solid var(--space-xxx-small) var(--color-maize-400);
}
.m-table tr > *[data-th]:before {
  content: attr(data-th) ':\00a0';
  display: none;
}
.m-table tr > td[data-th]:before {
  font-weight: var(--semibold);
}
@media only screen and (max-width: 1200px) {
  .m-table--responsive-large thead {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px);
    clip: rect(1px, 1px, 1px, 1px);
  }
  .m-table--responsive-large tr > * {
    display: block;
  }
  .m-table--responsive-large tr > *:not(:last-child) {
    border-bottom: 0;
    padding-bottom: 0;
    padding-right: 0;
  }
  .m-table--responsive-large tr > *[data-th]:not(th) + *[data-th] {
    padding-top: 0;
  }
  .m-table--responsive-large tr > *[data-th]:before {
    display: inline;
  }
}
@media only screen and (max-width: 920px) {
  .m-table--responsive-medium thead {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px);
    clip: rect(1px, 1px, 1px, 1px);
  }
  .m-table--responsive-medium tr > * {
    display: block;
  }
  .m-table--responsive-medium tr > *:not(:last-child) {
    border-bottom: 0;
    padding-bottom: 0;
    padding-right: 0;
  }
  .m-table--responsive-medium tr > *[data-th]:not(th) + *[data-th] {
    padding-top: 0;
  }
  .m-table--responsive-medium tr > *[data-th]:before {
    display: inline;
  }
}
@media only screen and (max-width: 720px) {
  .m-table--responsive-small thead {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px);
    clip: rect(1px, 1px, 1px, 1px);
  }
  .m-table--responsive-small tr > * {
    display: block;
  }
  .m-table--responsive-small tr > *:not(:last-child) {
    border-bottom: 0;
    padding-bottom: 0;
    padding-right: 0;
  }
  .m-table--responsive-small tr > *[data-th]:not(th) + *[data-th] {
    padding-top: 0;
  }
  .m-table--responsive-small tr > *[data-th]:before {
    display: inline;
  }
}
.m-table--responsive thead {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px 1px 1px 1px);
  /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
}
.m-table--responsive tr > * {
  display: block;
}
.m-table--responsive tr > *:not(:last-child) {
  border-bottom: 0;
  padding-bottom: 0;
  padding-right: 0;
}
.m-table--responsive tr > *[data-header]:not(th) + *[data-header] {
  padding-top: 0;
}
.m-table--responsive tr > *[data-header]:before {
  content: attr(data-header) ':\00a0';
}
.m-table--responsive tr > td[data-header]:before {
  font-weight: var(--semibold);
}
              
            
!

JS

              
                /*
Automatically sets responsive state based on smallest-possible width. This will one day be replaced with @container, when widely available: https://caniuse.com/?search=%40container
*/

// Make sure everything is loaded before continuing
window.addEventListener('load', () => {
  // Responsive table class
  const responsiveClass = 'm-table--responsive';
  // Find and loop through each table
  const getTables = document.querySelectorAll('table.m-table');
  getTables.forEach((table) => {
    // Get parent element
    const parent = table.parentElement;
    // Get smallest possible width of table
    table.setAttribute('style', 'width: min-content;');
    const tableWidth = table.scrollWidth;
    table.removeAttribute('style');
    // Add responsive table class if table width is greater than parent width
    window.addEventListener('resize', (event) => {
      // Get left and right padding of parent
      let parentHorizontalPadding = 0;
      ['left', 'right'].forEach((side) => parentHorizontalPadding += parseInt(getComputedStyle(parent).getPropertyValue(`padding-${side}`)));
      // Get parent width, minus padding
      const parentWidth = parent.clientWidth - parentHorizontalPadding;
      // Compare widths and check if class exists
      if (tableWidth > parentWidth) {
        table.classList.add(responsiveClass);
      } else {
        table.classList.remove(responsiveClass);
      }
    });
  });
  // Trigger resize event
  window.dispatchEvent(new Event('resize'));
});
              
            
!
999px

Console