Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website CSS: Cascading Style Sheets Use ID Selectors

Alex Thomas
Alex Thomas
4,247 Points

setting an image as background using css

Hello, i'm trying to set an image from the file tree as the background to the html using css. I can't seem to get it to appear. Can someone tell me what I'm doing wrong?

body { background-image: img("classic.jpg"); }

2 Answers

Tray Denney
Tray Denney
Courses Plus Student 12,884 Points

Hey there! You were very close but it appears you have made a slight syntax error while setting the background image.

Try using

body {
   background-image: url("path/to/image");

https://www.w3schools.com/cssref/pr_background-image.asp is a wonderful resource on how to set the background image using CSS.

Tray is totally correct, however if you need to find some resources in the future the Mozilla Developer Network(MDN) is a more trustworthy source.

Tray Denney
Tray Denney
Courses Plus Student 12,884 Points

Thanks for adding that! It slipped my mind. Here is the MDN documentation on the background-image property: https://developer.mozilla.org/en-US/docs/Web/CSS/background-image?v=control