CSS Properties: How to set the top margin for a paragraph element
Solution:
HTML Code:
Explanation:
- This HTML document demonstrates how to set the top margin for specific paragraph elements using CSS.
- CSS comments are added to explain each section of the code.
- A class named w3r is defined to style specific paragraphs with a top margin.
- The margin-top property is used to set the top margin for paragraphs with class w3r. The value 2cm represents the top margin, set to 2 centimeters.
Live Demo:
See the solution in the browser
Supported browser
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics