Cascading Style Sheets (CSS) is a versatile styling language that allows web developers to control the look and feel of websites. One of the most fundamental aspects of CSS is setting text color, which dramatically impacts the user experience, accessibility, and aesthetics of a webpage. Let's explore how to manipulate text color using CSS.

Before delving into the specifics, it's crucial to understand the CSS syntax for text color. The property to use is `color`, and its value can be specified in various ways. We'll outline these methods in the sections that follow.

Specifying Text Color
There are several ways to specify text color in CSS. The choice depends on your design, brand guidelines, or personal preference. Let's explore these methods.

Here are the primary ways to specify text color using the `color` property:
Named Colors

The `color` property accepts named color values, like 'black', 'white', 'red', 'blue', etc. There are 140 named colors in total, predefined in the CSS3 specification. This method is simple but offers limited control.
Here's an example: color: blue;
Hexadecimal Colors

Hexadecimal (hex) color codes allow for more control and precision. They are six-digit combinations of numbers and letters, starting with a '#' symbol. The first two digits represent the red value, the next two the green value, and the last two the blue value.
For instance, color: #FF0000; sets the text color to pure red.
Opacity and Text Color

Sometimes, you might want to display text with some transparency. CSS provides the `opacity` property to achieve this. It accepts a value between 0.0 (fully transparent) and 1.0 (fully opaque).
Here's an example of semi-transparent text: color: rgba(255, 0, 0, 0.5); sets the text color to semi-transparent red.










Changing Text Color Based on State
CSS allows you to change text color based on the element's state, which can be quite useful in various design scenarios.
Here's an example using pseudo-classes: a:hover { color: blue; } changes the color of text within anchor (`a`) tags when the mouse pointer hovers over them.
Dark Mode and Text Color
Dark mode is an increasingly popular feature that allows users to browse websites using a dark color scheme. Designing elements to accommodate both light and dark modes is essential for a consistent user experience.
You can use CSS variables with the `prefers-color-scheme` media query to create adaptive text color effects. Below is an example: ```css :root { --text: black; --bg: white; } @media (prefers-color-scheme: dark) { :root { --text: white; --bg: black; } } body { color: var(--text); background-color: var(--bg); } ```