Padding
Published Aug 8, 2021Updated Apr 19, 2023
Contribute to Docs
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.
Syntax
In CSS, you can modify this space with the padding
property.
p.content-header {border: 3px solid coral;padding: 10px;}
Here, the code added 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 the content look less cramped.
Video Walkthrough
Watch this video on the differences between the CSS margin and padding properties.
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:
Padding
- padding
- Shorthand property for padding-top, padding-bottom, padding-left and padding-right that sets the space between the content and margin of an element or for each side individually.
- padding-bottom
- Defines the width of the bottom padding for an element.
- padding-left
- Defines the width of the left padding for an element.
- padding-right
- Defines the width of the right padding for an element.
- padding-top
- Defines the width of the top padding for an element.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn CSS
In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.Beginner Friendly6 hours