Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML How to Make a Website CSS: Cascading Style Sheets Center the Wrapper

What does padding really do?

I want to get a clear conception of this padding property. Thanks in advance.

1 Answer

Padding is the space inside an element, and margin is the space around an element. The border is right between.

Look here:

        margin
--------------------
|      padding     |
|                  |
|      content     |
|                  |
|      padding     | <- Border
--------------------
        margin


           margin
----------------------------
|         padding          |
|                          |
| content of other element |
|                          |
|         padding          | <- Border
----------------------------
           margin

Look at this post for more information.

Also, check out the CSS box model at w3schools.

Finally, I must mention that doodling around with stuff will help you understand how the thing you're using works.

Here's an experiment: try making an h1 element in the HTML and setting it's background color to something different from the background color that the H1 is on. Then, try adding padding. You should see the output pretty clearly. Try different amounts of padding and seeing its output! :smile: