How to change header text color?

QuestionsQuestions8 SkillsProCSS Styling TablesOct, 22 2025
0169

To change the header text color in CSS, you can use the color property. You can target specific header elements (like <h1>, <h2>, etc.) or use a class or ID selector. Here are a few examples:

  1. Changing the color of all header elements:

    h1, h2, h3, h4, h5, h6 {
        color: blue; /* Changes the color of all header elements to blue */
    }
  2. Changing the color of a specific header element:

    h1 {
        color: red; /* Changes the color of <h1> elements to red */
    }
  3. Using a class to change the header color:

    <h1 class="header-title">My Header</h1>
    .header-title {
        color: green; /* Changes the color of headers with the class "header-title" to green */
    }
  4. Using an ID to change the header color:

    <h1 id="main-header">Main Header</h1>
    #main-header {
        color: purple; /* Changes the color of the header with the ID "main-header" to purple */
    }

You can specify colors using color names, hex codes, RGB, or HSL values. For example:

h1 {
    color: #ff5733; /* Hex code */
}

h2 {
    color: rgb(255, 87, 51); /* RGB */
}

h3 {
    color: hsl(12, 100%, 60%); /* HSL */
}

Simply include the CSS in a <style> tag in your HTML or in an external stylesheet to apply the changes.

0 Comments

no data
Be the first to share your comment!