To change margin of heading using CSS, you can set the margin
style property for the heading 2 elements with the values like 20px
, 2rem
, 1.1in
, etc.
The following is the typical CSS code to change margin of heading in HTML page using tag name h2
.
h2 {
margin: 20px;
}
h2 {
margin: 2rem;
}
h2 {
margin: 1.1in;
}
We shall go through some working examples on how to change margin of heading using CSS. In the following examples, you may change the value of margin and Run the code to visually observe the changes made to the Heading 2 elements.
This is an example on how to change margin of heading using pixels for margin.
You may edit the following code, and click on Run button.
This is an example on how to change margin of heading using margin relative to parent dimensions.
You may edit the following code, and click on Run button.
This is an example on how to change margin of heading using inches for margin.
You may edit the following code, and click on Run button.