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

What does setting margin and padding to 0 in CSS mean?

More specifically, what does setting margin and padding to 0 in CSS but in the body selector do? Why do this if you can already add the same property and value to other selectors like paragraphs?

1 Answer

Steven Parker
Steven Parker
231,248 Points

Browsers typically give the body element some margin and/or padding by default. By explicitly setting it to 0, you can be sure your layout will look the same on any browser; and also be able to use the full width of the window.

This sums it up for me really well, thank you :)