HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
table {
border-collapse: collapse;
border: 1px solid black;
max-width: 400px;
}
th, td {
border: 1px solid black;
padding: 5px;
}
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);
Also see: Tab Triggers