Open In App

CSS margin-right Property

The margin-right property in CSS is used to set the right margin of an element. It sets the margin-area on the right side of the element. Negative values are also allowed. The default value of margin-right property is zero. 

Syntax:



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

Property Value:

Example: In this example, we are using margin-right: length; property.






<!DOCTYPE html>
<html>
<head>
    <title>
        margin-right property
    </title>
 
    <!-- margin-right property -->
    <style>
        h1 {
            margin-right: 100px;
            border: 1px solid black;
        }
 
        h2 {
            margin-right: 250px;
            border: 1px solid black;
        }
    </style>
</head>
 
<body style="text-align:center">
    <h1>GeeksforGeeks</h1>
    <h2>margin-right property</h2>
</body>
</html>

Output:

Example: In this example, we use margin-right: auto; property.




<!DOCTYPE html>
<html>
<head>
    <title>
        margin-right property
    </title>
 
    <!-- margin-right property -->
    <style>
        h1 {
            margin-right: auto;
            border: 1px solid black;
        }
 
        h2 {
            margin-right: auto;
            border: 1px solid black;
        }
    </style>
</head>
 
<body style="text-align:center">
    <h1>GeeksforGeeks</h1>
    <h2>margin-right property</h2>
</body>
</html>

Output:

Example: In this example, we use margin-right: initial; property.




<!DOCTYPE html>
<html>
<head>
    <title>
        margin-right property
    </title>
 
    <!-- margin-right property -->
    <style>
        h1 {
            margin-right: auto;
            border: 1px solid black;
        }
 
        h2 {
            margin-right: auto;
            border: 1px solid black;
        }
    </style>
</head>
 
<body style="text-align:center">
    <h1>GeeksforGeeks</h1>
    <h2>margin-right property</h2>
</body>
</html>

Output:

Supported Browsers: The browser supported by margin-right property are listed below:


Article Tags :