- How to change text color in HTML? – Top 3 ways to create awesome website content
- How to change text color in HTML with color property
- What’s this article about?
- What parts of the text can we change the color of in HTML?
- Setting the text color in HTML
- Using the color property using CSS selectors
- How to change text color in HTML by using the color property in inline CSS formatting
- Changing the font color of headings
- Changing the font color of paragraphs
- HTML color names and color codes
- Defining the same color with color names and color codes
- How to change text color in HTML with the tag – an outdated method
- How to set font color in HTML?
- Syntax
- Example
- Example
- Example: Specifying internal style
- HTML Font Style – How to Change Text Color and Size with an HTML Tag
- Basic font-size Syntax
- How to Change Text Size and Text Color in the HTML Tag
- How to Change Text Size and Text Color in an External CSS File
- Conclusion
How to change text color in HTML? – Top 3 ways to create awesome website content
How to change text color in HTML with color property
If we want to change the text color on our website, we have to use the color CSS property.
What’s this article about?
We can modify the font color of many HTML elements or even the whole website. To do so, we’ll use one CSS setting, but we have two options as to where we can put this information in our code.
The article will look at these methods, talk about the methods of defining or referring to colors and show you how to change text color in HTML on different ways.
What parts of the text can we change the color of in HTML?
We can change the text color of elements such as:
- Headings ,
- Paragraphs
- Values in tables
- Sections of a page
- A highlighted part of a line
In this article, we’ll talk about the methods for changing the color of texts on a website.
Setting the text color in HTML
Using the color property using CSS selectors
We can change the selected HTML element’s text color in the section. In this case, we can use a CSS selector to select the tag we want to format.
We can also use an inline CSS statement, meaning we can place a statement in the tag that creates the HTML element we want to change the text color of.
How to change text color in HTML by using the color property in inline CSS formatting
We can set the text color of a given HTML element by placing the statement of the color change in the tag that creates the element. We have to add the style=color:”value” attribute to the tag.
Changing the font color of headings
Changing the font color of paragraphs
HTML color names and color codes
After we decide which color to use, we have to choose the format of the color as well. HTML knows the names of 140 colors, such as OliveGreen , PowderBlue , Black , etc.
If we don’t want to use the name of a color, or we choose one that is not included in the 140 named colors, we have to use color codes.
You can learn more about this topic in our article titled HTML Color Codes .
Defining the same color with color names and color codes
We can refer to the dark magenta font color above in three ways:
Dark magenta font color, in different formats: | Name | HEX | RGB |
DarkMagenta | #8b008b | (139, 0, 139) |
How to change text color in HTML with the tag – an outdated method
There is a method that is not supported in HTML5 called the tag. This can also change the text color, but this method is a bit outdated.
If you’d like to see more programming tutorials, check out our Youtube channel, where we have plenty of video tutorials in English.
In our Programming Tutorials series, you’ll find useful materials which will help you improve your programming skills and speed up the learning process.
HTML and CSS:
- HTML color codes
- How to create perfect HTML tables
- Best way to create HTML table with HTML and CSS
- How to create perfect CSS background images
- How to center an image in HTML?
- How to change background color in HTML?
- How to disable scrolling in HTML?
- How to change text color in HTML?
Other materials:
How to set font color in HTML?
We use the style attribute to set the font color in HTML. The style attribute specifies an inline style for an element, with the CSS property color. The attribute is used with the HTML
tag, with the CSS property color. HTML5 do not support the tag, so the CSS style is used to add font color. The tag deprecated in HTML5.
Syntax
Example
In the example below, we set the font color of the text inside the
tag.
DOCTYPE html> html> head> title>HTML Font colortitle> head> body> h1>Productsh1> p style="color:blue">This is demo content.p> body> html>
Example
Following is the example program to set font color in HTML.
DOCTYPE html> html> head> style> body < background-color: rgb(20,30, 1); >style> h1 style="color: azure">HTML Articlesh1> head> body> body> html>
Example: Specifying internal style
We can also specify internal style for an element, with the CSS property color to set font color in HTML. Following is the example program for internal style sheet to set font color in HTML.
DOCTYPE html> html> head> style> body < background-color: rgb(20,30, 1); >h1 < color: cyan; >style> h1>HTML Articlesh1> head> body> body> html>
HTML Font Style – How to Change Text Color and Size with an HTML Tag
Kolade Chris
When you code in HTML and add some text, you don’t want to leave it like that. You want to make that text look good.
And to do that, you need to change their appearance through the color and font-size properties of CSS.
In this tutorial, I will show you two different ways you can make your HTML texts look good.
Basic font-size Syntax
How to Change Text Size and Text Color in the HTML Tag
You can change the color and size of your text right inside its tag with the color and font-size properties. This is known as inline CSS. You do it with the style attribute in HTML.
In the HTML code below, we will change the color and size of the freeCodeCamp text.
It looks like this in the browser:
To change the size of the text, you’ll use the style attribute, and then set a value with the font-size property like this:
The text now looks like this in the browser:
If you are wondering what 4rem is, it’s a unit of measurement. It’s the same as 64 pixels, because 16px makes 1rem unless you change the root font-size ( html ) to another value.
To change the color of the text, you can use the style attribute, and then set a value with the color property:
This is what we now have in the browser:
Combining the font-size and color properties gives us this in the browser:
How to Change Text Size and Text Color in an External CSS File
You can also change the color and size of text in an external stylesheet. Most importantly, you have to link the external CSS in the head section of your HTML.
The basic syntax for doing it looks like this:
Now, to change the text size and color of the freeCodeCamp text, you need to select it in the stylesheet and apply the appropriate properties and values to it.
Remember this is our simple HTML code:
You can change the color and size of the text by selecting the element (h1) and assigning values to the color and font-size properties:
We have the same result in the browser:
Conclusion
I hope this tutorial gives you the knowledge to be able to change the size and color of your HTML text so you can make them look better.
Thank you for reading, and keep coding.