1

I have a question regarding html color code.

<font color=rgb(255,0,0)> This is my font </font>

not showing red color fonts in firefox though the color code is fine. Any idea? Instead it is showing some weird green gray color!

Thanks

snoze
  • 123
  • 1
  • 3
  • 12

5 Answers5

5

Try with "style".

<font style="color: rgb(255,0,0)"> This is my font </font>
Marc Giroux
  • 186
  • 1
  • 7
  • 18
2

The syntax rgb(255,0,0) is not HTML and you are encountering error recovery. It is defined in the CSS colors spec. You can only use it in CSS.

Aside from that, the color attribute and the rest of the <font> element have been removed from HTML.

Use a stylesheet and a semantically appropriate element.

p {
  color: rgb(255, 0, 0);
}
<p>This is my font</p>
Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

I think something has to be added to this. You shouldn't use the HTML <font> tag. It's deprecated, it's not supported by HTML5 and it has a weird behavior such as the one already displayed when you tried to go rgb(255,0,0) and the browser painted your font dark green.

Go with any of the text tags such as <span>, or <p> or whatever. And for the color, use the style attribute:

<span style="color:rgb(255,0,0);">This is my font</span>

Docs regarding <font> http://www.w3schools.com/html/html_styles.asp

fnune
  • 5,256
  • 1
  • 21
  • 35
2

The color attribute only supports named and hexadecimal colors. To achieve the same affect using semantic HTML you can use the ID attribute on a span element and then use CSS to style it:

#warning {
  color: rgb(255, 0, 0);
}
<span id="warning">This is my font</span>

The reason it is displayed as the weird color is because of the same reason "chucknorris" produces a red-brownish color.

Community
  • 1
  • 1
metarmask
  • 1,747
  • 1
  • 16
  • 20
1

The <font> tag is obsolete, and the color attribute may not work completely in most recent browsers as it's deprecated, although it still works when using the hex color codes and the name of the color.

HTML should be used for describing the structure of web pages.

For styling your web page, you should use CSS. In your case, you could do something like:

<span style="color: rgb(255,0,0)">Hello World</span>

From W3C:

The <font> element is a non-standard element.

HTML5 classifies it as a non-conforming feature.

From MDN:

Do not use this element! Though once normalized in HTML 3.2, it was deprecated in HTML 4.01, at the same time as all elements related to styling only, then obsoleted in HTML5.

Starting with HTML 4, HTML does not convey styling information anymore (outside the <style> element or the style attribute of each element). For any new web development, styling should be written using CSS only.

The former behavior of the <font> element can be achieved, and even better controlled using the CSS Fonts CSS properties.

Sources:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font

https://www.w3.org/wiki/HTML/Elements/font

https://www.w3.org/TR/html5/obsolete.html#non-conforming-features

https://www.w3.org/standards/webdesign/htmlcss

jjnilton
  • 43
  • 2
  • 10