Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Margins and Padding.docx58.7 KB Margins and Padding - Solution.docx
58.8 KB
Quick reference
Margins and Padding
Margins add space around the outside of an element. Paddings add space around the inside of an element.
When to use
Whenever you need to add space around the inside or outside of an element, use margins or padding.
Instructions
Margin adds space around the outside of an element. It looks like this:
margin: 5px;
You can desgnate different sizes for each side:
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 10px;
You can use a shorthand:
margin: 5px 10px 5px 12px;
...which corresponds to top, right, bottom, left.
Padding adds space around the inside of an element:
padding: 10px;
You can desgnate different sizes for each size:
padding-top: 5px;
padding-bottom: 10px;
padding-left: 4px;
padding-right: 12px;
And you can use a shorthand:
padding: 5px 12px 4px 8px;
...which corresponds to top, right, bottom, left.
Hints & tips
- Margins add space around the outside of an element.
- Padding adds space around the inside of an element.
Lesson notes are only available for subscribers.