margin-left - HTML CSS CSS Property

HTML CSS examples for CSS Property:margin-left

Description

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

The following table summarizes the margin-left 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-left:      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-left property.

The example below shows the margin-left property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS margin-left Property</title>
  <style type="text/css">
    h1 {<!--from  w w w  .  j ava2s  .com-->
        margin-left: 25px;
    }
    p {
        margin-left: 50px;
    }
</style>
 </head>
 <body>
  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>
 </body>
</html>

Related Tutorials