HTML font color Attribute - GeeksforGeeks (2024)

Last Updated : 24 Jun, 2024

Summarize

Comments

Improve

The HTML font color attribute is used to specify the text color within the <font> tag. Although this method is deprecated in HTML5, it’s still important to understand its historical use. Modern HTML uses CSS for styling purposes, but let’s see how the font color attribute works.

Syntax:

<font color="color_name|hex_number|rgb_number">

Attribute Values:

  • color_name: It sets the text color by using the color name. For example: “red”.
  • hex_number: It sets the text color by using color hex code. For example: “#0000ff”.
  • rgb_number: It sets the text color by using rgb code. For example: “rgb(0, 153, 0)”.

Note: The <font> color attribute is not supported in HTML5. It is recommended to use CSS for setting text color in modern web development.

Example to Set Font Color in HTML

You can use the color attribute of the font tag to set a font color in HTML. You can assign a color value using a color name, hex code, or RGB code.

Let’s understand it better with example:

Example: In this example, we are getting the colored text by using the color attribute having three different types of values. We have used color name value, hex code value, and RGB code value to set the font color of three different text elements.

HTML
<!DOCTYPE html><html><head> <title> HTML | <font> color Attribute </title></head><body> <font size="6" face="verdana" color="green"> GeeksforGeeks! </font> <br> <font size="6" face="arial" color="#008000"> GeeksforGeeks! </font> <br> <font size="6" color="rgb(128, 128, 0)"> GeeksforGeeks! </font></body></html>

Output:

HTML font color Attribute - GeeksforGeeks (1)

Although the font tag and its attributes are obsolete in HTML5, the above browsers still support them for backward compatibility. However, for modern web development, use CSS to style your text.

Modern Approach with CSS

To set font colors using CSS, you should use the style attribute or an external stylesheet.

CSS
<!DOCTYPE html><html><head> <title>Font Color Example with CSS</title> <style> .red-text { color: red; } .blue-text { color: #0000ff; } .green-text { color: rgb(0, 153, 0); } </style></head><body> <p class="red-text">This text is red using CSS class.</p> <p class="blue-text">This text is blue using CSS class.</p> <p class="green-text">This text is green using CSS class.</p></body></html>

Output:

HTML font color Attribute - GeeksforGeeks (2)

Modern Approach to style font color

While the <font> tag and its color attribute were useful in the past, modern HTML relies on CSS for styling. Understanding the historical context can help when dealing with legacy code, but using CSS is the best practice for current and future web development.

Supported Browsers

You can view the set font colors HTML using these browsers. The browsers support color attribute of font tag, and display the changes in text color.

HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.



HTML font color Attribute - GeeksforGeeks (4)

Improve

Please Login to comment...

HTML font color Attribute - GeeksforGeeks (2024)
Top Articles
Achieve your 2019 Financial Goals
Costco (COST) Stock Forecast & Price Prediction 2025, 2030 | CoinCodex
Public Opinion Obituaries Chambersburg Pa
Riverrun Rv Park Middletown Photos
It's Official: Sabrina Carpenter's Bangs Are Taking Over TikTok
Somboun Asian Market
No Limit Telegram Channel
La connexion à Mon Compte
CKS is only available in the UK | NICE
Craigslist Mexico Cancun
The Pope's Exorcist Showtimes Near Cinemark Hollywood Movies 20
Nordstrom Rack Glendale Photos
Moviesda Dubbed Tamil Movies
Catsweb Tx State
Osrs Blessed Axe
Valentina Gonzalez Leak
Job Shop Hearthside Schedule
Puretalkusa.com/Amac
Niche Crime Rate
Officialmilarosee
Site : Storagealamogordo.com Easy Call
Our History
Free Personals Like Craigslist Nh
How to Grow and Care for Four O'Clock Plants
Hannaford To-Go: Grocery Curbside Pickup
Sadie Sink Reveals She Struggles With Imposter Syndrome
Low Tide In Twilight Ch 52
Bento - A link in bio, but rich and beautiful.
Skycurve Replacement Mat
Makemv Splunk
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
Craigslist Maryland Baltimore
Sinfuldeeds Vietnamese Rmt
Black Adam Showtimes Near Amc Deptford 8
T&J Agnes Theaters
Ljw Obits
AI-Powered Free Online Flashcards for Studying | Kahoot!
Studentvue Columbia Heights
Danielle Ranslow Obituary
Electric Toothbrush Feature Crossword
Booknet.com Contract Marriage 2
How Big Is 776 000 Acres On A Map
20 Mr. Miyagi Inspirational Quotes For Wisdom
Market Place Tulsa Ok
Grace Family Church Land O Lakes
Wild Fork Foods Login
Hampton Inn Corbin Ky Bed Bugs
Autozone Battery Hold Down
David Turner Evangelist Net Worth
Buildapc Deals
Craigslist Yard Sales In Murrells Inlet
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 5974

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.