Welcome to the HTML Colors Tutorial! Today, we'll learn how to use and manipulate colors in our HTML projects. 💡
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! 📝
HTML supports a set of predefined color names. Here are some examples:
What is the color name for a bright pink shade?
Hexadecimal color codes consist of six characters (0-9, A-F) and are more accurate than color names. Here's an example for blue:
<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 stands for Red, Green, and Blue. These values range from 0 to 255. Here's an example for yellow:
<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 stands for Hue, Saturation, and Lightness. HSL is easier to understand as it represents color intuitively. Here's an example for yellow:
<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). ✅
Now let's create a simple web page that uses various color methods:
<!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! 🌟
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! 🚀