How To Change The Background In HTML

Table of contents:

How To Change The Background In HTML
How To Change The Background In HTML

Video: How To Change The Background In HTML

Video: How To Change The Background In HTML
Video: how to add background image in html 2024, December
Anonim

The background of the page can be set using HTML and CSS by specifying the appropriate directives in the source code of the document. The attributes used in markup languages are supported by most modern browsers and will display correctly on almost any visitor to your site.

How to change the background in HTML
How to change the background in HTML

Background parameter

Open your HTML page file for editing in the editor you are using. To do this, you can right-click on the document and select the "Open with" section.

The structure of an HTML file is a series of descriptors of various levels and purposes. The page code usually starts with a tag. This is usually followed by a section that contains the page title and CSS code. After the descriptor is closed, the body of the page begins. The attribute for setting the background image of the page is set as an additional background parameter for this tag. The code for creating the page background will look like this:

In this case, the path to the picture can be a URL (starting with https://). The location can be specified from the root directory (/root/folder/background.jpg) or relative to the location of the edited HTML document (for example, folder / background.jpg).

Save your changes and open the page in a browser. To do this, right-click and select "Open with". In the list provided, indicate the name of the program you are using for browsing the Internet. If the background parameter was set correctly, you will see the previously specified background image. If the picture is not displayed, check the correctness of the background attribute and the path to the background file.

Bgcolor parameter

To set the background color without a picture, you can use the bgcolor directive. As a value for this attribute, you can specify the color name in English or use the color value in the HTML palette. For example:

This code gives the page a blue background. If you want to set a color tint or a more accurate color, use the values of the HTML palette:

In this case, # 002902 is the color to be given to the page.

CSS Attributes

You can also set the background using the CSS in the parameters:

With CSS, you can also specify the background image for the page via background-image:

Using CSS and HTML gives the same results, however, it is preferable to use CSS when setting the page display parameters.

Recommended: