Skip to Content
The Box Model
Padding I

The space between the contents of a box and the borders of a box is known as padding. Padding is like the space between a picture and the frame surrounding it. In CSS, you can modify this space with the padding property.

p.content-header { border: 3px solid coral; padding: 10px; }

The code in this example puts 10 pixels of space between the content of the paragraph (the text) and the borders, on all four sides.

The padding property is often used to expand the background color and make content look less cramped.

If you want to be more specific about the amount of padding on each side of a box’s content, you can use the following properties:

  1. padding-top
  2. padding-right
  3. padding-bottom
  4. padding-left

Each property affects the padding on only one side of the box’s content, giving you more flexibility in customization.

p.content-header { border: 3px solid fuschia; padding-bottom: 10px; }

In the example above, only the bottom side of the paragraph’s content will have a padding of 10 pixels.



In one line, set the .navigation li elements to have 20 pixels of padding. Click Run and observe their change.


Look at the red boxes at the bottom of the web page. Set the .share a elements to have 14 pixels of padding in style.css and run your code. Observe how the red boxes at the bottom of the page changed.


Set the top and bottom padding of h2 elements to 20 pixels and set the left and right padding of h2 elements to 30 pixels.

Folder Icon

Take this course for free

Already have an account?