CSS
CSS – How to Change Text Color? (Simplest Guidance)
One of the first and most essential things you learn in CSS is how to change the color of text. Whether you’re building a personal blog, a product page, or a landing screen, using the right text color enhances readability and visual appeal.
In this post, we’ll walk you through the simplest way to change text color using CSS, with examples for absolute beginners.
🎨 The CSS Property: color
In CSS, the color
property is used to set the text color of an element.
📌 Basic Syntax:
selector {
color: value;
}
Where:
selector
is the HTML element or class you want to stylevalue
is the color you want to apply (e.g., name, hex code, RGB, etc.)
✅ Example 1: Change Paragraph Text to Red
HTML:
<p class="red-text">This is a red paragraph.</p>
CSS:
.red-text {
color: red;
}
✅ Result: The paragraph text will appear red.
🎨 Different Ways to Define Colors
CSS supports several formats to define colors:
Format | Example | Notes |
---|---|---|
Color name | color: blue; | Easiest to use |
Hex code | color: #ff0000; | Common in design tools |
RGB | color: rgb(255, 0, 0); | Red-Green-Blue format |
RGBA | color: rgba(255, 0, 0, 0.5); | Adds transparency |
HSL | color: hsl(0, 100%, 50%); | Hue-Saturation-Lightness |
✅ Example 2: Change Heading Text Using Hex Color
HTML:
<h1 class="custom-heading">Welcome!</h1>
CSS:
.custom-heading {
color: #3498db; /* Light blue */
}
✅ Example 3: Transparent Text Using RGBA
CSS:
.transparent-text {
color: rgba(0, 0, 0, 0.6); /* 60% opacity black */
}
Great for muted or secondary text.
🎯 Targeting Different Elements
You can apply text color to almost any text-based HTML element:
h1, h2, h3 {
color: #222;
}
p {
color: gray;
}
a {
color: green;
}
👀 Quick Styling Tip
If you’re using dark backgrounds, make sure to use light text (e.g., white, light gray), and vice versa for readability.
📝 Summary
Task | Code |
---|---|
Change text to red | color: red; |
Use hex color | color: #ff9900; |
Add transparency | color: rgba(0,0,0,0.5); |
Target element | p { color: blue; } |
✅ Conclusion
Changing text color with CSS is one of the easiest and most powerful ways to customize your web page. Just use the color
property and choose from a variety of formats like named colors, hex codes, or RGB.
Start simple, then get creative with transparent colors, gradients, and themes as you learn more.