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! While you're at it, check out some resources Treehouse students have shared here.

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

CSS CSS Basics (2014) Basic Layout Backgrounds: Color and Images

What's the advantage of adding a background image in CSS as opposed to HTML?

I thought CSS is just for layout and positioning? Shouldn't everything content-related be added in HTML for best practice?

1 Answer

Ivan Villa
Ivan Villa
8,597 Points

correct everything content related should be in the HTML, but images can be used for decoration as well as content.

for example lets say you are doing a website on hiking, you may want to add an image of some cool trails in the background, and this image is used for design only so CSS is a good choice.

if you are writing an article about a specific trail and you add the photo to your article, then adding it to HTML is a better choice, because the photo is part of the page content.

Mod Edit - Changed from comment to answer so it may be voted on or marked as best answer.