Margin-right

CSS margin-right property is used to define how much the right margin of the element will be set. We can also give negative values.

CSS Syntax

margin-top: length | auto | initial | inherit;

Let's see an example:

<!DOCTYPE html>
<html>
   <head>
     <style>
          .right { margin-right: 250px;}
     </style>
   </head>
   <body>

        <p>This paragraph has no margin-right which is defined especially. This paragraph has no margin-right which is defined especially.</p>
        <p class="right">But you can see another text here which has a right margin defined as 200px. But you can see another text here which has a right margin defined as 250px.</p>

   </body>
</html>

Here the result is:



Property Values

Value Descriptions
length It sets the right margin in px, pt, cm, etc. Its default value is 0px.
% It sets right margin in percent of the width of the containing element.
auto When we choose auto value, the browser sets the right margin.
initial It makes the property use its default value.
inherit It inherits the property from its parents element.