HTML Colors can be applied to text, backgrounds, borders, links, forms, tables, etc. This article provides an in-depth look at how colors can be applied to various elements such as text, backgrounds, borders, links, forms, and tables in HTML. We will explore different color formats including hexadecimal, RGB, RGBA, HSL, and named colors, offering you precise control over the color presentation on your web pages.
HTML Colors Name
HTML color names offer a user-friendly way to specify colors. From classic colors like Red, Green, Blue, Pink, Purple, Sky Blue, Gray, and Orange, to more exotic shades, HTML provides a wide palette for web designers. Whether you’re designing a serene theme or a vibrant layout, HTML color names have got you covered.
Red
Green
Blue
Pink
Purple
Sky Blue
Gray
Orange
Checkout Color Wheel Tool on GFG: Color Wheel
HTML Color Usage
Usage | Descriptions | Syntax |
---|
Background Color | HTML Background Color is the shade that appears behind the content on a webpage. The background covers the total size of the element with padding and border but excludes the margin. It makes the text so easy to read for the user. | <div style="background-color: magenta;"> Div with magenta background </div> |
Text Color | Text color in HTML specifies the color of the text content, similar to font color. | <p style="color: pink;"> Pink color is used </p> |
Border Color | HTML Border Color refers to the color of borders around elements like <div>, <img>, etc. It defines the color of the border lines. | <div style="border: 1px solid black; border-color: green;"> This div has a green border </div> |
Link Color | HTML Link Color specifies the color of the anchor tag within a webpage, allowing us to define the color of clickable text, and making user navigation more visual. | <a href="#" style="color: blue;"> Link has a blue color </a> |
HTML Colors Example:
The example illstrates the various HTML Colors to the element.
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>
<div style="border: 2px solid skyblue;">
Div with Skyblue Border color
</div>
<span >
<a href="#" style="color: #ff6347;">
Link has a tomato color
</a>
</span>
<p style="color: darkgreen;">
Paragraph with Dark Green Text color
</p>
</center>
</body>
</html>
Output:
HTML ColorHTML Colors Example Explanation:
- In this example we create HTML to structure content with elements like headings, divs, links, and paragraphs.
- Heading displays a gray background for emphasis.
- Div is bordered with skyblue color for visual distinction.
- Link text appears in tomato color for better visibility.
- Paragraph text is styled with a dark green color for readability.
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 Color Value
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.
RGB Color Value Properties
Some properties are:
- It's representation is as rgb(red, green, blue).
- By adjusting these values from 0 to 255, we can produce 16,777,216 unique colors.
- For instance, specifying rgb(0, 255, 0) results in green because the green value is at its maximum (255), while red and blue are at 0. Conversely, using rgb(0, 0, 255) produces blue, with the blue channel set to its peak (255), and red and green at 0.
- To render black, all color parameters are set to 0 (rgb(0, 0, 0)), and for white, all parameters are set to their maximum (rgb(255, 255, 255)).
RGB Color Value Syntax
// Blue background
<p style="background-color: rgb(0, 0, 255);">
Is the sky background Blue by using RGB
</p>
RGB Color Value Example
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;
}
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>
<div style="border: 2px solid rgb(135, 206, 235);">
<li>
<a href="#html-color-usage">
HTML Color Usage
</a>
</li>
Div with Skyblue Border color
</div>
<span>
<a href="#" style="color: rgb(241, 76, 89);">
Link has a tomato color
</a>
</span>
<p style="color: rgb(0, 100, 0);">
Paragraph with Dark Green Text color
</p>
</center>
</body>
</html>
Output:

