Open In App

How to set the Text Color of HTML Element using CSS?

Setting the text colour of an HTML element using CSS involves using the color property. It allows you to define the colour of the text content within the selected element.

Note: The color property can take various colour values, such as named colours, hexadecimal, RGB, or HSL values.



Syntax:

p {
color: #336699;
}
h1 {
color: red;
}

The text color will be changed using the following methods :

Example:






<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>Color the Text</title>
    <style>
        .custom-text-color {
            color: #3498db;
        }
 
        #geeks {
            color: red;
        }
    </style>
</head>
 
<body>
    <p class="custom-text-color">
        This text will be colored using class
    </p>
    <span id="geeks">
        This text will be colored using id
    </span>
    <p style="color: #2ecc71;">
        This text is coloured using inline CSS.
    </p>
</body>
 
</html>

Output:

Features


Article Tags :