
The CSS margin-left property settles the left margin of an element.
Demo:
Click the “Try it” button to change the left margin of the paragraph:
This is a paragraph.
Syntax:
margin-left: auto|length;
auto – the browser calculates the left margin.
length – defines a fixed left margin in px, cm, etc.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
.ex1 {
margin-left: 40px;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p class="ex1">This is a paragraph with a 40pixels left margin.</p>
<p>This is a paragraph.</p>
</body>
</html>
Output:
This is a paragraph.
This is a paragraph with a 40pixels left margin.
This is a paragraph.
Enjoy coding!
Read also: