CSS Tutorials

Padding In CSS
Previous Home Next

A padding is the space between an element's border and the content within it.The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.

The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once. The padding CSS property sets the required padding space on all sides of an element. The padding area is the space between the content of the element and its border. Negative values are not allowed.

The padding property in CSS defines the innermost portion of the box model, creating space around an element's content, inside of any defined margins and/or borders.Most of the rules for margins also apply to padding, except there is no "auto" value, and negative values cannot be declared for padding.

CSS Code

padding-top: length percentage; 
padding-left: length percentage;
padding-right: length percentage;
padding-bottom: length percentage;

In the above css code have 2 choices of values for the padding property:

  • length
  • percentage

You can also declare all the padding of an element in a single property as follows:

padding: 20px 20px 20px 20px;

 

If you declare all 4 values as I have above, the order is as follows:

  1. top
  2. right
  3. bottom
  4. left
Simple example
<html>
<head>
<style>
p.padding {
font:"Times New Roman", Times, serif;
background-color:#CCCCCC;
padding-left:10px;
padding-right:10px;
padding-top:20px;
padding-bottom:20px;
}
</style>
</head>
<body>
<p class="padding">Example of padding</p>
</body>
</html>

Output

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: