Download Article
Easily change the color of text using CSS or HTML
Download Article

Do you want to change the color of the text on a web page? In HTML5, you can use CSS to define what color the text will appear in various elements on your page. You can also use inline style attributes to change the color of individual text elements in your CSS file. Using CSS will ensure that your web page is compatible with every possible browser. You can also use external CSS files to create a standard font color for a specific style across your entire website. This How.com.vn article teaches you how to change text color using HTML and CSS.

Method 1
Method 1 of 2:

Creating Text Styles

Download Article
  1. How.com.vn English: Step 1 Open your HTML file.
    The best way to change the color of your text is by using CSS. The old HTML <font> attribute is no longer supported in HTML5. The preferred method is to use CSS to define the style of your elements. Go ahead and open or create a new HTML document.
  2. How.com.vn English: Step 2 Place your cursor inside the head of your HTML file.
    When you are using an internal style sheet for a specific HTML file, it is usually placed within the head of the HTML file. The head is at the top of the sheet in between the opening <head> tag, and the closing </head> tag.
    • If your HTML document does not have a head, go ahead and enter the opening and closing head tags at the top of your HTML file.
    Advertisement
  3. How.com.vn English: Step 3 Type the opening and closing tags for the style sheet.
    All CSS elements that affect the style of the webpage go in between the opening and closing style tags within the head section of your HTML document. Type <style> in the "head" section to create the opening style tag. Then type </style> a couple of lines down to create the closing style tag. When you're finished, the beginning of your HTML file should look something like this:[1]
    <!DOCTYPE html><html><head><style></style></head>
  4. How.com.vn English: Step 4 Type the element you want to change the text color for followed by the opening and closing brackets.
    Elements you can change include the text body (body), paragraph text ("<p>"), as well as headers ("<h1>", "<h2>", "<h3>", etc.). Then enter the opening bracket ("{") one space after. Then add the closing bracket ("}") a few lines down. In this example, we will be changing the "body" text. The beginning of your HTML file should look something like the following:
    <!DOCTYPE html><html><head><style>body {}</style></head>
  5. How.com.vn English: Step 5 Add the color attribute into the element section of the CSS.
    Type color: in between the opening and closing brackets of the text element you just created. The "color:" attribute will tell the page what text color to use for that element. So far, the head of your HTML file should look something like the following:
    <!DOCTYPE html><html><head><style>      body {      color:}</style></head>
  6. Step 6 Type in a color for the text followed by a semi-colon (";").
    There are three ways you can enter a color: the name, the hex value, or the RGB value. For example, for the color blue you could type blue; for the color name, rgb(0, 0, 255); for the RGB value, or #0000FF; for the hex value. Your HTML page should look something like the following:
    <!DOCTYPE html><html><head><style>body {color: red;}</style></head>
  7. How.com.vn English: Step 7 Add other selectors to change the color of various elements.
    You can use different selectors to change the color of different text elements. If you want the header to be a different color than the paragraph text or body text, you will need to create a different selector for each element within the "<style>" section. In the following example, we change the color of the body text to red, the header text to green, and the paragraph text to blue:
    <!DOCTYPE html><html><head><style>body {color: red;}h1 {color: #00FF00;}p {color: rgb(0,0,255)}</style></head><body><h1>This header will be green.</h1><p>This paragraph will be blue.</p>This body text will be red.</body></html>
  8. How.com.vn English: Step 8 Define a CSS class that changes text color.
    In CSS, you can define a class rather than using the existing elements. You can apply the class to any text element within your HTML document. To do so, type a period (".") followed by the name of the class you'd like to define. In the following example, we define a new class called ".redtext", which changes the color of the text to red. Then we apply it to the header at the top of the HTML document. Checkout the following example:
    <!DOCTYPE html><html><head><style>.redtext {color: red;}</style></head><body><h1 class="redtext">This heading will be red</h1><p>This paragraph will be normal.</p><p class="redtext">This paragraph will be red</p></body></html>
  9. Advertisement
Method 2
Method 2 of 2:

Using Inline Styles

Download Article
  1. How.com.vn English: Step 1 Open your HTML file.
    You can use inline HTML style attributes to change the style of a single element on your page. This can be useful for one or two quick changes to the style but is not recommended for widespread use. It's best to use CSS for comprehensive changes. Go ahead and open or create a new HTML document.[2]
  2. How.com.vn English: Step 2 Find the text element in the file that you want to change.
    You can use inline style attributes to change the text color of any of your text elements, including paragraph text ("<p>""), or your headline text ("<h1>").
    <!DOCTYPE html><html><body><h1>This is the header you want to change</h1></body></html>
  3. How.com.vn English: Step 3 Add the style attribute to the element.
    To do so, Type style="" inside the opening tag for the element you want to change. In the following example, we have added the style attribute to the header text:
    <!DOCTYPE html><html><body><h1 style="">This is the header you want to change</h1></body></html>
  4. How.com.vn English: Step 4 Type the color: attribute inside the quotation marks.
    Type "color" with a colon (":") within the quotation marks after the style attribute. So far, your HTML file should look something like the following:
    <!DOCTYPE html><html><body><h1 style="color:">This is the header you want to change</h1></body></html>
  5. Step 5 Type the color you want to change the text to followed by a semi-colon (";").
    There are three ways you can express a color. You can type the name of the color, you can enter the RGB value, or you can enter the hex value. For example, to change the color to yellow, you could type yellow; for the color name, rgb(255,255,0); for the RGB value, or #FFFF00; to use the hex value. In the following example, we change the headline color to yellow using the hex value:
    <!DOCTYPE html><html><body><h1 style="color:#FFFF00;">This header is now yellow</h1></body></html>
  6. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How would I type bold font in html?
    How.com.vn English: Community Answer
    Community Answer
    <b></b> is the code for bold text, so you would put your text within that, e.g. <b> hello world </b>.
  • Question
    How do I change background colors in HTML?
    How.com.vn English: Community Answer
    Community Answer
    Use the bgcolor attribute with body tag.
  • Question
    How do I change the color of the background?
    How.com.vn English: Community Answer
    Community Answer
    You will create a similar tag as you did to change the font color. After putting everything in the body tag, you will put the {} brackets and on the inside, type "background-color:(insert desired color)." In code, it should look like this:body { color: black; background-color:gold }This code gives you black text and a gold background.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      • You can see a list of supported color names and their hex values at http://www.w3schools.com/colors/colors_names.asp
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      How.com.vn English: Travis Boylls
      Co-authored by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for How.com.vn. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College. This article has been viewed 2,005,215 times.
      How helpful is this?
      Co-authors: 68
      Updated: January 30, 2023
      Views: 2,005,215
      Article SummaryX

      1. Open the file in a text editor.
      2. Find the element you want to change.
      3. Type style=″color:#FFFF00;″ in the opening tag.
      4. Replace ″#FFFF00″ with your desired color.

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 2,005,215 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement