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
Training Requirements and Guidelines for Web Services Users
USPS.com FAQs
Maxtrack Live
Kevin Cox Picks
7 Verification of Employment Letter Templates - HR University
Week 2 Defense (DEF) Streamers, Starters & Rankings: 2024 Fantasy Tiers, Rankings
Restaurer Triple Vitrage
Lamb Funeral Home Obituaries Columbus Ga
Kaydengodly
America Cuevas Desnuda
Kristine Leahy Spouse
Jonathan Freeman : "Double homicide in Rowan County leads to arrest" - Bgrnd Search
J Prince Steps Over Takeoff
Walgreens On Nacogdoches And O'connor
What Was D-Day Weegy
Housework 2 Jab
How Much Is Tj Maxx Starting Pay
Luna Lola: The Moon Wolf book by Park Kara
Google Flights Missoula
Mflwer
Marine Forecast Sandy Hook To Manasquan Inlet
Universal Stone Llc - Slab Warehouse & Fabrication
Laveen Modern Dentistry And Orthodontics Laveen Village Az
‘The Boogeyman’ Review: A Minor But Effectively Nerve-Jangling Stephen King Adaptation
Craigslist St. Cloud Minnesota
Ontdek Pearson support voor digitaal testen en scoren
Labcorp.leavepro.com
How do you get noble pursuit?
TJ Maxx‘s Top 12 Competitors: An Expert Analysis - Marketing Scoop
Craigslist Boerne Tx
Lawrence Ks Police Scanner
Craigslist Central Il
Mg Char Grill
Kokomo Mugshots Busted
Lowell Car Accident Lawyer Kiley Law Group
Uhaul Park Merced
آدرس جدید بند موویز
Jennifer Reimold Ex Husband Scott Porter
Agematch Com Member Login
Asian Grocery Williamsburg Va
42 Manufacturing jobs in Grayling
Daily Jail Count - Harrison County Sheriff's Office - Mississippi
8005607994
Walgreens Agrees to Pay $106.8M to Resolve Allegations It Billed the Government for Prescriptions Never Dispensed
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Todd Gutner Salary
Sea Guini Dress Code
Graduation Requirements
What your eye doctor knows about your health
Marion City Wide Garage Sale 2023
Shad Base Elevator
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.