A web page with a background tends to look prettier than without it. The correctness of the display of the web page depends on the competent actions to add the background.
Instructions
Step 1
The easiest way to make a background in an html document is to assign the attribute value to the body tag. A given value for the background attribute will determine the background image on the page. If you set the value of the bgcolor attribute, the page will take on a background color. The color in the bgcolor attribute of the body tag can be specified either in hexadecimal or just in one word.
Step 2
You can achieve the same effect by using cascading CSS style sheets. The value of the background-color attribute will determine the background color on the page, while the value of the background-image attribute will determine the path to the background image of the page. These instructions can be written to the body selector. You can do it differently: assign a class or identifier to the body tag in the html tag, and assign the above attributes to the class or identifier in css, respectively. It should only be borne in mind that if the attributes are assigned to a class, then all objects with the specified class will have a background color in the html document.
Step 3
The above instructions can be written in the body of the html document itself. To do this, open the style tag in the service section between the head tags (opening and closing). Any CSS statements can be written between the opening and closing of a given tag. It should only be borne in mind that in this case, the page weight will increase, which can negatively affect the time it takes to load it for the end user. It should also be noted that in the case of specifying a background image, it can be repeated horizontally, vertically or along two axes at once. The background-repeat attribute in CSS is responsible for this. The background picture can be rigidly docked regardless of the presence of a scroll bar in the document. To achieve this effect, you must specify background-attachment: fixed.
Step 4
The background of an html document can be done using programming languages. You can write html instructions using JavaScript. The document.write language construct is suitable for this. If the same thing is expressed through the DOM, the document.body.style.backgroundColor = “red” statement will make the background of the page red. This is the same as writing the appropriate attribute directly in CSS.
Step 5
The previous instructions can be written right in the code of a web page by creating a pair of script tags between the opening and closing head tags. However, all these instructions can be written into a separate file with the js extension, which, subsequently, can be connected to the page.