This first example shows an h5 element with the margins poking out the top and bottom of its container.
The second example shows that the margins can be contained by using a small amount of padding on the container.
The third example shows that the margins can be contained by using a border on the container.
The fourth example shows that the problem can also be solved by applying padding, rather than margins to the heading element.