Professional Documents
Culture Documents
HTML Colors - HTML Color Types & Usage - GeeksforGeeks
HTML Colors - HTML Color Types & Usage - GeeksforGeeks
HTML Tutorial HTML Exercises HTML Tags HTML Attributes Global Attributes Event Attributes HTML Inter
HTML Colors
HTML Colors can be applied to text, backgrounds, borders, links, forms, tables,
etc., They can be defined using various formats, such as hexadecimal, RGB,
RGBA, HSL, and named colors, allowing for precise control of color
presentation on web pages.
Border Color HTML Border Color refers to the color <div style=”border: 1px
of borders around elements like <div>, solid black; border-
https://www.geeksforgeeks.org/html-colors/?ref=lbp 1/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Text Color</title>
<style>
center {
width: 50%;
margin: 0 auto;
}
h2, div, p, span {
padding: 10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<center>
<h2 style="background-color: gray;">
Heading with Gray Background color
</h2>
https://www.geeksforgeeks.org/html-colors/?ref=lbp 2/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
</center>
</body>
</html>
Output:
HTML Color
Color Values
Color values in HTML define the color of elements. They can be specified using
various formats such as hexadecimal, RGB, RGBA, HSL, HSLA, color names,
and system color keywords.
RGB, which stands for Red, Green, and Blue, is a method used in CSS to
describe colors. It works by mixing different amounts of three primary colors,
each with values ranging from 0 to 255. By adjusting these values, we can
produce an extensive range of colors, allowing for the creation of diverse and
better color palettes across websites.
// Blue background
<p style="background-color: rgb(0, 0, 255);">
Is the sky background Blue by using RGB
</p>
The example we are using the RGB color values to style our html elements.
HTML
<!DOCTYPE html>
<html>
<head>
<title>RGB Color Value</title>
<style>
center {
width: 50%;
margin: 0 auto;
}
https://www.geeksforgeeks.org/html-colors/?ref=lbp 4/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
h2,
div,
p,
span {
padding: 10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<center>
<h2 style="background-color: rgb(109, 102, 197);">
Heading with blue Background color
</h2>
</center>
</body>
</html>
Output:
https://www.geeksforgeeks.org/html-colors/?ref=lbp 5/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
In the above example the Heading exhibits a blue background using RGB
color value (109, 102, 197).
Div border is styled with skyblue using RGB color value (135, 206, 235).
Link text appears in tomato color using RGB value (241, 76, 89) for visual
distinction.
Paragraph text is styled with dark green using RGB value (0, 100, 0) for
readability.
https://www.geeksforgeeks.org/html-colors/?ref=lbp 6/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
In this example we are using the RGBA color values to style our html
elements.
HTML
<!DOCTYPE html>
<html>
<head>
<title>RGBA Color Value</title>
<style>
center {
width: 50%;
margin: 0 auto;
}
h2, div, p, span {
padding: 10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<center>
<h2 style="background-color: rgba(255, 99, 71, 0.5);">
Heading with semi-transparent Tomato Background color
</h2>
https://www.geeksforgeeks.org/html-colors/?ref=lbp 7/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
</center>
</body>
</html>
Output:
Hexadecimal color values, often referred to as hex values, use a six-digit code
made up of pairs of characters.
Hexadecimal values in CSS are represented as #rrggbb, where rr, gg, and
bb denote the intensity of red, green, and blue, respectively, ranging from
00 to ff.
This encoding allows for 16,777,216 unique color combinations, providing a
vast spectrum for web design.
For example, #ff0000 corresponds to red (max red, no green, no blue),
while #00ff00 represents green (max green, no red, no blue).
Black is denoted by #000000 (no red, no green, no blue), while white is
represented as #ffffff (max red, max green, max blue).
// Pinkish Background
<div style="background-color: #FF69B4;">
div has a pinkish background by using Hex
</div>
In this example we are using the HEX color values to style our html elements.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Hex Color Value</title>
<style>
center {
width: 50%;
margin: 0 auto;
}
h2, div, p, span {
padding: 10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<center>
https://www.geeksforgeeks.org/html-colors/?ref=lbp 9/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
</body>
</html>
Output:
In this example Heading Styled with a tomato background using hex color
value #FF6347.
Div Features an orange border using hex color value #FFA500.
Link Rendered with a deep sky blue color using hex value #00BFFF.
Paragraph Text is colored purple using hex value #800080.
https://www.geeksforgeeks.org/html-colors/?ref=lbp 10/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
// Golden Background
<div style="background-color: hsl(45, 100%, 50%);">
This div has a golden background using HSL
</div>
HTML
<!DOCTYPE html>
<html>
<head>
<title>HSL Color Value</title>
<style>
center {
width: 50%;
margin: 0 auto;
}
h2, div, p, span {
padding: 10px;
margin-bottom: 20px;
}
</style>
https://www.geeksforgeeks.org/html-colors/?ref=lbp 11/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
</head>
<body>
<center>
<h2 style="background-color: hsla(120, 100%, 50%, 0.5);">
Heading with semi-transparent
Green Background color
(HSL: hsla(120, 100%, 50%, 0.5))
</h2>
</body>
</html>
Output:
Colors in web design are used to convey emotion, establish hierarchy, improve
readability, and create visual interest, enhancing user experience.
To create a Color Generator, use HTML for layout, CSS for styling, and
JavaScript to handle user interactions, generating random colors dynamically.
To change the background color in HTML, use the CSS property “background-
color” and specify a color value for the desired background.
4.How to create Hex color generator using HTML CSS and JavaScript ?
To create a Hex color generator, use HTML for structure, CSS for styling, and
JavaScript to generate random Hexadecimal values.
5.How to create multicolored text in a web page using HTML and CSS ?
To create multicolored text, use HTML to structure content and CSS to apply
different colors to individual text elements or spans.
https://www.geeksforgeeks.org/html-colors/?ref=lbp 13/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
To add a color picker in a form, use the HTML input element with type “color”
to allow users to select colors.
“This course was packed with amazing and well-organized content! The
project-based approach of this course made it even better to understand
concepts faster. Also the instructor in the live classes is really good and
knowledgeable.”- Tejas | Deutsche Bank
With our revamped Full Stack Development Program: master Node.js and
React that enables you to create dynamic web applications.
So get ready for salary hike only with our Full Stack Development Course.
Previous Next
Similar Reads
React.js Blueprint Colors Core colors How to Change the Label Colors or the
Legend Colors in a Chart ?
How to set Bullet colors in HTML Lists Different ways to apply colors in an
using only CSS? HTML document
https://www.geeksforgeeks.org/html-colors/?ref=lbp 14/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
P pankaj_g…
Company Explore
About Us Hack-A-Thons
Legal GfG Weekly Contest
Careers DSA in JAVA/C++
In Media Master System Design
Contact Us Master CP
Advertise with us GeeksforGeeks Videos
GFG Corporate Solution Geeks Community
Placement Training Program
https://www.geeksforgeeks.org/html-colors/?ref=lbp 15/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
Tutorials Archive
https://www.geeksforgeeks.org/html-colors/?ref=lbp 17/18
4/1/24, 5:06 AM HTML Colors - HTML Color Types & Usage - GeeksforGeeks
https://www.geeksforgeeks.org/html-colors/?ref=lbp 18/18