margin-right - HTML CSS CSS Property

HTML CSS examples for CSS Property:margin-right

Description

The margin-right CSS property sets the right margin of the element.

The following table summarizes the margin-right Property.

Item Value
Default value: 0
Applies to:All elements except those with table display types other than table-caption, table, and inline-table. It also applies to ::first-letter.
Inherited: No
Animatable: Yes.

Syntax

The syntax of the property is as follows:


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

Property Values

The following table describes the values of this property.

Value Description
length A length value in px, pt, cm, em, etc. Negative values are allowed.
percentage The margin in percentage. The percentage is calculated with respect to the width of the element's containing block.
auto The browser will calculate the margin.
initialSets this property to its default value.
inherittake the value of its parent element margin-right property.

The example below shows the margin-right property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS margin-right Property</title>
  <style type="text/css">
    h1 {<!--from   ww  w  .  j  a  va  2s.co m-->
        margin-right: 25px;
    }
    p {
        margin-right: 50px;
    }
</style>
 </head>
 <body>
  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>
  <p><strong>Note:</strong> Play with the margin-right property value to see how it works.</p>
 </body>
</html>

Related Tutorials