CSS margin-right Property

Description

The margin-right property of an element sets the margin space required on the right of an element. A negative value is also allowed.

Initial value
0
Applies to
All elements
Inherited
No
Media
Visual
Computed value
As specified, but with relative lengths converted into absolute pixel values.
Animatable
Yes
CSS Version
CSS1, CSS2, CSS3
JavaScript syntax
object.style.marginRight

Syntax

margin-right: <length> | <percentage> | auto

Values

  • <length>Specifies a fixed length, using any standard CSS length units. Negative Values are allowed.
  • <percentage>A percentage always relative to the width of the containing block.
  • inherit

Example

<div class="parent"> 
<div class="child">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
.parent { 
   background: #e2edc1;
   padding: 10px;
} 
.child { 
   border: 3px solid #333391; 
   padding: 10px;
   margin: 10px;
   margin-right: 40px;
}

Give it a Try

Click the button below to experiment with this property.

Give it a Try!

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
312113.51
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
118410.11X

Last updated by CSSPortal on: 3rd November 2019