title: Rendering performance: style attributes or classnames and stylesheet rules?
body: <p>I'm building a data visualisation, and the rendering performance is critical. My question would be relevant to bog-standard HTML, though I happen to be using SVG, with JavaScript.</p>
  
  <p>OK, a hypothetical scenario: say I have 10,000 DOM nodes with a <code>background-color</code> of "<code>red</code>", and 10,000 DOM nodes with a <code>background-color</code> of "<code>green</code>". Each node is created by a JavaScript loop. I could either:</p>
  
  <ol>
  <li>Set a <code>style</code> attribute on each node, specifying the <code>background-color</code> of the node: <code>&lt;element style="background-color:red;"/&gt;</code></li>
  <li><p>Set a <code>class</code> attribute on each node, and then reference that class in an inline style or external stylesheet:</p>
  
  <p><code>&lt;head&gt;&lt;style&gt;.foo {background-color:red;}&lt;/style&gt;&lt;/head&gt;</code></p>
  
  <p><code>&lt;body&gt;&lt;element class="foo"/&gt;&lt;/body&gt;</code></p></li>
  </ol>
  
  <p>The performance of <em>downloading</em> the code is not at all important here - I'm only interested in the browser's rendering performance. I'm also quite aware that style attributes are not usually so useful or semantic in day-to-day website development, but I have a specific use case here.</p>
  
  <p>I <em>am</em> interested in logical answers, but it'd be really useful to hear from anyone has actually tested this or read about someone else's tests (I've searched for information, but found nothing specifically on this).</p>
  
  <p>Thanks for your help!</p>