title: Is it considered bad practice to write an element's style directly with PHP?
body: <p>I know that it is usually considered bad practice to mix CSS with HTML and that CSS selectors (ids, classes, etc) should generally be used to style elements in external stylesheets. But this can be quite inconvenient when writing a dynamic page in PHP. It is much easier to output the element's style directly using PHP by writing to the element's style attribute. Would this be considered bad practice, even if using classes would make it even more difficult to manage from the developer's end?</p>
  
  <p>For example, I have an element's color style store in a database and this element has a different color depending on the parameters provided in the dynamic PHP page. In this scenario, I could write to the css stylesheet with php some class with the color variable I get from the database</p>
  
  <pre><code>echo '.custom-color {';
  echo   'color: ' . $colorFromDatabase . ';';
  echo '}';
  </code></pre>
  
  <p>and then append the class to the element:</p>
  
  <pre><code>&lt;div class="custom-color"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>or I could just echo the style directly to the element.</p>
  
  <pre><code>echo '&lt;div style="color:' . $colorFromDatabase . ';" &gt;';
  </code></pre>
  
  <p>Which is the better way to go?</p>