What’s an HTML background tag?

Print anything with Printful



The HTML background tag is deprecated and should be replaced with CSS. CSS allows for more flexibility in defining background properties, including color, image, attachment, position, and repeat. Different browsers may require specific definitions.

There is no background tag in HTML. What might have been called a background tag in earlier versions of HTML, the HTML tag background attribute, was used to display a background image for a web page. The current World Wide Web Consortium (W3C) recommendation is HTML 4.01/XHTML 1.0. In this recommendation, the background attribute is deprecated: it is no longer considered valid HTML. The related attribute bgcolor, which could be considered a background tag, is also deprecated.

Cascading Style Sheets (CSS) should be used to set all background effects in a valid HTML or XHTML web page. Using CSS to define background properties is much more flexible than the previous method. The background attribute, or background tag, was limited to displaying a background image. Background properties in CSS can define where the background image starts, how it repeats and whether it flows with the rest of the page or stays in the same place. CSS background properties can be applied to an entire web page or to page elements.

Background properties include background color, background image, background attachment, background position, and background repeat. All of these properties can be consolidated into the background property instead of being set as separate properties. This is called the shorthand property.

Like the older bgcolor attribute, background-color can take the form of an RGB value, a hexadecimal code, or a color name. The background of any element to which this property is applied will be displayed in that color. The value for background-image is the URL of the image.

The other properties — background link, background position and background repeat — can be defined, but otherwise the default values ​​will be used. Wallpaper repeat is used to repeat the wallpaper vertically or horizontally; by default, it repeats vertically and horizontally. The background attachment scrolls the background image with the rest of the page, which is the default, or stays in one place. The default background position is the upper left corner of the element.

Different web browsers may display background properties differently or require more specific definitions in the CSS. For example, while Internet Explorer® 8 supports value inheritance for some properties, it does not support it for background properties. In Firefox®, the background-position property doesn’t work correctly if the background-attachment property is not set to fixed. Developers should test their pages in a variety of browsers to ensure that the pages render as intended.




Protect your devices with Threat Protection by NordVPN


Skip to content