title: Download CSV from HTML table
body: <p>This is a self-answered question.</p>
  
  <hr>
  
  <p>How can I download an HTML <code>&lt;table&gt;</code> as a CSV within the browser? Assuming the HTML table contains no commas in the actual data.</p>
  
  <p>Here's my HTML table:</p>
  
  <pre><code>&lt;table style="width:100%"&gt;
    &lt;tr&gt;
      &lt;th&gt;Firstname&lt;/th&gt;
      &lt;th&gt;Lastname&lt;/th&gt; 
      &lt;th&gt;Age&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Jill&lt;/td&gt;
      &lt;td&gt;Smith&lt;/td&gt; 
      &lt;td&gt;50&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Eve&lt;/td&gt;
      &lt;td&gt;Jackson&lt;/td&gt; 
      &lt;td&gt;94&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I don't care about older browsers, just modern browsers that fully support ES6.</p>