How to add background image in html | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add background image in html

15th Jan 2020, 4:30 AM
Nasim Sachora
Nasim Sachora - avatar
4 Answers
+ 2
<!DOCTYPE html> <html> <body> <h2>Background Image</h2> <div style="background-image: url('img_girl.jpg');"> 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. </div> </body> </html>
15th Jan 2020, 4:55 AM
Akshay Harshora
Akshay Harshora - avatar
+ 1
To add background image to the body <body style="background-image:url("the picture name and directory goes here")></body> To add to html elements like p, div, etc. <p style="background-image:url("IMG/tree.jpg")></p>
15th Jan 2020, 9:13 AM
Atewogbola Ayomide
Atewogbola Ayomide - avatar
- 1
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body, html { height: 100%; margin: 0; } .bg { background-image: url("image.jpg"); height: 100%; background-color: #cccccc; background-position: center; background-repeat: no-repeat; background-size: cover; } </style> </head> <body> <div class="bg"></div> </body> </html>
15th Jan 2020, 12:28 PM
Sujay
Sujay - avatar