What is the preferred method for setting CSS properties?
Inline style properties:
<div style="width:20px;height:20px;background-color:#ffcc00;"></div>
Style properties in <style>...</style> tags:
<style>.gold{width:20px;height:20px;background-color:#ffcc00;}</style><div class="gold"></div>
Style rules can be attached using:
Generally, I prefer to use linked style sheets because they:
However, your question is asking specifically about the
styletag versus inline styles. Prefer to use thestyletag, in this case, because it:Inline elements only affect their respective element.
An important difference between the
styletag and the inline attribute is specificity. Specificity determines when one style overrides another. Generally, inline styles have a higher specificity.Read CSS: Specificity Wars for an entertaining look at this subject.