156 views
How to add Padding in Html
To add padding to an HTML element, you can use the CSS padding
property. The padding
property allows you to specify the space between the content of an element and its border.
There are different ways to apply padding in HTML:
- Inline Style:
HTML
<div style="padding: 20px;">Content with padding</div>
- Internal CSS:
HTML
<style>
.my-element {
padding: 20px;
}
</style>
<div class="my-element">Content with padding</div>
- External CSS:
CSS
/* styles.css */
.my-element {
padding: 20px;
}
HTML
<!-- index.html -->
<link rel="stylesheet" href="styles.css">
<div class="my-element">Content with padding</div>
In the examples above, the padding
value is set to 20px
, but you can adjust it to your desired size. You can also specify different padding values for each side of the element using the padding-top
, padding-right
, padding-bottom
, and padding-left
properties.
Note that padding adds space inside the element, affecting its content. If you want to add space outside the element, you can use the CSS margin
property instead.