HTML for Web Development

0% completed

Previous
Next
HTML - Backgrounds

In this lesson, you'll learn how to set backgrounds using HTML-only techniques. Although the HTML background attribute is considered deprecated in favor of CSS, it is still a simple way to understand how a background image can be applied to an entire page.

1. Using the HTML background Attribute

In older versions of HTML, the background attribute was used on the <body> element to set a background image for the entire page. This method does not require any CSS.

Syntax:

<body background="path/to/background.jpg"> <!-- Page content --> </body>
  • background Attribute: Directly assigns an image file to be used as the page background.

Example:

HTML

. . . .

Explanation:

  • The <body> tag includes the background attribute that links to the image URL.
  • The image is applied as the background for the entire page.
  • All content (headings, paragraphs, etc.) appears in front of this background image.

2. Limitations and Considerations

  • Deprecated Method:
    The background attribute is deprecated in HTML5. Modern web development uses CSS (with the background-image property) for more control and flexibility.

  • No Advanced Control:
    Using the HTML background attribute does not allow for control over properties like repeat, size, or position. For full control over a background's appearance, learning CSS is recommended later.

  • For Learning Purposes:
    While not best practice for production sites, using the HTML method helps beginners understand the concept of assigning a background image to a web page without getting into CSS.

By starting with HTML-only techniques, you can grasp the fundamentals of applying backgrounds. In CSS course, you'll explore more advanced methods using CSS, which allow for detailed control and better compatibility with modern web standards.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next