The margin property defines the space around an HTML element.
There are properties for setting the margin for each side of an element (top, right, bottom, and left).
You can set following Borders properties −
margin-top :The margin-top specifies the top margin of an element.
margin-right : The margin-right specifies the right margin of an element.
margin-bottom : The margin-bottom specifies the bottom margin of an element.
margin-left : The margin-left specifies the left margin of an element.
All the margin properties can have the following values:
auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
% - specifies a margin in % of the width of the containing element
inherit - specifies that the margin should be inherited from the parent element
Example : CSS - Margins
<!DOCTYPE html>
<html>
<head>
<style>
h3{
border: 1px solid black;
margin-top: 10px;
margin-bottom: 100px;
margin-right: 300px;
margin-left: 80px;
}
</style>
</head>
<body>
<p>Code Always.</p>
<h3>code always to become best programmer.</h3>
</body>
</html>
When the above code is compiled , it produces the following result.
Result
Code Always.
Code Always To Become Best Programmer.
You can set CSS margin properties inline, internal and external way of using CSS in your HTML page.