Background image to HTML and/or BODY element

Keep in mind that height of <html> and <body> element are not same. Body element is inside of <html> element, so in some cases are important to specify background (image or color) for particular element in different way. This is example how:


html {
    background: url(background1.png) center center no-repeat;

body {
    background: url(background2.png) center center no-repeat;


body {
    background: url(background2.png) center center no-repeat, 
		url(background1.png) center center no-repeat;

Specification says : The background of the root element becomes the background of the canvas and its background painting area extends to cover the entire canvas, although any images are sized and positioned relative to the root element as if they were painted for that element alone. (In other words, the background positioning area is determined as for the root element.) If the root's ‘background-color’ value is ‘transparent’, the canvas's background color is UA dependent. The root element does not paint this background again, i.e., the used value of its background is transparent.

For documents whose root element is an HTML HTML element or an XHTML html element: if the computed value of ‘background-image’ on the root element is ‘none’ and its ‘background-color’ is ‘transparent’, user agents must instead propagate the computed values of the background properties from that element's first HTML BODY or XHTML body child element. The used values of that BODY element's background properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the BODY element rather than the HTML element.

Comments are closed