CSS - margin-right



Description

The margin-right property sets the width of the margin on the right of an element.

Possible Values

  • length − Any length value.

  • percentage − The margin's width is calculated with respect to the width of the element's containing block.

  • auto − Default, Let the browsers automatically set the margin.

Applies to

All the HTML elements.

DOM Syntax

object.style.marginRight = "5px"

Example

Here is the example −

<html>
   <head>
   </head>
   
   <body>
      <p style = "margin-right: 15px; border:1px solid black;">
         This is a paragraph with a specified right margin
      </p>
      <p style = "margin-right: 5%; border:1px solid black;">
         This is another paragraph with a specified right margin in percent
      </p>
   </body>
</html> 

This will produce following result −

Advertisements