Skip to content

HTML for greens - HTML

Background and text color

How do I change the background color and text color on a web page?

<body style="background-color: background color; color: text color">
Here is the actual content of the page
</body>
Instead of the words "background color" and "text color", you should enter the definition of the background color and text color, respectively, just like in the case of fonts.

If you want to set the background color and text color for the entire page, you can use additional attributes for the <body> tag. These values ("background-color: ...; color: ...") are not entered within the actual content of the page, as with tags. Instead, they are placed in the style="..." attribute inside the opening <body> tag (before the actual content) because they are not separate tags but attribute values. It's essential to remember that there can be only one <body> tag on a page. All attributes related to it (like the one shown above) are added to the existing tag, rather than inserting a new one in a different part of the page.

The background color and text color of the entire page should always be set simultaneously.

Even if you set the text color for the entire page, you can later change it locally using the <span style="color: color">...</span> command (see: Font Color).

Questions and Answers

How to change the background color and text color in HTML?

To change the default background color and text color for the entire page, it's best to add the appropriate attributes to the tag of the document's body. For example: <body style="background-color: black; color: white">...</body> will set a black background color and white text color. However, it's essential to remember that in an HTML file (e.g., *.html), there can be only one document body tag. Therefore, you add the relevant attribute to the existing tag rather than inserting a new one!

How to make a yellow background in HTML?

The background color on a web page should always be set together with a text color that provides adequate contrast. Otherwise, the user may change the default text color in their web browser, and it could become unreadable (e.g., white text on a yellow background). To set a yellow background and black text for the entire page, it's best to add the appropriate attributes to the tag of the document's body: <body style="background-color: yellow; color: black">...</body>. However, it's essential to remember that in an HTML file (e.g., *.html), there can be only one document body tag. Therefore, you add the relevant attribute to the existing tag rather than inserting a new one!