Explanation of em versus px (pixel) values
The use of pixels is more common, but is also ‘old-fashioned’. Many web developers / designers now use em values. Here we provide an explanation of the differences between px and em.
Explanation of em versus px (pixel)
Pixels are absolute
Em is relative
Example
You set a white space under a heading of 0.4em. Then the white space is 40% of the height of the headline. If the header is 24 pixels high, a white space of 0.4em gives a space of 9.6 pixels. A web builder usually sets a headline in such a way that the height of the headline for mobile display is somewhat smaller, for example 18 pixels. The white space then automatically becomes smaller; namely 7.2 pixels.
This CSS code controls the space above and below all H1, H2, H3, H4, H5 and H6 headings. Note: the first number is the space above the heading, the last number is the space below the heading. The margin in this code example is expressed in
em . You can change this to px, such as 15px. Note that decimals are marked here with a . (period) and not with a comma.
White space is very important
Below you see an image with a heading (bold) with whitespace underneath. Below that, you see a smaller heading with less whitespace.
White space is also part of ‘typography’. See this link for more details.
