Filter (Advanced Search)
Downloads
3
Views
278
Video

Background Image on a HTML element | Images

Details

To add a background image on an HTML element, use the HTML style attribute and the CSS background-image property:

Example

Add a background image on a HTML element:

<p style="background-image: url('cat.jpg');">

You can also specify the background image in the <style> element, in the <head> section:


<!DOCTYPE html>
<html>
<head>
<title>Background Image</title>
</head>
<body>

<h2>Background Image</h2>

<p>You can specify background images<br>
for any visible HTML element.<br>
In this example, the background image<br>
is specified for a div element.<br>
By default, the background-image<br>
will repeat itself in the direction(s)<br>
where it is smaller than the element<br>
where it is specified. (Try resizing the<br>
browser window to see how the<br>
background image behaves.</p>

</body>
</html>


Output


Ad