CSS Margin and Padding
Margin
Margin creates space outside an element’s border. Vertical margins between normal block elements can collapse in some layouts.
Padding
Padding creates space inside the border, around an element’s content.
.card {
margin: 1.5rem auto;
padding: 1rem 1.25rem;
}
.section { padding-block: 3rem; }
.stack > * + * { margin-block-start: 1rem; }
Logical properties such as padding-block adapt better to writing modes than physical top/bottom properties.
Practice
Center a card with auto side margins and add comfortable inner padding.
Want to learn this professionally?
Explore practical IT training at Cyber Code Academy.
View Academy Courses