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

General Discussion

how to separate paragraphs? margin or padding

Hi! I have a page with a h1 h3 and a few paragraphs, what's the best way to separate them margin or padding?

4 Answers

I think margin.

h1{margin-bottom:15px} h3{margin-bottom:12px;} p{ margin-bottom:10px }

Thats how i'd do it. Padding pushes the content within the element. Margin pushes the element away from other elements. Elements being the p/h1/h2 and content being the text inside. I think I worded that right. :P GL hope it helps

diagram

That's right, you can experiment with margin and padding using a border around your elements.

h1, h3, p { border: 1px solid black; } ***for test purposes.

Agreed. Margin is the way to go. Padding works if paragraphs have either no background or the same color background as the content area behind it. But, what if you want to make a single paragraph stand out by adding a background color to it? In that case, the background color of the paragraph will hit up against the paragraphs around it and you'll end up needed to add margin to that paragraph anyway. It's better to use margin so that you can adding a background and padding to one or more of the paragraphs if you need to, while still maintaing an equal distance between paragraph blocks. I hope that make sense!

TL;DR - Margin is the one you want.

There are few important differences between margin and padding, margins auto-collapse padding doesn't. Also padding enlarges the size of an element, e.g. it makes the clickable area of a button bigger.


Margin is on the outside of block elements while padding is on the inside.

use margin to separate the block from things outside it, padding to move the contents away from the edges of the block.

source: http://stackoverflow.com/a/2189462/1756132

For more details check out this tutorial on CSS basics from Smashing