HTML/CSS font color vs span style

HtmlCss

Html Problem Overview


What should I use?

<span style="color:red">test</span>

or

<font color="red">test</font>

and why?

Html Solutions


Solution 1 - Html

You should use <span>, because as specified by the spec, <font> has been deprecated and probably won't display as you intend.

Solution 2 - Html

Neither. You should separate content and presentation, giving your HTML code logical codes. Think of it this way; to a blind person, or on a browser that cannot display colors, what is left of your code? Why do you want it to be red?

Most probably, your decision to make text red is because you want to give it emphasis. So your HTML code should be:

<em>test</em>

This way, even non-visual browsers can make sure they give the text emphasis in one way or another.

Next step is to make the text red. But you don't want to add the color code everywhere, much more efficient to just add it once:

<style>
  em { color: red; }
</style>

This way, all emphasized code on your website becomes red, making it more constant.

Solution 3 - Html

1st preference external style sheet.

<span class="myClass">test</span>

css

.myClass
{
color:red;
}

2nd preference inline style

<span style="color:red">test</span>

<font> as mentioned is deprecated.

Solution 4 - Html

Use style. The font tag is deprecated (W3C Wiki).

Solution 5 - Html

<span style="color:#ffffff; font-size:18px; line-height:35px; font-family: Calibri;">Our Activities </span>

This works for me well:) As it has been already mentioned above "The font tag has been deprecated, at least in XHTML. It always safe to use span tag. font may not give you desire results, at least in my case it didn't.

Solution 6 - Html

The <font> tag has been deprecated, at least in XHTML. That means that it's use is officially "frowned upon," and there is no guarantee that future browsers will continue to display the text as you intended.

You have to use CSS. Go with the <span> tag, or a separate style sheet. According to its specification, the <span> tag has no semantic meaning and just allows you to change the style of a particular region.

Solution 7 - Html

Actually I would say the 1st preference would be an external style sheet (External CSS), the 2nd preference would be writing CSS in style tags in the header section of the current page (Internal CSS)

<style type="text/css">
<!-- CSS goes here -->
</style>

And as a 3rd option - or last resort rather - I'd use CSS in the tags themselves (Inline CSS).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIsisView Question on Stackoverflow
Solution 1 - HtmlKyleView Answer on Stackoverflow
Solution 2 - HtmlPeterView Answer on Stackoverflow
Solution 3 - HtmlMichaelView Answer on Stackoverflow
Solution 4 - HtmlfncompView Answer on Stackoverflow
Solution 5 - HtmlAmar PratapView Answer on Stackoverflow
Solution 6 - HtmlCody GrayView Answer on Stackoverflow
Solution 7 - HtmlDamienView Answer on Stackoverflow