Number 2 of this exercise says “the height and width of a content area can be set in pixels or percentage”. What is the difference between these two units and how do I know which unit to use?

Question

Number 2 of this exercise says “the height and width of a content area can be set in pixels or percentage”. What is the difference between these two units and how do I know which unit to use?

Answer

A pixel is an absolute unit of measure equal to 1/96 of an inch. On the other hand, percentage is a relative unit of measure and is depended on the specific property in question. For example, the width and height properties define percentages relative to the width and height of a parent element whereas the font-size property defines percentages relative to the font-size of a parent element.

Both units have their uses but one major advantage of percentages is that this unit lends itself more naturally to responsive design.