CSS | margin-left Property
The margin-left property in CSS is used to set the width of the margin on the left of the desired element. Negative values of this property are allowed.
- A positive value is used when it is desired that the margin is farther away from its neighbors.
- A negative value is used when it is desired that the margin is placed closer.
Syntax:
margin-left: length|auto|initial|inherit;
Property values:
- length : Sets a fixed value defined in px, cm, pt. Negative values as mentioned earlier are allowed. 0 px is the default value.
margin-left: 15px;
Example 1:
<html><head><title>CSS | margin-left Property</title></head><body><pstyle = "margin-left:15px; border-style:solid ;border-color:black;">This paragraph has 15px margin .</p></body></html>chevron_rightfilter_noneExample 2:
<html><head><title>CSS | margin-left Property</title></head><body><pstyle = "margin-left:20%; border-style:solid ;border-color:black;">This paragraph has 20% margin .</p></body></html>chevron_rightfilter_none -
auto :It is used when it is desired that the browser determines the width of the left margin.
margin-left: auto;
Example:
<html><head><title>CSS | margin-left Property</title></head><body><pstyle = "margin-left:auto; border-style:solid ;border-color:black;">This paragraph has auto margin .</p></body></html>chevron_rightfilter_none - initial :It is used to set the value of the margin-left property to its default value.
margin-left: initial;
Example:
<html><head><title>CSS | margin-left Property</title></head><body><pstyle = "margin-left:initial; border-style:solid ;border-color:black;">This paragraph has initial margin .</p></body></html>chevron_rightfilter_none - inherit :It is used when it is desired that the element inherit the margin-left property of its parent as its own.
margin-left: inherit;
Example 1:
<html><head><title>CSS | margin-left Property</title></head><body><divstyle="margin-left:50px;"><pstyle = "margin-left:inherit; border-style:solid ;border-color:black;">This paragraph has auto margin .</p></div></body></html>chevron_rightfilter_noneExample 2:
<html><head><title>CSS | margin-left Property</title></head><body><pstyle = "margin-left:auto; border-style:solid ;border-color:black;">This paragraph has auto margin .</p><pstyle = "margin-left:10px; border-style:solid ;border-color:black;">This paragraph has 10px margin.</p><br><pstyle = "margin-left:5%;border-style:solid;border-color: black;">This paragraph has 5% margin.</p><br><pstyle = "margin-left:15px; border-style:solid;border-color: black;">This text has an margin of 15px.</p><br><br><pstyle = "margin-left:initial;border-style:solid;border-color: black;">This text has a margin of defaulttypeset by initial</p></body></html>chevron_rightfilter_none
Supported Browsers: The browser supported by margin-left Property are listed below:
- Google Chrome 1.0
- Internet Explorer 6.0
- Opera 3.5
- Firefox1.0
- Safari 1.0
Recommended Posts:
- HTML | DOM Style marginLeft Property
- CSS | transition-property Property
- CSS | top Property
- CSS | right Property
- CSS | all Property
- CSS | animation-name Property
- CSS | height Property
- CSS | padding-right Property
- CSS | border-right Property
- CSS | order property
- CSS | grid-row Property
- HTML | DOM name Property
- CSS | visibility Property
- CSS | z-index Property
- CSS | direction Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



