In CSS (Cascading Style Sheets), the property used to change the color of the text is called color
. CSS is used in web development to design and build websites, specifying the look and format of a webpage.
The color property sets either foreground color (the text color) of an element or color of any specified generic CSS markers in lists.
As an example, consider the following sample HTML:
<p>This is some text!</p>
Let's change the color of the text to blue using the CSS color
property:
p {
color: blue;
}
After applying this CSS, the text in the <p>
element on the webpage will appear blue.
The color
property accepts values in several formats:
red
, blue
, green
, etc.#ff0000
for red, #0000ff
for blue, etc.rgb(255,0,0)
for red.rgba(255,0,0,0.5)
for semi-transparent red.The color
property inherits by default, which means that if you set the color property of a parent element, the child elements will inherit that color unless specified otherwise.
It's also good practice to ensure the color contrast between your text and its background is high enough to maintain readability, keeping in mind people with visual impairments.
Note that confusion sometimes arises due to the existence of the background-color
property in CSS, which as the name suggests, is used to change the color of the element's background, not the text.
Remember, while font-color
and text-color
might seem intuitive, they're not valid CSS properties. Always use the color
property to change text color in CSS.