Concept of HTML Colors

Concept of HTML Colors

4 mins read53 Views Comment
clickHere
Esha
Esha Gupta
Associate Senior Executive
Updated on Nov 24, 2023 13:54 IST

HTML Colors play a pivotal role in creating the visual identity of a webpage, influencing its aesthetics, readability, user experience, and even its brand messaging. Let us understand more!

2023_09_Copy-of-What-is-6.jpg

HTML colors are a way to add color to your web content, making it visually appealing and communicative. It is defined using a system of codes that tell browsers how to display a specific color. These codes can be in several formats: HEX codes, RGB values, HSL values, or even predefined color names.

Read Also: What is HTML

Explore Top HTML Interview Questions and Answers

 

The strategic use of color in web design goes beyond just beautifying a webpage. Here’s why HTML colors matter:

  1. Companies often choose colors that align with their brand message.
  2. Colors can be used strategically to draw attention to specific pieces of content.
  3. By understanding the psychology of colors, web designers can evoke specific emotions in their audience.

HTML Colors help us improve the overall user experience & engagement of our web content.

HTML colors are specified with predefined color names or with RGB, HSL, HEX, HSLA or RGBA values.

Must Read: Basic Structure of HTML

Let’s understand HTML Colors in detail:

1. Setting the Background Color for HTML Elements

Let’s see an example to understand this


 
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:AliceBlue;">AliceBlue</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:Crimson;">Crimson</h1>
<h1 style="background-color:Aqua;">Aqua</h1>
<h1 style="background-color:DeepPink;">DeepPink</h1>
</body>
</html>
Copy code

Output

2023_09_Screenshot-2023-09-01-123139.jpg

The main purpose of this HTML code is to display five headings with different background colors corresponding to the color names they showcase. This is a simple way to display and demonstrate various color names in HTML.

2. Setting the Color of the Text

Let’s see an example to understand this


 
<!DOCTYPE html>
<html>
<body>
<h2 style="color:DarkViolet;">Hello World</h2>
<p style="color:FireBrick;">Let's understand the concept of HTML Colors with Shiksha Online. Study harder to grow smarter</p>
<p style="color:OrangeRed;">Checkout our blogs on different streams, topics both tech & non-tech. Keep exploring!</p>
</body>
</html>
Copy code

Output

2023_09_Screenshot-2023-09-01-124424.jpg

This webpage visually presents a series of text elements with varying colors to demonstrate the use and effect of different HTML color values on text elements.

 

3. Setting the Color of Borders

Let’s see an example to understand this.


 
<!DOCTYPE html>
<html>
<body>
<h1 style="border: 5px solid Salmon;">Welcome to Shiksha Online</h1>
<h1 style="border: 5px solid Violet;">Welcome to Shiksha Online</h1>
<h1 style="border: 5px solid Teal;">Welcome to Shiksha Online</h1>
</body>
</html>
Copy code

Output

2023_09_Screenshot-2023-09-01-142136.jpg

This webpage visually demonstrates the application of different border colors around text elements.

HTML supports 140 standard color names. You can choose any color out of those & use it accordingly to decorate your web page.

How to Create HTML Forms – Tutorial with Examples
How to Create HTML Forms – Tutorial with Examples
HTML forms are a part of a document that can help you collect some data from the site visitor. Through this guide, you will understand how to create the HTML...read more
Creating HTML Tables (Tutorial With Examples)
Creating HTML Tables (Tutorial With Examples)
This guide offers an introduction to HTML tables. You will learn how to create tables in HTML to present tabular data.
Top Features of HTML5 With Examples
Top Features of HTML5 With Examples
HTML5 is the latest version of Hypertext Markup Language, used for structuring content on the web. It introduces new elements, multimedia support, and improved semantics, making it essential for modern...read more

4. Specifying Colors in HTML Using RGB, HEX, HSL, RGBA, and HSLA values.

Let’s see an example to understand this.


 
<!DOCTYPE html>
<html>
<body>
<p>Exploring the shade "Coral":</p>
<h1 style="background-color:rgb(255, 127, 80);">RGB: (255, 127, 80)</h1>
<h1 style="background-color:#ff7f50;">HEX: #ff7f50</h1>
<h1 style="background-color:hsl(16, 100%, 66%);">HSL: (16, 100%, 66%)</h1>
<p>Coral shade with reduced opacity:</p>
<h1 style="background-color:rgba(255, 127, 80, 0.5);">RGBA: (255, 127, 80, 0.5)</h1>
<h1 style="background-color:hsla(16, 100%, 66%, 0.5);">HSLA: (16, 100%, 66%, 0.5)</h1>
<p>Beyond standard colors, we have options to use RGB, HEX, HSL, and for adding transparency, there's RGBA and HSLA.</p>
</body>
</html>
Copy code

Output

2023_09_Screenshot-2023-09-01-143926.jpg

The code visually demonstrates how a single color (“Coral”) can be represented using different color specification methods in web design. It effectively teaches the viewers how to specify RGB, HEX, HSL, RGBA, and HSLA Values.

