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.

**Syntax:

margin-right: length | auto | initial | inherit;

**Property 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

`