CSS margin-right property

CSS Margin-right Property

Description

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

Possible Values

  • length – Any length value.
  • percentage – The width of the margin is calculated relative to the width of the element’s containing block.


  • auto – The default value allows the browser to automatically set margins.

Applies to

All HTML elements.

DOM syntax

object.style.marginRight = "5px" 

Example

This is an 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 the following −

CSS Margin-right Property

Leave a Reply

Your email address will not be published. Required fields are marked *