Let’s break down the values set for each color specification method in the above code.

1. RGB: Red-Green-Blue
Example: rgb(255, 127, 80)

This method represents colors based on their Red, Green, and Blue components.
Each value can range between 0 and 255.
In the example, the RGB values break down as follows:

Red: 255 (full intensity)
Green: 127 (approximately half intensity)
Blue: 80

2. HEX: Hexadecimal
Example: #ff7f50

Colors are represented using hexadecimal values. The first two characters after the # represent the Red component, the next two represent the Green component, and the last two represent the Blue component.
The values range from 00 (lowest intensity) to FF (highest intensity).
Breaking down the HEX values:

Red: ff (equivalent to 255 in decimal)
Green: 7f (equivalent to 127 in decimal)
Blue: 50 (equivalent to 80 in decimal)

3. HSL: Hue-Saturation-Lightness
Example: hsl(16, 100%, 66%)

This method represents colors based on their hue, saturation, and lightness values.
Hue: A value between 0 and 360, representing the position on a color wheel.
16 indicates a color close to red-orange.
Saturation: A percentage that indicates the intensity of the color.
100% means fully saturated.
Lightness: A percentage where 0% is black, 100% is white, and 50% is the normal color.
66% means it’s lighter than the base color.

4. RGBA: Red-Green-Blue-Alpha
Example: rgba(255, 127, 80, 0.5)

Like RGB, but with an additional alpha (A) value for transparency.
Alpha ranges from 0 (fully transparent) to 1 (fully opaque).
The example uses:
Red: 255
Green: 127
Blue: 80
Alpha: 0.5 (50% opacity)

5. HSLA: Hue-Saturation-Lightness-Alpha
Example: hsla(16, 100%, 66%, 0.5)

Like HSL, but with an additional alpha value for transparency.
The example uses:
Hue: 16
Saturation: 100%
Lightness: 66%
Alpha: 0.5 (50% opacity)

All these methods are set to represent approximately the same colour (Coral) but with varying methods of definition. The RGBA and HSLA versions additionally have 50% transparency.

How to Create HTML Forms – Tutorial with Examples
How to Create HTML Forms – Tutorial with Examples
HTML forms are a part of a document that can help you collect some data from the site visitor. Through this guide, you will understand how to create the HTML...read more

HTML Full Form
HTML Full Form
HTML, an acronym for Hypertext Markup Language, is a fundamental building block of the World Wide Web. It is a markup language used to structure and present content on the...read more

HTML Tags: Essential and Basic Tags for Creating an HTML Document
HTML Tags: Essential and Basic Tags for Creating an HTML Document
HTML tags form the basic structure of any webpage or HTML document. In this blog, we will discuss some essential and basic HTML tags with examples.

Creating HTML Tables (Tutorial With Examples)
Creating HTML Tables (Tutorial With Examples)
This guide offers an introduction to HTML tables. You will learn how to create tables in HTML to present tabular data.

HTML Attributes Explained with Examples
HTML Attributes Explained with Examples
HTML attributes provide additional information about HTML elements. They are used to modify the behavior or appearance of an element. Attributes are specified within the opening tag of an element...read more

HTML Lists: Ordered and Unordered Lists Explained with Examples
HTML Lists: Ordered and Unordered Lists Explained with Examples
This tutorial explains how to create different types of lists: unordered, ordered, and description lists in HTML.

A Guide to Semantic Tags in HTML
A Guide to Semantic Tags in HTML
Have you ever heard about semantic tags in HTML? These tags give meaning to your web content, making it more accessible and understandable both to users and search engines. They...read more

Understanding HTML Doctype
Understanding HTML Doctype
HTML Doctype is basically an instruction given to the web browser about what version of the markup language the page is written in.

Mastering HTML Layout: A Comprehensive Guide to HTML and CSS Techniques
Mastering HTML Layout: A Comprehensive Guide to HTML and CSS Techniques
Semantic and non-semantic elements in HTML layout and techniques work together to structure and style web content. Techniques like CSS Flexbox, CSS Grid, and media queries enhance the design, ensuring...read more

HTML Iframe (With Examples)
HTML Iframe (With Examples)
An HTML iframe is an HTML tag that allows you to embed another HTML document within a current HTML document. Importance of Using HTML iframes. Let’s see some main attributes...read more

Conclusion

HTML colors play a pivotal role in shaping web content’s visual aesthetics and user experience. Impacting readability, accessibility, branding, and even user emotions. When chosen thoughtfully, colors can transform a simple webpage into a memorable user journey, underlining that every hue truly matters in web design. Keep learning, Keep exploring!

Download this article as PDF to read offline

Download as PDF
clickHere
About the Author
author-image
Esha Gupta
Associate Senior Executive

I'm Esha Gupta, a B.Tech graduate in Computer Science & Engineering, specializing in Front End Web Dev. I've interned at GeeksforGeeks & Coding Minutes, fueling my passion for crafting appealing and functional digit... Read Full Bio

Comments

We use cookies to improve your experience. By continuing to browse the site, you agree to our Privacy Policy and Cookie Policy.