Skip to content
Related Articles
Open in App
Not now

Related Articles

How to set the text-color for different elements in CSS ?

Improve Article
Save Article
  • Last Updated : 31 Mar, 2021
Improve Article
Save Article

Colors are very important to give a good look to the website and engage the users. So, different colored text elements are added to enhance the visuals of the webpage. The CSS color property defines the text color for an HTML element.

For setting text-color for different elements in CSS, add the appropriate CSS selector and define the color property with the required color value. 

Syntax : 


Note: There are different ways to specify the color values in CSS, for example using color keywords, RGB color values, Hexadecimal color values, and many more.

Example: In the following example, the heading is in green color as specified in <h3> styling tag, “content” class have grey color text while the text in ordinary <p> tag have black text color which is default text-color for the page as defined in the body selector.


<!DOCTYPE html>
      body {
        text-align: center;
        font-size: 15px;
        color: black;
      h3 {
        text-align: center;
        font-size: 60px;
        color: green;
      p.content {
        color: grey;
    <p>A Computer Science portal for geeks</p>
    <p class="content">
      It is a one-stop destination for all 
      Computer Science students!! It is a
      platform that fulfill all their needs 
      such as- Tutorials & Courses,
      Placement preparation, Interview 
      Experiences, and various others.

Output : 

text color for different elements

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!