Home  >  Article  >  Web Front-end  >  How to set background image in html

How to set background image in html

王林
王林Original
2021-06-23 10:49:5863207browse

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('');].

How to set background image in html

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(&#39;https://static.runoob.com/images/mix/paper.gif&#39;);
	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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn