सीएसएस मार्जिन प्रॉपर्टी मार्जिन-टॉप, मार्जिन-राइट, मार्जिन-बॉटम और मार्जिन-लेफ्ट के लिए शॉर्टहैंड है। यह हमें तत्वों के आसपास के स्थान को निर्दिष्ट करने में सक्षम बनाता है। हम अलग-अलग पक्षों के लिए मार्जिन भी सेट कर सकते हैं।
सिंटैक्स
CSS मार्जिन प्रॉपर्टी का सिंटैक्स इस प्रकार है -
Selector {
margin: /*value*/
} उदाहरण
निम्नलिखित उदाहरण CSS मार्जिन गुण को दर्शाते हैं -
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 10px 50px 20px;
padding: 1rem;
border: dashed;
}
p {
text-align: center;
}
#demo {
margin-left: -80px;
box-shadow: inset 0 0 10px brown;
}
</style>
</head>
<body>
<div></div>
<p>This is demo text.</p>
<p id="demo">Another demo text.</p>
<p>This is new demo text.</p>
</body>
</html> आउटपुट
यह निम्न आउटपुट देता है -

उदाहरण
<!DOCTYPE html>
<html>
<head>
<style>
ul {
margin: auto;
background-image: linear-gradient(to right, khaki, aliceblue, skyblue, rebeccapurple);
width: 20em;
}
li {
margin-top: 3px;
}
li + li {
margin-left: -20px;
}
li:last-child {
margin-left: 75px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<ul>
<li>This is demo list item.</li>
<li>This is another list item with different style.</li>
<li>This is our third demo text with another style.
</li>
</ul>
</body>
</html> रूपरेखा
यह निम्न आउटपुट देता है -
