WebTrainingRoom Online Courses
Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing

How to write Margin CSS style for html div, span, p, table

CSS margin property indicates the space around an HTML element. We can use negative values to overlap content, means margin can be less than zero

How to define Margin in CSS


Any margin property can have the following values:

  • % - indicate margin in % of the width of container
  • length - specifies a fix margin in px, pt, cm, etc.

Margin can be set for each side as shown in above example, but if you don’t specify any side then margin will be applied to all the side like below example


Above style indicates 10px margin for each side of div

Different type of margin
margin-top indicates the top margin of an html element
margin-bottom indicates the bottom margin of an html element
margin-left indicates the left margin of an html element
margin-right indicates the right margin of an html element

Margin Auto Example

Margin auto will keep any div in centre of html page

<div style="width:50%;margin: 0 auto;">

Name Email Website
Margin CSS Style, CSS Tutorial