How to change a background in HTML

How to change a background in HTML

The background of the page can be set by means of HTML and CSS at the indication of the corresponding directives in the source code of the document. The attributes used in markup languages are supported by the majority of modern browsers and correctly will be displayed practically at any visitor of your website.

Background parameter



Open the file of your HTML page for editing in the editor used by you. For this purpose you can click with the right mouse button on the document and select the section "Open with the Help".


The structure of the HTML-file represents a number of descriptors of different level and assignment. The code of the page usually begins with the <HTML> tag </html>. After it usually there is a section <head> </head> in which the heading of the page and the CSS code is specified. After closing of a descriptor the body of the <body> page begins </body>. The attribute for a task of the background drawing of the page is exposed as the additional background parameter for this tag. The code for creation of a background of the page will look as follows:

 

<body background = "path to the file of the picture">

At the same time path to the picture can represent URL (starting with http://). Placement can be set from a root directory (/root/folder/background.jpg), and concerning location of the edited document HTML (for example, folder/background.jpg).

Save the made changes and open the page in the browser. For this purpose click with the right mouse button and select "Open with the help". Specify the name of the program for browsing the Web used by you in the offered list. If the background parameter was set correctly, you will see the specified earlier background picture. If the picture is not displayed, check correctness of the indication of the background attribute and path to the file of a background.

Bgcolor parameter



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

<body bgcolor = "blue">

This code sets to the page a blue background. If you want to set color hue or more exact color, use HTML-palettes values:

<body bgcolor=”#002902”>

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

CSS attributes



You can also set a background by means of the CSS code registered in the <body> parameters:

<body style=" background-color: #E09255”>

By means of CSS you can specify also the background drawing for the page through background-image:

<body style=" background-image: url(/put_do_fayla_fona)">

Use of CSS and HTML yields identical results, however setting display options of the page it is more preferable to use CSS.

Author: «MirrorInfo» Dream Team


Print