Top Margin

The CSS margin properties define the space around elements. CSS padding properties refer to the white space within the border or we can say that it’s internal spacing. Setting the value of a margin is NOT the same as setting the padding value, and you should always remember that padding & marginare two different properties.
All four sides (top, bottom, right, left) can be changed independently using separate properties. It is also possible to use negative values to overlap content.
margin-top: 10px;
margin-top: 10pt;
margin-top: 10%;
margin-top: auto;
Many a times we would need to set margin for our objects. This will set the top margin of the object.
It takes the following values.
  1. pt: You can set values in points. (e.g: 10pt or 100pt).
  2. px: You can set values in pixels. (e.g: 10px or 100px).
  3. %: You can set values in percentage. (e.g: 10% or 100%).
  4. auto: This will set a automatic margin.
The following CSS code example shows how to set the value of the top margin:
<style type=”text/css”>
margin-top: 5cm

This paragraph does not have a specified margin.
<div class=”topmargin”>
This paragraph has a top margin of 5cm.


Scroll to Top