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

              
                <table>
  <thead>
    <tr>
      <td></td>
      <th>Basic</th>
      <th>Premium</th>
      <th>Deluxe</th>
      <th>Business</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>Feature 1</th>
      <td>✔</td>
      <td>✔</td>
      <td>✔</td>
      <td>✔</td>
    </tr>
     <tr>
      <th>Feature 2</th>
      <td>❌</td>
      <td>✔</td>
      <td>✔</td>
      <td>✔</td>
    </tr>
     <tr>
      <th>Feature 3</th>
      <td>❌</td>
      <td>❌</td>
      <td>✔</td>
      <td>✔</td>
    </tr>
     <tr>
      <th>Feature 4</th>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>✔</td>
    </tr>
  <tbody>
</table>
              
            
!

CSS

              
                body {
  padding: 5%;
}

table {
  width: 100%;
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
  border-collapse: collapse;
  margin-bottom:1em;
  
  th, td {
    padding: 0.5em 1em;
    border-bottom: 1px solid #ccc;
    border-right: 1px solid #ccc;
    white-space: pre;
  }
  
  thead th,
  tbody td {
    text-align: center;
  }
  
  // Custom Styles
  thead {
    color: white;
    background: #0cf;
    
    th {
      padding: 1em;
    }
  }
  
  &[data-comparing="active"] tbody th {
    border-bottom: none;
    font-size: 0.75em;
    color: #767676;
    padding-bottom: 0;
  }

}
              
            
!

JS

              
                // CONFIGS
var tableSelector = 'table';
var targetBreakpoint = 500;
var currentVisibleColumn = 1;
var nextButtonText = 'Compare Next';

// SETUP/SELECT REUSABLE ELEMENTS
var table = document.querySelector( tableSelector );
var allCells = table.querySelectorAll('th, td');
var columnHeaders = table.querySelectorAll('thead th:not(:empty)');
var rowHeaders = table.querySelectorAll('tbody th');
var nextButton = document.createElement('button');

function createButtons() {
  nextButton.textContent = nextButtonText;
  nextButton.style.display =  'none';

  table.parentNode.insertBefore(nextButton, table.nextSibling );
  
  nextButton.addEventListener('click', function(){
    currentVisibleColumn = currentVisibleColumn + 1 > columnHeaders.length ? 1 : currentVisibleColumn + 1;
    showCurrentlyVisible();
  });
}

function showCurrentlyVisible() {
    // Get the Items we're going to show. The :not(:empty) query here is because sometimes you have empty <th>s in <thead>
    var currentlyVisibleColHeader = document.querySelector('thead th:not(:empty):nth-of-type( '+ currentVisibleColumn +')');
    var currentlyVisibleCells = document.querySelectorAll('tbody td:nth-of-type(' +currentVisibleColumn+ ')');

    // Hide All The Cells
    for(var i=0;i<allCells.length;i++ ) { 
      allCells[i].style.display = 'none'; 
    }

    // Show Currently Visible Col Header
    currentlyVisibleColHeader.style.display = 'block';

    // Show Currently Visible Cells
    for( var i=0;i<currentlyVisibleCells.length;i++) {
      currentlyVisibleCells[i].style.display = 'block';
    }

    // Show Row Headers
    for( var i=0;i<rowHeaders.length;i++) {
      rowHeaders[i].style.display = 'block';
    }
}

function updateTable() {
  
  // Get the Table's Width. Might as well go FULL Container Query over here.
  var tableWidth = table.getBoundingClientRect().width;
  
  // If the table explodes off the viewport or is wider than the target breakpoint
  if ( tableWidth > window.innerWidth || tableWidth < targetBreakpoint ) {

    if(table.getAttribute('data-comparing') != 'active') {
      // Set the comparison state to "Active"
      table.setAttribute('data-comparing','active');

      // Show Next Button
      nextButton.style.display =  'block';
    
      // Show the currently visible column
      showCurrentlyVisible();

    }

  } else {
    
    if(table.getAttribute('data-comparing') == 'active') {

      // Turn off comparing    
      table.setAttribute('data-comparing','');

      // Hide the next button
      nextButton.style.display =  'none';

      // Remove styles from all cells, ergo, show all the cells
      for( var i=0;i<allCells.length;i++ ) {
        allCells[i].style.display = ''; 
      }

      // Remove styles from all row headers
      for( var i=0;i<rowHeaders.length;i++) {
        rowHeaders[i].style.display = '';
      }
    }
  }
}

createButtons();
updateTable();
window.addEventListener('resize', updateTable);
              
            
!
999px

Console