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

              
                <compress-table rows=20>
	<table>
		<thead>
			<tr>
				<th>Name</th><th>Something</th><th>Age</th>
			</tr>
		</thead>
		<tbody>
<tr><td>Cat 0</td><td>Foo</td><td>0 years old.</td></tr>
<tr><td>Cat 1</td><td>Foo</td><td>2 years old.</td></tr>
<tr><td>Cat 2</td><td>Foo</td><td>4 years old.</td></tr>
<tr><td>Cat 3</td><td>Foo</td><td>6 years old.</td></tr>
<tr><td>Cat 4</td><td>Foo</td><td>8 years old.</td></tr>
<tr><td>Cat 5</td><td>Foo</td><td>10 years old.</td></tr>
<tr><td>Cat 6</td><td>Foo</td><td>12 years old.</td></tr>
<tr><td>Cat 7</td><td>Foo</td><td>14 years old.</td></tr>
<tr><td>Cat 8</td><td>Foo</td><td>16 years old.</td></tr>
<tr><td>Cat 9</td><td>Foo</td><td>18 years old.</td></tr>
<tr><td>Cat 10</td><td>Foo</td><td>20 years old.</td></tr>
<tr><td>Cat 11</td><td>Foo</td><td>22 years old.</td></tr>
<tr><td>Cat 12</td><td>Foo</td><td>24 years old.</td></tr>
<tr><td>Cat 13</td><td>Foo</td><td>26 years old.</td></tr>
<tr><td>Cat 14</td><td>Foo</td><td>28 years old.</td></tr>
<tr><td>Cat 15</td><td>Foo</td><td>30 years old.</td></tr>
<tr><td>Cat 16</td><td>Foo</td><td>32 years old.</td></tr>
<tr><td>Cat 17</td><td>Foo</td><td>34 years old.</td></tr>
<tr><td>Cat 18</td><td>Foo</td><td>36 years old.</td></tr>
<tr><td>Cat 19</td><td>Foo</td><td>38 years old.</td></tr>
<tr><td>Cat 20</td><td>Foo</td><td>40 years old.</td></tr>
<tr><td>Cat 21</td><td>Foo</td><td>42 years old.</td></tr>
<tr><td>Cat 22</td><td>Foo</td><td>44 years old.</td></tr>
<tr><td>Cat 23</td><td>Foo</td><td>46 years old.</td></tr>
<tr><td>Cat 24</td><td>Foo</td><td>48 years old.</td></tr>
<tr><td>Cat 25</td><td>Foo</td><td>50 years old.</td></tr>
<tr><td>Cat 26</td><td>Foo</td><td>52 years old.</td></tr>
<tr><td>Cat 27</td><td>Foo</td><td>54 years old.</td></tr>
<tr><td>Cat 28</td><td>Foo</td><td>56 years old.</td></tr>
<tr><td>Cat 29</td><td>Foo</td><td>58 years old.</td></tr>
<tr><td>Cat 30</td><td>Foo</td><td>60 years old.</td></tr>
<tr><td>Cat 31</td><td>Foo</td><td>62 years old.</td></tr>
<tr><td>Cat 32</td><td>Foo</td><td>64 years old.</td></tr>
<tr><td>Cat 33</td><td>Foo</td><td>66 years old.</td></tr>
<tr><td>Cat 34</td><td>Foo</td><td>68 years old.</td></tr>
<tr><td>Cat 35</td><td>Foo</td><td>70 years old.</td></tr>
<tr><td>Cat 36</td><td>Foo</td><td>72 years old.</td></tr>
<tr><td>Cat 37</td><td>Foo</td><td>74 years old.</td></tr>
<tr><td>Cat 38</td><td>Foo</td><td>76 years old.</td></tr>
<tr><td>Cat 39</td><td>Foo</td><td>78 years old.</td></tr>
<tr><td>Cat 40</td><td>Foo</td><td>80 years old.</td></tr>
<tr><td>Cat 41</td><td>Foo</td><td>82 years old.</td></tr>
<tr><td>Cat 42</td><td>Foo</td><td>84 years old.</td></tr>
<tr><td>Cat 43</td><td>Foo</td><td>86 years old.</td></tr>
<tr><td>Cat 44</td><td>Foo</td><td>88 years old.</td></tr>
<tr><td>Cat 45</td><td>Foo</td><td>90 years old.</td></tr>
<tr><td>Cat 46</td><td>Foo</td><td>92 years old.</td></tr>
<tr><td>Cat 47</td><td>Foo</td><td>94 years old.</td></tr>
<tr><td>Cat 48</td><td>Foo</td><td>96 years old.</td></tr>
<tr><td>Cat 49</td><td>Foo</td><td>98 years old.</td></tr>
<tr><td>Cat 50</td><td>Foo</td><td>100 years old.</td></tr>
<tr><td>Cat 51</td><td>Foo</td><td>102 years old.</td></tr>
<tr><td>Cat 52</td><td>Foo</td><td>104 years old.</td></tr>
<tr><td>Cat 53</td><td>Foo</td><td>106 years old.</td></tr>
<tr><td>Cat 54</td><td>Foo</td><td>108 years old.</td></tr>
<tr><td>Cat 55</td><td>Foo</td><td>110 years old.</td></tr>
<tr><td>Cat 56</td><td>Foo</td><td>112 years old.</td></tr>
<tr><td>Cat 57</td><td>Foo</td><td>114 years old.</td></tr>
<tr><td>Cat 58</td><td>Foo</td><td>116 years old.</td></tr>
<tr><td>Cat 59</td><td>Foo</td><td>118 years old.</td></tr>
<tr><td>Cat 60</td><td>Foo</td><td>120 years old.</td></tr>
<tr><td>Cat 61</td><td>Foo</td><td>122 years old.</td></tr>
<tr><td>Cat 62</td><td>Foo</td><td>124 years old.</td></tr>
<tr><td>Cat 63</td><td>Foo</td><td>126 years old.</td></tr>
<tr><td>Cat 64</td><td>Foo</td><td>128 years old.</td></tr>
<tr><td>Cat 65</td><td>Foo</td><td>130 years old.</td></tr>
<tr><td>Cat 66</td><td>Foo</td><td>132 years old.</td></tr>
<tr><td>Cat 67</td><td>Foo</td><td>134 years old.</td></tr>
<tr><td>Cat 68</td><td>Foo</td><td>136 years old.</td></tr>
<tr><td>Cat 69</td><td>Foo</td><td>138 years old.</td></tr>
<tr><td>Cat 70</td><td>Foo</td><td>140 years old.</td></tr>
<tr><td>Cat 71</td><td>Foo</td><td>142 years old.</td></tr>
<tr><td>Cat 72</td><td>Foo</td><td>144 years old.</td></tr>
<tr><td>Cat 73</td><td>Foo</td><td>146 years old.</td></tr>
<tr><td>Cat 74</td><td>Foo</td><td>148 years old.</td></tr>
<tr><td>Cat 75</td><td>Foo</td><td>150 years old.</td></tr>
<tr><td>Cat 76</td><td>Foo</td><td>152 years old.</td></tr>
<tr><td>Cat 77</td><td>Foo</td><td>154 years old.</td></tr>
<tr><td>Cat 78</td><td>Foo</td><td>156 years old.</td></tr>
<tr><td>Cat 79</td><td>Foo</td><td>158 years old.</td></tr>
<tr><td>Cat 80</td><td>Foo</td><td>160 years old.</td></tr>
<tr><td>Cat 81</td><td>Foo</td><td>162 years old.</td></tr>
<tr><td>Cat 82</td><td>Foo</td><td>164 years old.</td></tr>
<tr><td>Cat 83</td><td>Foo</td><td>166 years old.</td></tr>
<tr><td>Cat 84</td><td>Foo</td><td>168 years old.</td></tr>
<tr><td>Cat 85</td><td>Foo</td><td>170 years old.</td></tr>
<tr><td>Cat 86</td><td>Foo</td><td>172 years old.</td></tr>
<tr><td>Cat 87</td><td>Foo</td><td>174 years old.</td></tr>
<tr><td>Cat 88</td><td>Foo</td><td>176 years old.</td></tr>
<tr><td>Cat 89</td><td>Foo</td><td>178 years old.</td></tr>
<tr><td>Cat 90</td><td>Foo</td><td>180 years old.</td></tr>
<tr><td>Cat 91</td><td>Foo</td><td>182 years old.</td></tr>
<tr><td>Cat 92</td><td>Foo</td><td>184 years old.</td></tr>
<tr><td>Cat 93</td><td>Foo</td><td>186 years old.</td></tr>
<tr><td>Cat 94</td><td>Foo</td><td>188 years old.</td></tr>
<tr><td>Cat 95</td><td>Foo</td><td>190 years old.</td></tr>
<tr><td>Cat 96</td><td>Foo</td><td>192 years old.</td></tr>
<tr><td>Cat 97</td><td>Foo</td><td>194 years old.</td></tr>
<tr><td>Cat 98</td><td>Foo</td><td>196 years old.</td></tr>
<tr><td>Cat 99</td><td>Foo</td><td>198 years old.</td></tr>		
		</tbody>
	</table>
