Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Set Margin for All Sides At Once</title> <style> h1 { margin: 50px; /* apply to all four sides */ } p { margin: 25px 75px; /* vertical | horizontal */ } div { margin: 25px 50px 75px; /* top | horizontal | bottom */ } hr { margin: 25px 50px 75px 100px; /* top | right | bottom | left */ } h1, p, div { background: yellow; } </style> </head> <body> <h1>This is a heading</h1> <p>This is a simple paragraph of text.</p> <div>This is a DIV element.</div> <hr> <p><strong>Note:</strong> Play with the margin property value to see how it works.</p> </body> </html>