Reputation: 21749
Ok, so let's say I am coding HTML/CSS template and I see that I need to create a text with certain color and text-shadow. Should I create a different style in css file or just add style to the element? This <span style="color: #f2f12; text-shadow: 0 2px 0 #f1f1f1">Text</span>
or this <span class="styleforthistext">Text</span>
is better practise? If I know that I will use this color only for this text (only once).
Upvotes: 2
Views: 95
Reputation: 34591
Your html layout should only contain data. All styling should be done in separate css files. This is a good practice for many reasons.
Upvotes: 6
Reputation: 4914
Using a separate style in the CSS file is usually the better practice. It's the principle of separating your concerns - content is in the HTML, presentation (style) is in CSS (i.e. not inlined with the HTML) and behavior is in JavaScript (again, not inlined in the HTML).
Upvotes: 0
Reputation: 174957
You should ask yourself this, what is the meaning carried by the differently styled text?
Is it an emphasized text? Maybe a strong text? Is it a <h3>title</h3>
?
Based on that, create the appropriate element, and style that on your stylesheet. Very few cases justify the use of the style=
attribute, this isn't one of those cases.
Upvotes: 1