</compress-table>
              
            
!

CSS

              
                table {
	border-collapse: collapse;
	border: 1px solid black;
	max-width: 400px;
}

th, td {
	border: 1px solid black;
	padding: 5px; 
}

              
            
!

JS

              
                class CompressTable extends HTMLElement {

	constructor() {
		super();
		this.rows = this.hasAttribute('rows') ? parseInt(this.getAttribute('rows'),10) : 50;
	}
	
	connectedCallback() {
		let table = this.querySelector('table');
		if(!table) {
			console.warn('<compress-table> - No table found.');
			return;
		}
		
		// ok, so how big is our table?
		let rows = table.querySelectorAll('tbody tr');
		
		// can we leave if the table is small?
		if(rows.length <= this.rows) return;
		
		// ok, construct a click to show doohicky
		this.showRow = document.createElement('tr');
		let showTd = document.createElement('td');
		showTd.setAttribute('colspan',1000);
		showTd.style.textAlign = 'center';
		showTd.style.cursor = 'pointer';
		showTd.innerText = 'Click to Expand';
		this.showRow.appendChild(showTd);
		this.showRow.addEventListener('click', () => this.returnRows());
		
		// now, store rows this.rows +1 to rowCount
		let selector = `tbody tr:nth-child(n+${this.rows+1}):nth-child(-n+${rows.length})`;
		this.rowsToHide = table.querySelectorAll(selector);
		this.rowsToHide.forEach(r => {
			r.style.display = 'none';
		});
		
		table.querySelector('tbody').appendChild(this.showRow);

	}
	
	returnRows() {
		this.rowsToHide.forEach(r => {
			r.style.display = '';
		});
		this.showRow.style.display = 'none';		
	}
	
}

if(!customElements.get('compress-table')) customElements.define('compress-table', CompressTable);

              
            
!
999px

Console