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

              
                <sortable-table>
	<table>
		<caption>Bruce Springsteen’s studio albums</caption>
		<thead>
			<tr>
				<th data-sort-options="ascending">title</th>
				<th data-sort-options="ascending descending" aria-sort="ascending">release date</th>
				<th>producer</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>Greetings from Asbury Park, N.J.</td>
				<td><time>1973-01-05</time></td>
				<td>Mike Appel, Jim Cretecos</td>
			</tr>
			<tr>
				<td>The Wild, the Innocent & the E Street Shuffle</td>
				<td><time>1973-09-11</time></td>
				<td>Mike Appel, Jim Cretecos</td>
			</tr>
			<tr>
				<td>Born to Run</td>
				<td><time>1975-08-25</time></td>
				<td>Bruce Springsteen, Mike Appel, Jon Landau</td>
			</tr>
			<tr>
				<td>Darkness on the Edge of Town</td>
				<td><time>1978-06-02</time></td>
				<td>Bruce Springsteen, Jon Landau, Steven Van Zandt</td>
			</tr>
			<tr>
				<td>The River</td>
				<td><time>1980-10-10</time></td>
				<td>Bruce Springsteen, Jon Landau, Steven Van Zandt</td>
			</tr>
			<tr>
				<td>Nebraska</td>
				<td><time>1982-09-20</time></td>
				<td>Mike Batlan</td>
			</tr>
			<tr>
				<td>Born in the U.S.A.</td>
				<td><time>1984-06-04</time></td>
				<td>Bruce Springsteen, Jon Landau, Chuck Plotkin, Steven Van Zandt</td>
			</tr>
			<tr>
				<td>Tunnel of Love</td>
				<td><time>1987-10-09</time></td>
				<td>Bruce Springsteen, Jon Landau, Chuck Plotkin</td>
			</tr>
			<tr>
				<td>Human Touch</td>
				<td><time>1992-03-31</time></td>
				<td>Bruce Springsteen, Jon Landau, Chuck Plotkin, Roy Bittan</td>
			</tr>
			<tr>
				<td>Lucky Town</td>
				<td><time>1992-03-31</time></td>
				<td>Bruce Springsteen, Jon Landau, Chuck Plotkin, Roy Bittan</td>
			</tr>
			<tr>
				<td>The Ghost of Tom Joad</td>
				<td><time>1995-11-21</time></td>
				<td>Bruce Springsteen, Chuck Plotkin</td>
			</tr>
			<tr>
				<td>The Rising</td>
				<td><time>2002-07-30</time></td>
				<td>Brendan O’Brien</td>
			</tr>
			<tr>
				<td>Devils & Dust</td>
				<td><time>2005-04-26</time></td>
				<td>Brendan O’Brien, Bruce Springsteen, Chuck Plotkin</td>
			</tr>
			<tr>
				<td>We Shall Overcome: The Seeger Sessions</td>
				<td><time>2006-04-25</time></td>
				<td>Bruce Springsteen</td>
			</tr>
			<tr>
				<td>Magic</td>
				<td><time>2007-09-25</time></td>
				<td>Brendan O’Brien</td>
			</tr>
			<tr>
				<td>Working on a Dream</td>
				<td><time>2009-01-27</time></td>
				<td>Brendan O’Brien</td>
			</tr>
			<tr>
				<td>Wrecking Ball</td>
				<td><time>2012-03-06</time></td>
				<td>Ron Aniello, Bruce Springsteen</td>
			</tr>
			<tr>
				<td>High Hopes</td>
				<td><time>2014-01-14</time></td>
				<td>Ron Aniello, Brendan O’Brien, Bruce Springsteen</td>
			</tr>
			<tr>
				<td>Western Stars</td>
				<td><time>2019-06-14</time></td>
				<td>Ron Aniello, Bruce Springsteen</td>
			</tr>
			<tr>
				<td>Letter to You</td>
				<td><time>2020-10-23</time></td>
				<td>Ron Aniello, Bruce Springsteen</td>
			</tr>
			<tr>
				<td>Only the Strong Survive</td>
				<td><time>2022-11-11</time></td>
				<td>Ron Aniello, Bruce Springsteen</td>
			</tr>
		</tbody>
	</table>
</sortable-table>

              
            
!

CSS

              
                html {
	font: 1em/1.4 Lato, sans-serif;
	font-variant-numeric: lining-nums proportional-nums;
	color-scheme: light dark;
}

table {
	--column-gap: 1em;
	--row-gap: 0.55em;
	table-layout: fixed;
	border-collapse: collapse;
	line-height: 1.1;
	font-variant-numeric: lining-nums tabular-nums;
}

caption {
	padding-bottom: 1em;
}

thead {
	position: sticky;
	top: 0;
	background: Canvas;
}

th, td {
	text-align: start;
	vertical-align: top;
	
	&:not(:first-child) {
		padding-inline-start: calc(var(--column-gap) / 2);
	}
	&:not(:last-child) {
		padding-inline-end: calc(var(--column-gap) / 2);
	}
	
	thead tr:not(:first-child) &,
	tbody & {
		padding-block-start: calc(var(--row-gap) / 2);
	}
	thead &,
	tbody:not(:last-child) &,
	tbody:last-child tr:not(:last-child) & {
		padding-block-end: calc(var(--row-gap) / 2);
	}
}

sortable-table button {
	background: transparent;
	border: none;
	padding: 0;
	font: inherit;
	text-align: inherit;
	white-space: nowrap;
	
	:where(th[data-sort-options~="ascending"]) &::after {
		content: ' △'
	}

	:where(th[data-sort-options~="ascending"]) &::after {
		content: ' △'
	}

	:where(th[data-sort-options~="descending"]) &::after {
		content: ' ▽'
	}

	:where(th[data-sort-options~="ascending"][data-sort-options~="descending"]) &::after {
		content: ' △▽'
	}

	th[aria-sort="ascending"] &::after {
		content: ' ▲';
	}

	th[aria-sort="descending"] &::after {
		content: ' ▼';
	}
}

              
            
!

JS

              
                class SortableTable extends HTMLElement {
  constructor() {
    super();
  }

	connectedCallback() {
    this.querySelectorAll('th').forEach((thElement, index) => {
			if (thElement.dataset.sortOptions) {
				const buttonElement = document.createElement('button');
				buttonElement.textContent = thElement.textContent;
				buttonElement.addEventListener('click', () => {
					this.sortByColumn(thElement.textContent);
				});
				thElement.innerHTML = null;
				thElement.appendChild(buttonElement);
			}
		});
  }
	
	sortByColumn(title) {
		console.log(`sort by ${title}`);
	}
}

customElements.define('sortable-table', SortableTable);

              
            
!
999px

Console