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.
Example: Here, we use margin-right: auto; property.
Example: Here, we use margin-right: initial; property.