To add space around HTML element border. CSS also allows to set margin of specific sides like top, right, bottom, left. Margin allow negative values.

margin-top

To add spaces from top border of HTML element.

<html>
<head>
<style type="text/css">
#mydv{
       border: 1px solid black;
       margin-top: 25px;
}
</style>
</head>
<body>
<div id="mydv">
Margin top example
</div>
</body>
</html>

margin-left

To add spaces from left border of HTML element.

<html>
<head>
<style type="text/css">
#mydv{
       border: 1px solid black;
       margin-left: 25px;
}
</style>
</head>
<body>
<div id="mydv">
Margin left example
</div>
</body>
</html>

margin-right

To add spaces from right border of HTML element.

<html>
<head>
<style type="text/css">
#mydv{
       border: 1px solid black;
       margin-right: 25px;
}
</style>
</head>
<body>
<div id="mydv">
Margin right example
</div>
</body>
</html>

margin-bottom

To add spaces from bottom border of HTML element.

<html>
<head>
<style type="text/css">
#mydv{
       border: 1px solid black;
       margin-bottom: 25px;
}
</style>
</head>
<body>
<div id="mydv">
Margin bottom example
</div>
</body>
</html>

margin

To add spaces from top, right, bottom, left border of HTML element.

<html>
<head>
<style type="text/css">
#mydv{
       border: 1px solid black;
       margin: 25px;
}
</style>
</head>
<body>
<div id="mydv">
Margin example
</div>
</body>
</html>