YouTip LogoYouTip

Att Body Background

## HTML `` `background` Attribute The `background` attribute of the `` tag is used to specify a background image for an HTML document. > **⚠️ Deprecation Notice:** This attribute is **deprecated** in HTML 4.01 and is **not supported** in HTML5. Modern web development standards require using CSS instead to handle page styling and background images. --- ## Syntax ```html ``` ### Attribute Values | Value | Description | | :--- | :--- | | `URL` | The URL of the background image. Supported formats include:
β€’ **Absolute URL:** Points to an external website (e.g., `background="https://www.example.com/images/bg.gif"`)
β€’ **Relative URL:** Points to a file within the same website (e.g., `background="images/bg.gif"`) | --- ## Browser Support All major web browsers historically supported the `background` attribute for backwards compatibility: * Google Chrome * Mozilla Firefox * Internet Explorer / Microsoft Edge * Safari * Opera --- ## Code Examples ### Legacy HTML Example (Deprecated) The following example demonstrates how the `background` attribute was traditionally used to apply a background image to a webpage. ```html Legacy Background Attribute Example

Hello World!

This page uses the legacy HTML background attribute.

``` ### Modern CSS Example (Recommended) Because the `background` attribute is obsolete, you should use the CSS `background-image` property instead. This can be applied via inline styles, an internal stylesheet, or an external stylesheet. #### Using Inline CSS: ```html Modern CSS Background Example

Hello World!

This page uses modern inline CSS to set the background image.

``` #### Using External/Internal CSS (Best Practice): ```html Best Practice CSS Background

Hello World!

This page uses an internal CSS stylesheet for cleaner, more maintainable code.

``` --- ## Compatibility & Best Practices * **HTML5 Compatibility:** The `background` attribute is completely removed from the HTML5 specification. Pages using this attribute may not validate correctly. * **Separation of Concerns:** HTML should only be used to define the structure of a webpage, while CSS should handle all visual presentation and styling. * **Enhanced Control with CSS:** Using CSS allows you to control additional background behaviors that the HTML attribute cannot handle, such as: * `background-repeat`: Controls whether the image tiles (repeats). * `background-size`: Scales the background image (e.g., `cover` or `contain`). * `background-position`: Aligns the image to the center, top, bottom, left, or right. * `background-attachment`: Determines if the background scrolls with the page or remains fixed.
← Att Body BgcolorAtt Body Alink β†’