HTML Colors 🎨

beginner
15 min

HTML Colors 🎨

Welcome to the HTML Colors Tutorial! Today, we'll learn how to use and manipulate colors in our HTML projects. 💡

What are HTML Colors?

HTML colors are used to paint the background and text of web pages. They are defined using color names, hex codes, RGB values, and HSL values. Let's explore each one! 📝

Color Names 💛

HTML supports a set of predefined color names. Here are some examples:

  • Red
  • Green
  • Blue
  • Yellow
  • Orange
  • Pink
  • Purple
Quick Quiz
Question 1 of 1

What is the color name for a bright pink shade?

Hex Codes 🌈

Hexadecimal color codes consist of six characters (0-9, A-F) and are more accurate than color names. Here's an example for blue:

html
<body style="background-color: #0000FF;">

Each pair of characters (0-F) represents a different color channel. In the example above, #0000FF corresponds to RGB (0,0,255), the purest shade of blue. ✅

RGB Values 🎨

RGB stands for Red, Green, and Blue. These values range from 0 to 255. Here's an example for yellow:

html
<body style="background-color: rgb(255, 255, 0);">

In this example, 255 for red and green, and 0 for blue creates a pure yellow background. ✅

HSL Values 🌈

HSL stands for Hue, Saturation, and Lightness. HSL is easier to understand as it represents color intuitively. Here's an example for yellow:

html
<body style="background-color: hsl(60, 100%, 50%);">

In this example, the hue is 60 degrees (yellow), saturation is 100% (pure color), and lightness is 50% (medium intensity). ✅

Playing with HTML Colors 🎨

Now let's create a simple web page that uses various color methods:

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML Colors</title> </head> <body> <h1 style="color: Red;">Welcome to HTML Colors!</h1> <h2 style="color: #FF0000;">Using Hex Codes for Color</h2> <h3 style="color: rgb(255, 0, 0);">RGB Values for Color</h3> <h4 style="color: hsl(0, 100%, 50%);">HSL Values for Color</h4> </body> </html>

Save this code in a file named colors.html and open it in your web browser to see the results! 🌟

Summary 💡

In this tutorial, we learned about HTML colors and their various representation methods: color names, hex codes, RGB values, and HSL values. We also created a simple web page demonstrating their usage. Happy coding! 🚀