Change Text Color in HTML
While you can change text color using the tag in HTML, this method is no longer supported in HTML5. Instead, you'll use basic CSS to define what color the text will appear in various elements on your page. Using CSS will ensure that your web page is compatible with every possible browser.
Contents
Steps
Using CSS
- Open your HTML file. The best way to change the color of your text is by using CSS. The old HTML </kbd> attribute is no longer supported in HTML5. The preferred method is to use CSS to define the style of your elements.
- This method will also work with external stylesheets (separate CSS files). The examples below are for an HTML file using an internal stylesheet.
- Place your cursor inside the <head> tag. You'll be defining your styles inside this tag if you're using an internal stylesheet.
- Type <style> to create an internal stylesheet. When the <style> tag is in the <head> tag, the CSS inside the <style> tag will be applied to any applicable elements on that page. When you're finished, the beginning of your HTML file should look something like this:Template:CodeBox
- Type the element you want to change the text color for. You'll be using the <style> section to define the look of the different elements on your page. So for example, to change the style of all the body text on your page, type the following: Template:CodeBox
- Type the color: attribute into the element selector. The color: attribute will tell the page what text color to use for that element. In this example, it will change the text color of all body text, which is the default element for all text on your page: Template:CodeBox
- Type in a color for the text. 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, rgb(0, 0, 255), or #0000FF. Template:CodeBox
- Add other selectors to change the color of various elements. You can use the different selectors to change the color of your text for different parts of the page: Template:CodeBox
- Define a CSS class instead of changing an element. You can define a class and then apply it to any element you'd like throughout the page to instantly add the class style. For example, in the following file the ".redtext" class will make any element it's applied to use red text: Template:CodeBox
</ol>Using Inline Style Attributes
- Open your HTML file. You can use inline 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. For comprehensive style changes, use the previous method.
- Find the element in the file that you want to change. You can use inline style attributes to change the text color of any of your elements. For example, if you want to change the text color of a specific header, find it in your file: Template:CodeBox
- Add the style attribute to the element. Type style="" inside the opening tag for the element you want to change: Template:CodeBox
- Type the color: attribute inside the "". For example: Template:CodeBox
- Type the color you want to change the text to. 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;, rgb(255,255,0);, or #FFFF00;: Template:CodeBox
Tips
- You can see a list of supported color names and their hex values at http://www.w3schools.com/colors/colors_names.asp
Related Articles
- Learn HTML
- Resize iFrames in HTML
- Choose an HTML Editor
- Use Font Color Tags in HTML
- Paste Screen Captures Directly Into an HTML Formatted Email
- Define a Selectable List in HTML
- Change The Font Size on an iPhone
- Set Background Color in HTML
- Create a Big Block Text Box for an HTML Form
- Change the Font Type Using HTML Programming
- Change Text Color in Photoshop
- Make Paragraph Styled Heading Text in HTML
Sources and Citations