My recommendation: If you're a CSS beginner don't worry, go read this article first then come back to this one.
Make sure you open up the "BoxModel.png" image and keep it open while you read the article.
What Is Padding?
Padding Property: defining the exact space (in pixels) between your element/content and this element border. In other words padding clears an area around the content inside the border of an element. (Padding is the inner space of the element)
Padding Syntax:
padding: length px;
Shorthand property: padding:25px 50px 75px 100px;
(top padding is 25px, right padding is 50px, bottom padding is 75px, left padding is 100px) "Padding values are set clockwise, starting from the top"
Separate property: padding-top, padding-right, padding-bottom, padding-left
What Is Margin?
Margin Property: defining the exact space (in pixels) around elements. . In other words the margin clears an area around an element outside the border of an element. (Margin is the outer space of an element)
Padding Syntax:
margin: length px;
Shorthand property: margin:25px 50px 75px 100px;
(top margin is 25px, right margin is 50px, bottom margin is 75px, left margin is 100px) "Margin values are set clockwise, starting from the top"
Separate property: margin-top, margin-right, margin-bottom, margin-left
What Is Box Model?
The Box Model is a term used when taking about layout using CSS, basically all HTML can be considered as boxes. CSS Box Model is a box that wraps around every HTML element in your document or design, the box is consists of your actual content then a padding space around it, then a border containing both the padding area and the content, at the end there is a marring area around all. The box model allows designer to place a border around elements and space elements in relation to it. Please refer to the Box Model image attached with this article for a better look over the box model.
Layout Tips - when using Padding and Margins
You most know that Padding adds to your total physical width of your element that you used padding in. So for example, if you had an image with a 40 pixels wide, and you specified a left and right padding of 10 pixels, then you will end up with a new width for this element of 60 pixels. [40 (content) + 10px (left padding) + 10px (right padding) = 60 px]
Also you must know that Margin on the other hand does not directly affect height or width of your element.
That's all you need to know about Box Model and Padding vs. Margin, you can start laying out your design in style using CSS most famous techniques. For more special tips, techniques and CSS tutorials stay tuned for my next lesson on CSS Essentials series.
Published by Peter R
A senior web developer with wide experience in web programming languages like JavaScript, AJAX and CSS. I've a great interest in web technologies and gadgets since collage. Famous for writing How-to guides a... View profile
- How to Understand The Depth of a Child's MindEver wondered what goes on in a child's mind? What it is capable of? Let's do a deep dive into the mind of a child and discover what it is capable of doing.
How Women Can Enjoy Watching the Super Bowl (and Other Sports)Even the most uninterested women will enjoy watching sports after reading these tips.
10 Best Ways to Understand the Stock MarketIt took me 10 hard years from losses to gains to feel real comfortable in my knowledge as a trader in the stock market. I have incorporated this same idea with mutual funds in m...- The Complexities of the Japanese TeahouseIn this paper, the intricacies and underlying significance of various aspects of the traditional teahouse will be discussed in detail, in addition to a brief introduction to the Japanese tea ceremony.
- The Goals of a So-called Academic Who Yearns to Be a WriterAs I try to come to grips with the divergent ways my life goes and bring them into converge, I try to come up with life goals that allow me to bring my creative and acedemic work together.
- CSS Essentials: Foundation for CSS2 Beginners
- Styling CSS and HTML Unordered Lists
- Life, Living and Human Nature. Part 2
- Explaining the Fundamental Contributing Factor Theory Accident Model
- The Fundamental Aspects of Human Relations
- The Heart of Religion Through Film
- How to Understand the Stock Market
- Padding vs. Margin
- Box Model
- Layout Design





1 Comments
Post a CommentHi guys,
please refer to the following link http://img685.imageshack.us/img685/3402/boxmodel.png for the BOX Model image mentioned on the article. I forgot to upload it with the article before publishing. Have fun.
~Peter