In CSS, you can set the color of text using various methods. Here are the different ways to specify text color:
Color Names: CSS provides a set of predefined color names that you can use to specify the color of text. For example:
p {
color: red;
}
Hexadecimal Notation: You can use hexadecimal values to define text color. Hexadecimal values are preceded by a pound sign (#) followed by a combination of three or six hexadecimal digits. For example:
p {
color: #FF0000; /* Red */
}
RGB Notation: RGB notation allows you to specify text color using the Red, Green, and Blue color channels. Each channel is represented by a value ranging from 0 to 255. For example:
p {
color: rgb(255, 0, 0); /* Red */
}
RGBA Notation: RGBA notation is an extension of RGB notation that includes an alpha channel for specifying transparency. The alpha channel ranges from 0 (fully transparent) to 1 (fully opaque). For example:
p {
color: rgba(255, 0, 0, 0.5); /* Semi-transparent red */
}
HSL Notation: HSL notation allows you to define text color using the Hue, Saturation, and Lightness values. Hue is represented as an angle from 0 to 360 degrees, while Saturation and Lightness are percentages ranging from 0% to 100%. For example:
p {
color: hsl(0, 100%, 50%); /* Red */
}
HSLA Notation: HSLA notation is an extension of HSL notation that includes an alpha channel for specifying transparency. The alpha channel ranges from 0 (fully transparent) to 1 (fully opaque). For example:
p {
color: hsla(0, 100%, 50%, 0.5); /* Semi-transparent red */
}
These are the main methods for specifying text color in CSS. By using these color options, you can customize the appearance of text on your web page and achieve the desired visual style.