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

Is there a problem if I add a comma in a css declaration

Hello team Treehouse,

I keep typing commas in my css declarations. For example:

nav {
  text-align: center; 
  padding: 10px, 0;
  margin: 20px, 0, 0;
}

What am I telling the browser if I add commas like this? Or, why is this syntax incorrect?

Sorry, very newbie question.

2 Answers

Hey Rahi,

Check out this old post below. It should answer your question. But mainly commas are used in CSS to group "Selectors" together to have the same styles to each class or id you create.

https://teamtreehouse.com/forum/css-when-to-use-a-comma

Hope this helps you out!

Thanks David, the post you shared was just the explanation I needed.

Andrew Dushane
Andrew Dushane
9,264 Points

You can't use commas in that way. The reason is that it won't work - CSS is looking for white-space separated values, not comma-separated values. There are uses for commas in CSS - you'll use them a lot for grouping selectors, for example. You just have to follow the rules basically. In this case, there's only one way to write the list of values for padding and margin. http://www.w3.org/community/webed/wiki/CSS/Properties/margin

Thanks Andrew.