If you're looking to implement this using Bootstrap, version 4 has made it easy with the following guidelines:
The naming convention for classes is {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.
Here's a breakdown of the components:
m - for margin classes
p - for padding classes
Sides can be:
t - margin-top or padding-top
b - margin-bottom or padding-bottom
l - margin-left or padding-left
r - margin-right or padding-right
x - both *-left and *-right
y - both *-top and *-bottom
blank - margin or padding on all 4 sides
Available sizes include:
0 - sets margin or padding to 0
1 - default: $spacer * .25
2 - default: $spacer * .5
3 - default: $spacer
4 - default: $spacer * 1.5
5 - default: $spacer * 3
auto - sets margin to auto
Usage example:
.mt-0 {
margin-top: 0 !important;
}
.ml-1 {
margin-left: ($spacer * .25) !important;
}
.px-2 {
padding-left: ($spacer * .5) !important;
padding-right: ($spacer * .5) !important;
}
.p-3 {
padding: $spacer !important;
}
For more information, visit: https://getbootstrap.com/docs/4.0/utilities/spacing/