CSS Text: CSS has a lot of properties for formatting text.
CSS text formatting properties is used to format text and style text.
Text Color
The color property is used to set the color of the text. The color is determined by:
- a color name – like “red”
- a HEX value – like “#ff0000”
- an RGB value – like “rgb(255,0,0)”
Look at CSS Color Values for a complete list of possible color values.
The default text color for a page is defined in the body selector.
Example
<!DOCTYPE html> <html> <head> <style> body { color: blue; } h1 { color: green; } </style> </head> <body> <h1>This is heading 1</h1> <p>This is an ordinary paragraph. Notice that this text is blue. The default text color for a page is defined in the body selector.</p> <p>Another paragraph.</p> </body> </html>
Note: For W3C compliant CSS: If you define the color property, you should likewise define the background color.
Text Color and Background Color
In this example, we define both the background-color property and the color property:
Example
<!DOCTYPE html> <html> <head> <style> body { background-color: lightgrey; color: blue; } h1 { background-color: black; color: white; } </style> </head> <body> <h1>This Heading is Black with White Text</h1> <p>This page has a grey background color and a blue text.</p> <p>Another paragraph.</p> </body> </html>
Thanks for reading! We hope you found this tutorial helpful and we would love to hear your feedback in the Comments section below. And show us what you’ve learned by sharing your projects with us.