HTML colors are defined using hexadecimal notation, which consists of a hash sign (#) followed by a combination of six characters that represent the intensity of red (R), green (G), and blue (B) channels. This system is known as RGB (Red-Green-Blue) color model. Each channel can have a value ranging from 00 (minimum intensity) to FF (maximum intensity), giving a total of 16,777,216 possible colors.

Colors in HTML

Here are some examples of HTML colors:

1. Black: #000000

This color has no intensity in any of the RGB channels, resulting in pure black.

2. White: #FFFFFF

This color has maximum intensity (FF) in all three RGB channels, resulting in pure white.

3. Red: #FF0000

This color has maximum intensity (FF) in the red channel, while the green and blue channels have no intensity (00), resulting in pure red.

4. Green: #00FF00

This color has maximum intensity (FF) in the green channel, while the red and blue channels have no intensity (00), resulting in pure green.

5. Blue: #0000FF

This color has maximum intensity (FF) in the blue channel, while the red and green channels have no intensity (00), resulting in pure blue.

6. Yellow: #FFFF00

This color has maximum intensity (FF) in the red and green channels, while the blue channel has no intensity (00), resulting in a combination of red and green, which gives yellow.

7. Purple: #800080

This color has a medium intensity (80) in both the red and blue channels, while the green channel has no intensity (00), resulting in a deep purple color.

8. Orange: #FFA500

This color has maximum intensity (FF) in the red channel, a medium intensity (A5) in the green channel, and no intensity (00) in the blue channel, resulting in a vibrant orange color.

RGB and RGBA colors in HTML

In addition to hexadecimal notation, HTML also supports RGB (Red-Green-Blue) and RGBA (Red-Green-Blue-Alpha) color notations. These notations allow you to specify colors using decimal values for the intensity of each channel, providing more flexibility in color selection.

1. RGB Colors:

The rgb() method is used to define RGB colors, which are then followed by three numbers that reflect the strength of the red, green, and blue channels. The intensity values can be between 0 and 255. Here are few instances:

  • Red: rgb(255, 0, 0)
  • Green: rgb(0, 255, 0)
  • Blue: rgb(0, 0, 255)
  • Yellow: rgb(255, 255, 0)
  • Purple: rgb(128, 0, 128)
  • Orange: rgb(255, 165, 0)

2. RGBA Colors:

Similar to RGB colors, RGBA colors also have a value for the alpha channel, which governs how transparent the color is. From 0.0 (totally transparent) to 1.0 (entirely opaque), the alpha channel value may be found. Here are a few demonstrations:

  • Semi-transparent black: rgba(0, 0, 0, 0.5)
  • Semi-transparent white: rgba(255, 255, 255, 0.5)
  • Semi-transparent red: rgba(255, 0, 0, 0.5)
  • Semi-transparent green: rgba(0, 255, 0, 0.5)
  • Semi-transparent blue: rgba(0, 0, 255, 0.5)

The RGB and RGBA color notations provide more flexibility and control over the colors you can use in HTML. They allow you to specify precise intensity values for each color channel and adjust the transparency if needed.

HEX Colors in HTML

HTML HEX colors are defined using hexadecimal notation, which consists of a hash sign (#) followed by a combination of six characters representing the intensity of red (R), green (G), and blue (B) channels. Each channel can have a value ranging from 00 (minimum intensity) to FF (maximum intensity), giving a total of 16,777,216 possible colors.

Following are some demonstrations of HTML HEX colors:

1. Black: #000000

This color has no intensity in any of the RGB channels, resulting in pure black.

2. White: #FFFFFF

This color has maximum intensity (FF) in all three RGB channels, resulting in pure white.

3. Red: #FF0000

This color has maximum intensity (FF) in the red channel, while the green and blue channels have no intensity (00), resulting in pure red.

4. Green: #00FF00

This color has maximum intensity (FF) in the green channel, while the red and blue channels have no intensity (00), resulting in pure green.

5. Blue: #0000FF

This color has maximum intensity (FF) in the blue channel, while the red and green channels have no intensity (00), resulting in pure blue.

6. Yellow: #FFFF00

This color has maximum intensity (FF) in the red and green channels, while the blue channel has no intensity (00), resulting in a combination of red and green, which gives yellow.

7. Purple: #800080

This color has a medium intensity (80) in both the red and blue channels, while the green channel has no intensity (00), resulting in a deep purple color.

8. Orange: #FFA500
This color has maximum intensity (FF) in the red channel, a medium intensity (A5) in the green channel, and no intensity (00) in the blue channel, resulting in a vibrant orange color.

HSL and HSLA Colors in HTML


HTML HSL (Hue-Saturation-Lightness) and HSLA (Hue-Saturation-Lightness-Alpha) colors provide an alternative way to define colors using a different color model. HSL colors represent colors based on their hue, saturation, and lightness values, allowing for more intuitive color selection and manipulation.
HTML HSL (Hue-Saturation-Lightness) and HSLA (Hue-Saturation-Lightness-Alpha) colors provide an alternative way to define colors using a different color model. HSL colors represent colors based on their hue, saturation, and lightness values, allowing for more intuitive color selection and manipulation.

Here’s the definition and examples of HTML HSL and HSLA colors:

1. HSL Colors:

The hsl() function is used to define HSL colors, which are then followed by three values that stand for hue, saturation, and lightness. The hue value, which represents the color wheel, runs from 0 to 360. Values for brightness and saturation vary from 0% to 100%. Here are a few demonstration:

  • Red: hsl(0, 100%, 50%)
  • Green: hsl(120, 100%, 50%)
  • Blue: hsl(240, 100%, 50%)
  • Yellow: hsl(60, 100%, 50%)
  • Purple: hsl(300, 100%, 25%)
  • Orange: hsl(30, 100%, 50%)

2. HSLA Colors:

While HSLA colors are identical to HSL colors, they also provide a value for the alpha channel, which governs how transparent the color is. From 0.0 (totally transparent) to 1.0 (entirely opaque), the alpha channel value may be found. Here are a few demonstration:

  • Semi-transparent black: hsla(0, 0%, 0%, 0.5)
  • Semi-transparent white: hsla(0, 0%, 100%, 0.5)
  • Semi-transparent red: hsla(0, 100%, 50%, 0.5)
  • Semi-transparent green: hsla(120, 100%, 50%, 0.5)
  • Semi-transparent blue: hsla(240, 100%, 50%, 0.5)

The HSL and HSLA color notations provide a different way to define and manipulate colors in HTML. By using hue, saturation, and lightness values, you can have more control over the color appearance, and the alpha channel in HSLA allows for transparency effects if desired.

CSS styles for HTML

HTML Styles refers to the use of CSS (Cascading Style Sheets) to define the visual appearance and formatting of HTML elements. CSS allows you to apply styles to various elements on a webpage, controlling attributes such as colors, fonts, spacing, and layout. It provides a powerful and flexible way to enhance the presentation of HTML content.

Here’s a brief definition and examples of CSS styles in HTML:

1. Inline Styles:

Through the use of the style property, inline styles are directly applied to specific HTML components. Using double quotes, this attribute includes pairs of CSS property-value pairs. Here is an demonstration:

<h1 style="color: blue; font-size: 24px;">Hello, World!</h1>

In this example, the h1 element has an inline style that sets the text color to blue and the font size to 24 pixels.

2. Internal Stylesheet:

The <style> element in the <head> section of an HTML page defines an internal stylesheet. In a single file, you may define styles for several components. Here’s an demonstration:

<head>
  <style>
    h1 {
      color: blue;
      font-size: 24px;
    }
  </style>
</head>
<body>
  <h1>Hello, World!</h1>
</body>
<head>
  <style>
    h1 {
      color: blue;
      font-size: 24px;
    }
  </style>
</head>
<body>
  <h1>Hello, World!</h1>
</body>

In this example, the <style> element contains CSS rules that define the styles for all h1 elements in the document. The h1 elements will have blue text color and a font size of 24 pixels.

3. External Stylesheet:

An external stylesheet is a separate CSS file that is linked to an HTML document using the <link> element. This method allows you to define styles in a separate file, making it reusable across multiple HTML pages. Here’s an example:

HTML file:

<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <h1>Hello, World!</h1>
</body>

styles.css file:

h1 {
  color: blue;
  font-size: 24px;
}

In this example, the HTML file includes an external stylesheet file, styles.css, which contains the CSS rules for the h1 element. The styling will be applied to the h1 element in the HTML file.

Categorized in: