What are the rules of thumb for margins in web design?
My web designer tells me that in a web page, the empty margins or padding should always be multiples of a standard. For example 6 px, 12px, 18px. This should produce nicely balanced lay-outs. I would like to learn a little bit more about it:
Should one really not violate this at all?
Should the standard be the same horizontally and vertically?
I'm not proposing to close the question here, but graphic design SE is another good place to ask.
The reason for the bounty from me is I think this question is very interesting, and needs to be answered correctly. My answer is just one from my point of view. I think that there is more appropriate ones, taking full act on the complexity (like @Coswyn).
"empty margins or padding should **always** be multiples of a standard" (emphasis mine) - usage of the word "always" is a pretty good indicator of a false statement, because absolute statements are **always** false.
@zzzzBov "Absolute statements are always false" is an absolute statement. So are you wrong?
The best learning resource for this would be a good introduction on typography – probably the seminal classic by Bringhurst (see http://webtypography.net for a good roundup applied to the web), though e. g. Spiekermann's ‘Stop Stealing Sheep…’ is not bad for starters, either – and on design grids (see my answer here on UXexchange).
When designing grids you are mostly using a basic module (proportions ideally defined by working from the content outwards) that all content is fitted to (i.e. multiples of it).
Vertical and horizontal margins between blocks are in most cases different. Vertical whitespace is often oriented on the baseline grid (see e.g. Bringhurst, again). Using one is highly recommended to achieve at a unifying vertical rhythm.
The minimum amount of horizontal whitespace, i. e. primarily the separation between columns of body text (gutter), is governed by Gestalt psychology with font size, line spacing, and line width as main influencing factors. You should place text blocks far enough from another such that your recipients will be able to see them as distinct units of their own. A traditional rule of thumb would make the gutter at least 1.5 ems wide in order to appear significantly wider than any possible whitespace within a line of text. On the screen, good line spacing tends to be a little bit wider than in traditional print, though. Hence you will probably need a little bit more than that. Using the same value as your baseline grid is a good guess to start with in most cases.
BTW: design standards – unless significantly backed up by ergonomics or cognitive psychology – are never standards in the more rigid sense of the word. You may violate any ‘standard’ as long as you know why you are doing it.
It's better to use relative values - "em"s or percents, because margin looks good only in specific width/height ratio.
Relative sizes are useful even in fixed layouts, because when you need it to shrink/widen a little, you have to change it only in one place.
So the answer is: Do not use pixels, use "em"s for margins as well as box sizes, and it IMHO should be between 0.5em to 2em - depending on visual experience.
And ratio between vertical and horizontal margin depends on overall "vertical&horizontal" rhythm (google).
To be clear: 1em = `font-size`, 2em = 2 * `font-size` etc. Therefore: if `h1` and `p` both have margin of 0.5em, and `h1` has 20px and `p` 12px `font-size`, then heading's margin is translated to 10px and the paragraph's to 6px.
This site's layout is a good example of how a combination of adherence to multiple patterns yields balanced proportions and an overall consistent structure. The logo, for example, is spaced approximately 14px at the top and bottom within its header segment though it's indented 18px from the edge of the question header, making the top and bottom spacing approximately 30% smaller than the left side - other elements within the header are spaced similarly. On the other hand, the spacing of the text within the question header is approximately 9px on the bottom, 13px on the top, and 24px on the left side. That sets the top spacing to be approximately 50% smaller than the left side, and the discrepancy in the bottom is relative to the alignment of the text to the bottom of the main header in addition to it being header text (separated from the main content with a divider, though closer to that content which it more closely relates to than anything else that surrounds it).
Proportions vary and are an art in themselves. There is a math to it all, but bringing a complex structure together is, in practice, a generally intuitive process.
I'm sure there are multiple books and online resources that touch on this, and they are all likely helpful in their own ways, but my best advice is to be an avid observer of proportions in the things around you - in themselves and relative to their environments and other things in that environment - especially in nature. In time you will hone your intuition and begin to more naturally imitate those proportions and apply them in their appropriate settings.
Consider using a grid layout where your margins are also given by that grid. I tend to use the 960 Grid System but there are many more that other swear by.
For me the benefit of this is largely from choosing something once that works and then not having to spend time thinking about it every time something needs to be laid out.
You should IMHO not mistake the technical implementation of the grid (i.e. the main reason for using a CSS framework) with the underlying design. The default values in 960gs, Blueprint etc. are exactly that: defaults, i.e. tolerable guesses to start from. But they do not release you from making a design decision that might be better suited to your content. All those frameworks are quite well adaptable to different grid setups (see the countless grid generators for them on the web).
I think we differ here on the design side. Giving endless options to make each page as good as it could be in isolation of the others is not something that I believe makes a good UX. Consistency is far more valuable for me. I will however agree that one shouldn't stick exactly to a chosen grid even at the detriment of the page.
There is value in consistency of a grid framework. The example of 960 is very valuable - people are used to that width and designers are used to working with it. Consistency is part of usability.
ahem… where did I state that you should design ‘pages’ in isolation of each other? I had hoped that it was clear that my statement applied to designing a _system_ :-) But the design of a good grid system always should be guided by the content it shall be supporting.