CSS marginright Property (original) (raw)
CSS margin-right Property
Last Updated : 28 May, 2026
The margin-right property in CSS is used to add space on the right side of an element. It helps create proper spacing and alignment in webpage layouts.
- It sets the right margin area of an element.
- Negative values are allowed in margin-right.
- The default value of the margin-right property is 0.
**Syntax:
margin-right: length | auto | initial | inherit;
**Property Value:
- **length: This property is used to set a fixed value defined in px, cm, pt, etc. The negative value is allowed and the default value is 0px.
- **inherit: This property is inherited from its parent.
- **auto: This property is used when it is desired and the browser determines it.
- **initial It sets the value of the right-margin to its default value.
**Example: Here, we use margin-right: length; property.
html `
margin-right property<!-- margin-right property -->
<style>
h1 {
margin-right: 100px;
border: 1px solid black;
}
h2 {
margin-right: 250px;
border: 1px solid black;
}
</style>
GeeksforGeeks
margin-right property
`
**Example: Here, we use margin-right: auto; property.
html `
margin-right property<!-- margin-right property -->
<style>
h1 {
margin-right: auto;
border: 1px solid black;
}
h2 {
margin-right: auto;
border: 1px solid black;
}
</style>
GeeksforGeeks
margin-right property
`
**Example: Here, we use margin-right: initial; property.
html `
margin-right property<!-- margin-right property -->
<style>
h1 {
margin-right: auto;
border: 1px solid black;
}
h2 {
margin-right: auto;
border: 1px solid black;
}
</style>
GeeksforGeeks
margin-right property
`