Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
How To Add Border In HTML?
Next article icon

How to add color in HTML without CSS ?

Last Updated : 04 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In HTML, adding color to text and elements is typically done using CSS. However, there are several approaches to add color directly in HTML, without using CSS.

We will discuss the following approaches to add color without CSS in HTML Elements.

Table of Content

  • Using Font Tag
  • Using JavaScript
  • Using SVG tag with fill attribute
  • Using Text Color Attribute
  • Using the bgcolor Attribute

Approach 1: Using Font Tag

Use <font> tag to specify the color of text within the tag. In font tags, we have to use color attributes to provide color names or codes.

Syntax

<font color="value">

Example: Illustration ofaddingd color in HTML without CSS Using Font Tag.

HTML
<!DOCTYPE html> <html>  <head>     <title>Adding color in HTML without CSS</title> </head>  <body>     <h3>Using font tag with color attribute</h3>     <h1>         <font color="green">Welcome to GeekForGeeks </font>     </h1>     <h2>         <font color="pink">It is an online learning platform</font>     </h2> </body>  </html> 

Output:

pn
Output

Approach 2: Using JavaScript

Define a JavaScript function called changeColor that is used to change the color of an HTML element with the id "myElement". Here we used <script> tagto add javascript code in HTML.

Syntax

<script> <!-- javascript body --> </script> 

Example: Illustration of adding color in HTML without CSS Using JavaScript

HTML
<!DOCTYPE html> <html>  <head>     <title>JavaScript Example</title>     <script>         function changeColor() {             var element = document.getElementById("myElement");             element.style.color = "green";         }     </script> </head>  <body onload="changeColor()">     <h1 id="myElement">Using javascript to change color of this text</h1> </body>  </html> 

Output:

bn
Output

Approach 3: Using SVG tag with fill attribute

SVG tag allows us to create shapes or text in HTML along witha fill attribute which is used to assign the color to that shape or text. In the below example we have created some shapes with different colors.

Syntax

<svg width="value" height="value">     <tag fill="value">Text or Shape</tag> </svg>

Example: Illustration ofaddingd color in HTML without CSS using SVG tag with fill attribute.

HTML
<!DOCTYPE html> <html>  <head>     <title>SVG Example</title> </head>  <body>     <h3>Using SVG</h3>     <svg width="100" height="100">         <circle cx="50" cy="50" r="40" fill="red" />     </svg>     <svg width="100" height="100">         <rect x="10" y="10" width="80" height="80" fill="blue" />     </svg>     <svg width="100" height="100">         <ellipse cx="50" cy="50" rx="40" ry="20" fill="green" />     </svg>     <svg width="100" height="100">         <polygon points="50,10 90,90 10,90" fill="yellow" />     </svg> </body>  </html> 

Output:

svgsvg
Output

Approach 4: Using Text Color Attribute

The text attribute in the <body> tag sets the default text color for all text within the body of the HTML document.

Syntax

<body text="value"> 

Example: Illustration of add color in HTML without CSS using Text Color Attribute

HTML
<!DOCTYPE html> <html>  <head>     <title>Text Attribute Example</title> </head>  <body text="green">     <h1>Welcome to GeekForGeeks</h1>     <h3>Adding color in HTML without CSS           using Text Color Attribute       </h3> </body>  </html> 

Output:

in11
Output

Approach 5: Using the bgcolor Attribute

The bgcolor attribute is used to setthe background color ofan element or entire page. Use the attribute inside the <body> tag.

Syntax

<body bgcolor="value"> 

Example: Illustration of adding color in HTML without CSS Using the bgcolor Attribute

HTML
<!DOCTYPE html> <html>  <head>     <title>Adding color in HTML without CSS</title> </head>  <body bgcolor="yellow">     <h3>Add color in HTML without CSS            using the bgcolor Attribute       </h3>     <h1>GeekForGeeks is the best learning platform</h1> </body>  </html> 

Output:

imgbg
Output

Next Article
How To Add Border In HTML?
author
yuvrajghule281
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-Questions

Similar Reads

  • How to Change Background Color in HTML without CSS ?
    In HTML, you can change the background color of an element using the bgcolor attribute. However, it's important to note that the bgcolor attribute is deprecated in HTML5 and should be avoided in favor of using CSS for styling. This article will cover various methods to change the background color of
    2 min read
  • How to Link a CSS to HTML?
    To link a CSS file to an HTML file, Create a separate CSS file (styles.css) and write styles on it. Now we need to use the <link> element inside the <head> section of the HTML file to attach the CSS file. Syntax:<link rel="stylesheet" href="styles.css">rel="stylesheet": It specifie
    3 min read
  • How To Add Opacity To A Color in CSS?
    To add opacity to a color in CSS, you can use the rgba() function, which stands for red, green, blue, and alpha (opacity). The rgba() function allows you to specify the opacity of a color by adding a fourth parameter called the "alpha channel." The alpha value ranges from 0 (completely transparent)
    3 min read
  • How To Add Border In HTML?
    Adding Borders to HTML elements is a common way to enhance the presentation and layout of web pages. Borders can be added to divs, paragraphs, images, and tables to separate or highlight content visually. CSS can provide several properties to customize the borders, such as color, style, and width. T
    5 min read
  • How to Change Font Color in HTML?
    We can use <font> tag to change the text color in HTML. This tag was used in older versions of HTML but is deprecated in HTML5. So we can use inline CSS as the best and quickest way to change the font color. 1. Change Font Color using <Font> tagThe <font> tag was used to change tex
    2 min read
  • How to add color picker in a form using HTML ?
    In this article, we will learn how to add a color picker in a form using HTML. As we know, a color picker is also known as a color-chooser. It is an interface in which a user can select a single color from multiple collections of background colors. When we submitted the color, the browser convert it
    1 min read
  • How to Change Image Color in CSS?
    Here are the methods to Change Image Color in CSS: 1. Applying CSS FiltersCSS filters allow you to apply visual effects directly to images, such as changing colors, adjusting brightness, or applying grayscale. [GFGTABS] HTML <html> <head> <style> .grayscale { filter: grayscale(100%
    3 min read
  • How to Add Border to an Image Using HTML and CSS?
    Adding a border to an image means putting a line around the image to make it look better and more noticeable. To add a border to an image using HTML and CSS, we can use the <img> tag and apply CSS styles like border, border-width, and border color to customize the border's appearance. Syntax .
    1 min read
  • How to link CSS with HTML Document?
    CSS is probably the most powerful style language in web development. It allows you to keep presentations of a document separate from the structure using CSS, making the maintenance and updating of a web page quite easy. CSS provides possibilities to style HTML elements, handle layouts, and create re
    5 min read
  • How to Change Link Color in CSS?
    To change the link color in CSS, use the color property with the anchor (<a>) tag, and different pseudo-classes for various states. HTML Links are added by using the anchor tag. It creates the link to navigate to another webpage from the current page. Note: The default HTML links are in blue c
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences