CSS Tutorial
Margins are spaces around elements, such as text or images, that provide breathing room and improve readability. There are four types of margins:
In CSS, margins can be set using the following properties:
margin-top
margin-right
margin-bottom
margin-left
To give 20 pixels of space around a paragraph of text, use the following CSS:
p {
margin: 20px;
}
Margins can be used to create space between elements and control their positioning. For example, to create a 10-pixel gap between two paragraphs, use the following CSS:
p + p {
margin-top: 10px;
}
Ensuring that margins are adequate is essential for accessibility. Sufficient margins improve readability, particularly for users with low vision or dyslexia. Consider the following guidelines:
em
or %
) instead of absolute units (such as px
) to ensure margins are responsive.