The method to set the background image in html is to add the background-image attribute to the body and set the url of the background image, such as [background-image:url('');].
The operating environment of this article: windows10 system, html 5, thinkpad t480 computer.
The background-image property sets the background image of an element.
The background of an element is the total size of the element, including padding and borders (but not margins).
By default, the background-image is placed in the upper left corner of the element and repeats vertically and horizontally.
Common attribute values:
url('URL') URL of the image
none No image background will be displayed. This is the default attribute value
inherit Specifies that the background image should be inherited from the parent element
Code example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style> body { background-image:url('https://static.runoob.com/images/mix/paper.gif'); background-color:#cccccc; } </style> </head> <body> <h1>Hello World!</h1> </body> </html>
Everyone can Save the above code locally and try to run it to see the effect.
Related video sharing: html video tutorial
The above is the detailed content of How to set background image in html. For more information, please follow other related articles on the PHP Chinese website!