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.
Browser Support
Desktop | |||||
3 | 12 | 1 | 1 | 3.5 | 1 |
Tablets / Mobile | |||||
![]() |
|||||
1 | 18 | 4 | 10.1 | 1 | X |
Last updated by CSSPortal on: 3rd November 2019