![html margin left](https://cdn.educba.com/academy/wp-content/uploads/2020/02/html-margin-left.jpg.webp)
Introduction to HTML margin-left
HTML margin-left sets the margin area on the left side of an element. HTML has many pre-defined tags used for creating web pages more effectively, and additionally, CSS styles are mode advanced and decoratively in the web sites. By using this terminology, the user will attract the web sites more frequently, so it’s helpful for business perspectives. Html margin properties are one of the features which helps for creating the outside space of the HTML web screens, and additionally, they have some different types like margin-left, margin-right, margin-top, margin-bottom; these are some types to decide the outline space layout on the web pages. Each and Every type have their own possible length values.
Syntax:
Html margins have a different set of styles based on where we used them in the documents. If we use the HTML margin, CSS style documents, it is used for margins.
<html>
<head>
<style>
div
{
Margin:values;
}
</style>
</head>
</html>
The above codes are the basic syntax that will we discuss on the HTML margin styles in the web pages. In HTML, the dom pattern is mainly used for the HTML objects that will work on the back end of the codes.Html margins it depends upon the element with a different set of margins that will be applied on the web page document. We can use javascript functions to set the margins automatically on the web pages.
How Does HTML margin-left Works?
In HTML and CSS, the margins specify a fixed length using HTML and CSS standard style units; even negative values are also allowed in the web pages. Before that, we will set the margin-left property to have some values both we will assign or default values assigned in the document. The default value is “auto”, or else we will declare the values as “inherit”, “length”, and “percentage”, each of the specified values with a different set of sub-values based upon will use the margin-left property values.
The length will calculate the length or fixed length of the CSS units. A percentage of the width and height is calculated upon the HTML blocks; negative values also allowed in this field. If suppose margin has a top value attribute, the user browser will take the value as a percentage from the width; it will not specify the height of the blocks.
The user browser will calculate the margin-left value as auto; it depends upon the space available in the outer area of the document or web pages. Inherit value is used for the parent-child relationship of the HTML contents mainly it specified the width of the margin-left property with values. When we calculate the height and width of the HTML elements in the web pages, we mainly do not include the margins for that calculations; we include other HTML elements like padding, other content areas, borders, etc. Only calculate the available space of the HTML element margin-size property of the document. Popular Course in this categoryHTML Training (12 Courses, 19+ Projects, 4 Quizzes)12 Online Courses | 19 Hands-on Projects | 89+ Hours | Verifiable Certificate of Completion | Lifetime Access | | 4 Quizzes with Solutions
4.5 (6,502 ratings)Course Price
₹6999 ₹41999
View Course
Related CoursesBootstrap Training (2 Courses, 6+ Projects)XML Training (5 Courses, 6+ Projects)CSS Training (9 Courses, 9+ Projects)
If we have declared the two set of margins in the HTML its will collide; suppose we have assigned one block containing the right side of the margin and float point has right only, and another block containing left margin with the same as float point, the first larger point of the margin remains same, and it doesn’t change values smaller margin area of the block will be collapsed, and it won’t be shown properly in the web pages it maybe disappears in the web screens. Generally, margins are transparent in nature.
When margin will use as a shorthand property to specify margin as a width rather than we use the other type margin specifications of the cluster codes because it will difficult for reading the codes in the developer areas, if sometimes we use margin-bottom values the same as one in another margin types, i.e.)one class is differentiated into another class in CSS styles. We can specify the possible length values of each property wherever we use in the HTML tag elements length value is equal and relate to the height of the text fonts and also element fonts. In browser, compatibility version supposes IE version 3 margin has a specified value to the object that is default value is added to the web page in IE 4, and later versions margin value is absolute in the HTML documents.The margin property value is not supported in the HTML table elements <td> and <tr> objects in IE 4 version,but it will work in IE 3 version.If we will apply the margin values in to table cells using <div> or <p> tags in IE 4 versions.
Examples of HTML margin-left
Below are the examples of HTML margin-left:
Example #1
Code:
<html>
<head>
<style>
{
margin: 2;
}
div {
width: 210px;
height: 130px;
background:green;
border-radius: 13px;
}
.sample {
background-color: green;
margin-left: 3%;
}
.sample1 {
background-color: yelllow;
}
.sample2 {
background-color: solid green;
margin-left: -13%;
}
</style>
</head>
<body>
<div id="sample2">
<marquee> Welcome To My Domain</marquee>
</div>
</body>
</html>
Output:
![HTML margin-left 1](https://cdn.educba.com/academy/wp-content/uploads/2020/02/HTML-margin-left-1.png.webp)
Example #2
Code:
<html>
<head>
<style>
#sample {
width: 120%;
}
table, td, th {
border: 3px solid green;
}
table {
width: 212px;
float: left;
margin: 23px 42px;
}
</style>
</head>
<div id="sample">
<table>
<tr>
<th>Mobile Number</th>
<th>Name</th>
</tr>
<tr>
<td>8220244056</td>
<td>Siva</td>
</tr>
<tr>
<td>9075854876</td>
<td>Raman</td>
</tr>
</table>
<p>
<marquee>Welcome To My Domain</marquee>
</p>
</div>
</html>
Output:
![ID Sample Example](https://cdn.educba.com/academy/wp-content/uploads/2020/02/HTML-margin-left-2.png.webp)
Example #3
Code:
<html>
<head>
<style>
#sample {
width: 120%;
}
table, td, th {
border: 3px solid green;
}
table {
width: 212px;
float: left;
margin: 23px 42px;
}
</style>
</head>
<div id="sample">
<table>
<tr>
<th>Mobile Number</th>
<th>Name</th>
</tr>
<tr>
<td>8220244056</td>
<td>Siva</td>
</tr>
<tr>
<td>9075854876</td>
<td>Raman</td>
</tr>
</table>
<button type="button" onclick="samples()">Set margin</button>
</div>
<script>
function samples() {
document.getElementById("sample").style.margin-left = "11px 23px 34px 47px";
}
</script>
</html>
Output:
![HTML margin-left 3](https://cdn.educba.com/academy/wp-content/uploads/2020/02/HTML-margin-left-3.png.webp)
![HTML margin-left 4](https://cdn.educba.com/academy/wp-content/uploads/2020/02/HTML-margin-left-4.png.webp)
The above three examples will give three different usages of the margin properties first example is the basic margin property is used for the CSS style and HTML, the second example will create the tables in HTML and set the margin-left property values in the web page, the final example is same as previous one, but javascript is set the margin values automatically.
Conclusion
In HTML, we have seen margin property type as margin-left in HTML; based on that, we have altered the HTML tables, images and videos; also, we will align and set the layout as margin-left in the HTML documents. In browser compatibility, html5 is not supported in some elements.
Recommended Articles
This is a guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples, along with its Code Implementation. You can also go through our other suggested articles to learn more –