RGB Color Value Example Explanation
Here is the implementation of above example.
- 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.
RGBA Color Value
RGBA (Red, Green, Blue, Alpha) is a color model similar to RGB, but with an added alpha parameter representing transparency. The alpha value, which ranges from 0 to 1, adjusts transparency, allowing the display of colors with varying levels of opacity. It's representation is as rgba(red, green, blue, alpha).
RGBA Color values Properties
- RGBA Format Represents colors using Red, Green, Blue, and Alpha (transparency) values, allowing control over opacity.
- Alpha value ranges from 0 (fully transparent) to 1 (fully opaque).
- RGBA values are expressed as rgba(red, green, blue, alpha).
- Ideal for creating semi-transparent elements, providing subtle visual effects or layering content.
RGBA Color Value Syntax
// Semi-transparent text with a purple hue
<span style="color: rgba(128, 0, 128, 0.5);">
This text is semi-transparent with a purple hue using RGBA
</span>
RGBA Color Value Example
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>
<div style="border: 2px solid rgba(255, 165, 0, 0.7);">
Div with semi-transparent Orange Border color
</div>
<span>
<a href="#"
style="color: rgba(0, 191, 255, 0.8);">
Link has a semi-transparent Deep Sky Blue color
</a>
</span>
<p style="color: rgba(128, 0, 128, 0.6);">
Paragraph with semi-transparent Purple Text color
</p>
</center>
</body>
</html>
Output:
RGBA color valueRGBA Color Value Example Explanation:
- Here we styled Heading with semi-transparent tomato background color using RGBA (255, 99, 71, 0.5).
- Div Exhibits a semi-transparent orange border with RGBA (255, 165, 0, 0.7).
- Link Displays a semi-transparent deep sky blue color using RGBA (0, 191, 255, 0.8).
- In Paragraph Text appears semi-transparent purple with RGBA (128, 0, 128, 0.6).
HEX Color Value
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).
HEX Color Value Syntax
// Pinkish Background
<div style="background-color: #FF69B4;">
div has a pinkish background by using Hex
</div>
HEX Color Value Example:
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>
<h2 style="background-color: #FF6347;">
Heading with semi-transparent
Tomato Background color (Hex: #FF6347)
</h2>
<div style="border: 2px solid #FFA500;">
Div with semi-transparent
Orange Border color (Hex: #FFA500)
</div>
<span>
<a href="#" style="color: #00BFFF;">
Link has a semi-transparent
Deep Sky Blue color (Hex: #00BFFF)
</a>
</span>
<p style="color: #800080;">
Paragraph with semi-transparent
Purple Text color (Hex: #800080)
</p>
</center>
</body>
</html>
Output:
hex color valueHEX Color Value Explanation:
- 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.
HSL (Hue, Saturation, Lightness) Value
HSL color values in HTML represent colors by defining their hue, saturation, and lightness. The hue signifies the type of color (red, blue, green, etc.), saturation refers to the intensity or purity of the color, and lightness determines the brightness or darkness.
HSL Color value Properties:
- HSL representation defines colors based on Hue, Saturation, and Lightness components, offering a more intuitive way to specify colors.
- Hue represents the color type, ranging from 0 to 360 degrees.
- Saturation determines the intensity or purity of the color, from 0% (grayscale) to 100% (full color).
- Lightness controls the brightness of the color, ranging from 0% (black) to 100% (white), with 50% representing normal.
HSL Color value Syntax
// Golden Background
<div style="background-color: hsl(45, 100%, 50%);">
This div has a golden background using HSL
</div>
HSL color value Example:
The example shows the HSL color values.
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>
</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>
<div style="border: 2px solid hsla(240, 100%, 50%, 0.7);">
Div with semi-transparent
Blue Border color
(HSL: hsla(240, 100%, 50%, 0.7))
</div>
<span>
<a href="#" style="color: hsla(30, 100%, 50%, 0.8);">
Link has a semi-transparent
Orange color
(HSL: hsla(30, 100%, 50%, 0.8))
</a>
</span>
<p style="color: hsla(0, 100%, 25%, 0.6);">
Paragraph with semi-transparent
Red Text color
(HSL: hsla(0, 100%, 25%, 0.6))
</p>
</center>
</body>
</html>
Output:
hsl color valueHSL Color value Explanation:
- In this example HSLA(120, 100%, 50%, 0.5) creates a semi-transparent green background for the heading with 50% opacity.
- HSLA(240, 100%, 50%, 0.7) sets a semi-transparent blue border for the div with 70% opacity.
- HSLA(30, 100%, 50%, 0.8) defines a semi-transparent orange color for the link with 80% opacity.
- HSLA(270, 100%, 25%, 0.6) specifies semi-transparent purple text for the paragraph with 60% opacity.
HTML Colors in Web Development
Similar Reads
HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
11 min read
Basics
HTML IntroductionHTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam
6 min read
HTML EditorsAn HTML Editor is a software application designed to help users create and modify HTML code. It often includes features like syntax highlighting, tag completion, and error detection, which facilitate the coding process. There are two main types of HTML editors: Text-Based Editors - Allow direct codi
5 min read
HTML BasicsHTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over
7 min read
HTML Structure & Elements
HTML ElementsAn HTML Element consists of a start tag, content, and an end tag, which together define the element's structure and functionality. Elements are the basic building blocks of a webpage and can represent different types of content, such as text, links, images, or headings.For example, the <p> ele
5 min read
HTML AttributesHTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behavior, appearance, or functionality in a variety of ways. Each attribute has a name and a value
8 min read
HTML HeadingsHTML headings are used to define the titles and subtitles of sections on a webpage. They help organize the content and create a structure that is easy to navigate.Proper use of headings enhances readability by organizing content into clear sections.Search engines utilize headings to understand page
4 min read
HTML ParagraphsA paragraph in HTML is simply a block of text enclosed within the <p> tag. The <p> tag helps divide content into manageable, readable sections. Itâs the go-to element for wrapping text in a web page that is meant to be displayed as a distinct paragraph.Syntax:<p> Some Content...
5 min read
HTML Text FormattingHTML text formatting refers to the use of specific HTML tags to modify the appearance and structure of text on a webpage. It allows you to style text in different ways, such as making it bold, italic, underlined, highlighted, or struck-through. Table of ContentCategories of HTML Text FormattingLogic
4 min read
HTML Block and Inline ElementsHTML elements are either block-level, which structure the layout and span full width (like <div> or <p>), or inline, which styles content within blocks without breaking the flow (like <span> or <a>). This distinction covers 80â90% of common HTML usage.Inline and Block Level E
3 min read
HTML CharsetsHTML charsets define how characters are represented in a web document. The character encoding ensures that text appears correctly across different devices and platforms.The <meta> tag's charset attribute is used to specify which character encoding the HTML document uses. By setting the charset
4 min read
HTML List
HTML Visuals & Media
HTML ColorsHTML Colors can be applied to text, backgrounds, borders, links, forms, tables, etc. This article provides an in-depth look at how colors can be applied to various elements such as text, backgrounds, borders, links, forms, and tables in HTML. We will explore different color formats including hexadec
11 min read
HTML Links HyperlinksHTML Links, also known as hyperlinks, are defined by the <a> tag in HTML, which stands for "anchor." These links are essential for navigating between web pages and directing users to different sites, documents, or sections within the same page. The basic attributes of the <a> tag include
3 min read
HTML ImagesThe HTML <img> tag is used to embed an image in web pages by linking them. It creates a placeholder for the image, defined by attributes like src, width, height, and alt, and does not require a closing tag.There are two ways to insert the images into a webpage:By providing a full path or addre
7 min read
HTML FaviconA favicon (short for "favorite icon") is a small yet important image that appears next to your websiteâs title in the browser tab. Also known as a tab icon or bookmark icon, it helps users quickly identify and return to your site. Studies show that over 85% of users rely on visual cues like favicons
4 min read
HTML VideoThe <video> element in HTML is used to show video content on web pages. It supports various video formats, including MP4, WebM, and Ogg. It is introduced in HTML5.Scroll down to the End, there is a Tutorial Video which is a live example of the Video Element displaying on this webpage.Syntax:
4 min read
HTML Layout & Design
HTML TablesHTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over
10 min read
HTML IframesAn iframe, or Inline Frame, is an HTML element represented by the <iframe> tag. It functions as a 'window' on your webpage through which visitors can view and interact with another webpage from a different source.Iframes are used for various purposes like:Embedding Multimedia: Easily integrate
4 min read
HTML LayoutHTML layouts are a technique used to divide a web page into multiple sections, making it easier to apply styles, organize content, and manage operations efficiently. This division improves readability, accessibility, and overall user experience.HTML layout is achieved through elements like <heade
4 min read
HTML File PathsHTML file paths specify the location of files or resources that a webpage needs to access, such as images, videos, scripts, or other HTML documents. These paths tell the web browser where to find the files required to display the content correctly or to execute scripts as intended. To insert a file
3 min read
HTML Projects& Advanced Topics
HTML FormsHTML forms, defined using the <form> Tags are essential for collecting user input on web pages. They incorporate a variety of interactive controls such as text fields, numeric inputs, email fields, password fields, checkboxes, radio buttons, and submit buttons. Over 85% of websites rely on for
5 min read
HTML5 SemanticsHTML5 introduced a range of semantic elements that clearly describe their purpose in human and machine-readable language. Unlike non-semantic elements, which provide no information about their content, semantic elements clearly define their content. For instance, <form>, <table>, and
6 min read
HTML URL EncodingA Uniform Resource Locator (URL) is simply the address of a website to access the website content. Web browsers retrieve pages from web servers using a URL (Uniform Resource Locator).What is URL Encoding?URL Encoding is the process of converting the URL into a valid format that is accepted by web br
4 min read
HTML Responsive Web DesignHTML Responsive Web Design is a modern approach to web development that ensures web pages look great on any device, from phones and tablets to desktop computers. It focuses on making HTML elements automatically adjustâresizing, hiding, or repositioning based on the screen size. This approach guarant
11 min read
Top 10 Projects For Beginners To Practice HTML and CSS SkillsLearning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis
8 min read
HTML Tutorial References
HTML Tags - A to Z ListHTML Tags are fundamental elements used to structure and format content on web pages. They provide instructions to web browsers on how to render text, images, links, and other media.HTML tags are enclosed in angle brackets < > and usually come in pairs: an opening tag and a closing tag. The cl
15+ min read
HTML Attributes Complete ReferenceHTML attributes are special words placed inside the opening tag of an HTML element to define its characteristics. Each attribute has two parts:Attribute nameAttribute value (separated by an equal sign = and enclosed in double quotes " ").Syntax:<tag_name attribute_name="value"> Contents...
8 min read
HTML Global AttributesHTML attributes provide additional information about an element and define its properties. Global attributes are special types of attributes that can be used with any HTML element, offering common functionality to enhance behavior and presentation.Global attributes can be applied to any HTML element
5 min read
HTML5 Complete ReferenceHTML (HyperText Markup Language) is the standard language used to create and design web pages. It defines the structure and layout of a webpage using a series of elements and tags.HTML5 is the latest version of HTML, bringing significant improvements for building modern web applications.It introduce
8 min read
HTML5 MathML Complete ReferenceThe MathML comes in HTML5. The current MathML version is 3. It was introduced in the year 2015. MathML stands for Mathematics Markup Language. It is used to represent mathematical equations or expressions in web browsers, like other HTML elements. MathML is used to describe mathematics as a basis fo
3 min read
HTML DOM Complete ReferenceHTML DOM (Document Object Model) is a programming interface that represents the elements of an HTML document in a tree-like structure.Allows developers to change content and layout using JavaScript.Enables dynamic updates and user interaction on websites.Facilitates the addition, removal, or modific
15+ min read
HTML DOM Audio/Video Complete ReferenceHTML DOM Audio/Video properties and methods allow developers to control audio and video elements programmatically.These controls include playing, pausing, stopping, and adjusting volume.DOM methods enable dynamic interaction and customization of media elements.They enhance the user experience by off
2 min read
SVG Element Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Elements are the core things that is required to work with SVGs.List of SVG Elements:SVG ElementsDescription<a>The <a>
5 min read
SVG Attribute Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Attributes are the things that give the SVG shape, color, etc it will make the SVGs as attractive as you need.List of SVG Attribut
8 min read
SVG Property Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Properties are used for passing the value to the element, there are lots of properties that can be used in SVG elements. table{ di
7 min read
HTML Canvas Complete ReferenceThe HTML âcanvasâ element is used to draw graphics via JavaScript. The âcanvasâ element is only a container for graphics. One must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.Example: This example shows the basic
4 min read