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
What Does a Seller Do? Roles And Responsibilities - Zippia
“The Truth About Working Weekends: Is It Really Worth It?”
How To Fix Epson Printer Error Code 0x9e
Moon Stone Pokemon Heart Gold
Valley Fair Tickets Costco
What happened to Lori Petty? What is she doing today? Wiki
Robinhood Turbotax Discount 2023
Teenbeautyfitness
Nordstrom Rack Glendale Photos
Gameday Red Sox
Employeeres Ual
ATV Blue Book - Values & Used Prices
Craigslist Boats For Sale Seattle
Pro Groom Prices – The Pet Centre
Shemal Cartoon
Things To Do In Atlanta Tomorrow Night
Hell's Kitchen Valley Center Photos Menu
State HOF Adds 25 More Players
Earl David Worden Military Service
Rs3 Eldritch Crossbow
Watch Your Lie in April English Sub/Dub online Free on HiAnime.to
Cain Toyota Vehicles
F45 Training O'fallon Il Photos
Foolproof Module 6 Test Answers
Bn9 Weather Radar
Meta Carevr
11526 Lake Ave Cleveland Oh 44102
Elanco Rebates.com 2022
Poe T4 Aisling
Alima Becker
Persona 4 Golden Taotie Fusion Calculator
Kattis-Solutions
2012 Street Glide Blue Book Value
How to Watch the X Trilogy Starring Mia Goth in Chronological Order
THE 10 BEST Yoga Retreats in Konstanz for September 2024
New York Rangers Hfboards
Cookie Clicker The Advanced Method
Indio Mall Eye Doctor
Me Tv Quizzes
Xxn Abbreviation List 2023
Great Clips Virginia Center Commons
Isabella Duan Ahn Stanford
Frigidaire Fdsh450Laf Installation Manual
Academic Calendar / Academics / Home
M&T Bank
Go Nutrients Intestinal Edge Reviews
Willkommen an der Uni Würzburg | WueStart
Clock Batteries Perhaps Crossword Clue
German American Bank Owenton Ky
Bradshaw And Range Obituaries
Tommy Gold Lpsg
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.