Cover Image for How to Change Text Color in Html
89 views

How to Change Text Color in Html

To change the text color in HTML, you can use the CSS (Cascading Style Sheets) color property. Here’s an example of how to change the text color:

HTML<span role="button" tabindex="0" data-code="<p style="color: red;">This text is in red color.

<p style="color: red;">This text is in red color.</p>

In the example above, the <p> tag is used to enclose the text that you want to style. The style attribute is added to the <p> tag to apply inline CSS styles. Within the style attribute, you set the color property to the desired color. In this case, the color is set to “red”.

You can specify the color using various methods, such as using color names, hexadecimal color codes, RGB values, or HSL values. Here are a few examples:

Using color names:

HTML<span role="button" tabindex="0" data-code="<p style="color: blue;">This text is in blue color.

<p style="color: blue;">This text is in blue color.</p>

Using hexadecimal color codes:

HTML<span role="button" tabindex="0" data-code="<p style="color: #FF0000;">This text is in red color using hexadecimal code.

<p style="color: #FF0000;">This text is in red color using hexadecimal code.</p>

Using RGB values:

HTML<span role="button" tabindex="0" data-code="<p style="color: rgb(255, 0, 0);">This text is in red color using RGB values.

<p style="color: rgb(255, 0, 0);">This text is in red color using RGB values.</p>

Using HSL values:

HTML<span role="button" tabindex="0" data-code="<p style="color: hsl(0, 100%, 50%);">This text is in red color using HSL values.

<p style="color: hsl(0, 100%, 50%);">This text is in red color using HSL values.</p>

You can also apply the text color styling in an external CSS file or within a <style> block in the HTML document. Using CSS classes and selectors, you can target specific elements or apply the styling globally.

It’s important to note that the color property affects the foreground color of the text, while the background-color property is used to set the background color behind the text.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS