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

CSS CSS Basics (2014) Basic Layout Backgrounds: Size and Position

Matthew Keys
Matthew Keys
1,922 Points

Explanation of the slash after the image position

Can someone please explain to me why you need to put a slash after the image position (center / cover)?

1 Answer

Hi Matthew,

This is a syntax requirement to remove ambiguity that would occur without it.

background-position and background-size can both accept some of the same types of values. For example, percentages and lengths.

Imagine the following background shorthand was used:

background: 30% 80%;

This can be interpreted multiple ways if we didn't have that forward slash syntax requirement. Are both of those values for the background-position? Are both for background-size? Is one for background-position and the other for background-size?

To remove this uncertainty, it was decided that background-position would be first, then a forward slash, and then the background-size.

This syntax also means that it's not possible to specify the background-size without also first specifying the background-position using the shorthand.

Going back to the earlier example, because the browser does not see a forward slash followed by values for background-size, it knows that the 30% 80% is for background-position. There is no other way to interpret it.