Conversation


Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0


advertisement

Background and Foreground Colors in HTML

background in html


HTML provides background properties that specify the background color and image for Web pages. To select a background for a Web page, use the background property. The background property is a shorthand property that stipulates all the background properties in just one declaration.

The bgcolor attribute specifies the background color of a document.

Syntax:

<body bgcolor="color name | hex number| rgb number">


Where,

  • Color name - Specifies the background color with a color name (such as "red").
  • Hex_number - Specifies the background color with a hex code (such as " #ff0000")
  • RGB_number - Specifies the background color with an RGB code (such as "RGB (255, 0, 0)").

<html>
<body bgcolor="#E6E6FA">
<hl>Hello world! </hl>
<p><a href="http://www.w3schools.com">Visit W3Schools. Com! </a></p>
</body>
</html>



Another way to specify a background color for a Web page is by using style="background-color: color". This attribute must be added to the <body> tag. An example of applying a background color using the style attribute is as follows:

Example:

<body style="background-color: yellow">



The color name 'yellow' can also be replaced by the hex code or the RGB code.

The default text color of the page is specified as the foreground color. The foreground color can be specified by using the style="color: color" attribute. An example of applying a background and foreground color using the style attribute is as follows:

Example:

<body style="background-color: navy; color: yellow">


Background Image File

A Website developer can also insert an image as the background on a Web page. These background images are not recommended as sometimes the colors in the image may hide the text content. Hence, it is best to choose images with lighter shades. Also, as the image is tiled, it is best to choose an image that blends well and looks like a single image even after it is tiled.

<html>
<body background="bgimage.jpg">
</body>
</html>

HTML Image file in HTML Background color in HTML Foreground color in HTML Background image file background properties in HTML background image in HTML

advertisement