Home › Forums › CSS › Where to put paddings/margins › Re: Where to put paddings/margins
April 23, 2013 at 3:40 pm
#132913
Participant
General rule: margin for spacing between elements, padding for spacing between an element and it contents.
I don’t agree with “inner elements before outer”, it depends on what you’re trying to achieve. For example you may have some container element your’re using on many pages (`
` in my case), but you want an edge around the containers content (which can be one or more elements, depending on page). If you want the edge to be the same no matter what, padding is the right choice. It’s more consistent and prevents you from needing to specify margin on every possible child element. If you want more flexibility you should go for padding or margin on the child elements.
Even if you don’t use backgrounds on those elements, it makes the choice between margin or padding sometimes more obvious if you think about how a background on an element would behave, maybe even add a background color just for prototyping.