Box Model - CSS Reference
Box Model - CSS Reference
Transitions Typography
# border-bottom-width
Like border-width , but for the bottom border only.
border-bottom-width: 0; default
Hello world
# border-left-width
Like border-width , but for the left border only.
border-left-width: 0; default
Hello world
border-left-width: 4px;
Hello world
# border-right-width
Like border-width , but for the right border only.
border-right-width: 0; default
Hello world
Share Menu
border-right-width: 4px;
Hello world
# border-top-width
Like border-width , but for the top border only.
border-top-width: 0; default
Hello world
border-top-width: 4px;
Hello world
# border-width
Defines the width of the element's borders.
border-width: 1px;
Hello world
Share Menu
border-width: 2px 0;
Defines the top and bottom borders to 2px, the left and right to 0.
Hello world
# box-sizing
Defines how the width and height of the element are calculated: whether they include the padding and
borders or not.
The width and height of the element only apply to the content of the element.
border-width: 12px
padding: 30px
width: 200px
The content has the defined width. The box accomodates for those dimensions.
200px
Hello world
box-sizing: border-box;
The width and height of the element apply to all parts of the element: the content, the padding and the borders.
border-width: 12px
padding: 30px
width: 200px
Share Menu
The box has the defined width. The content accomodates for those dimensions, and ends up being 200px - 60px -
24px = 116px.
200px
Hello world
# height
Defines the height of the element.
The element will automatically adjust its height to allow its content to be displayed correctly.
height: 100px;
If the content does not fit within the specified height, it will overflow. How the container will handle this
overflowing content is defined by the overflow property.
Share Menu
In collections: Box-Model Typography Permalink Share MDN
# line-height
Defines the height of a single line of text.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
felis hendrerit sit amet.
You can use unitless values: the line height will be relative to the font size.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
felis hendrerit sit amet.
line-height: 30px;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
line-height: 0.8em;
You can use em values: like with unitless values, the line height will be relative to the font size.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
felis hendrerit sit amet.
Share Menu
In collection: Box-Model Permalink Share MDN
# margin-bottom
Defines the space outside the element, on the bottom side.
margin-bottom: 0; default
First item
Target
Third item
margin-bottom: 30px;
First item
Target
30px
Third item
margin-bottom: 2em;
First item
Target
2em
Share Menu
Third item
margin-bottom: 10%;
First item
Target
10%
Third item
# margin-left
Defines the space outside the element, on the left side.
margin-left: 0; default
First item
Target
Third item
margin-left: 50px;
Third item
margin-left: 7em;
First item
7em
Target
Third item
margin-left: 30%;
First item
30%
Target
Third item
margin-left: auto;
The auto keyword will give the left side a share of the remaining space.
When combined with margin-right: auto , it will center the element, if a fixed width is defined.
First item
auto
Target
width: 200px
# margin-right
Defines the space outside the element, on the right side.
margin-right: 0; default
First item
Target
Third item
margin-right: 50px;
First item
50px
Target
Third item
margin-right: 7em;
First item
7em
Target
Share Menu
Third item
margin-right: 30%;
First item
30%
Target
Third item
margin-right: auto;
The auto keyword will give the right side a share of the remaining space.
When combined with margin-left: auto , it will center the element, if a fixed width is defined.
First item
auto
Target
width: 200px
Third item
# margin-top
Defines the space outside the element, on the top side.
margin-top: 0; default
First item
Share Menu
Target
Third item
margin-top: 30px;
First item
30px
Target
Third item
margin-top: 2em;
First item
2em
Target
Third item
margin-top: 10%;
First item
10%
Share Menu
Target
Third item
# margin
Shorthand property for margin-top margin-right margin-bottom and margin-left .
margin: 0; default
First item
Target
Third item
margin: 30px;
First item
30px
30px
Third item
To remember the order think about the values you haven't defined.
Share Menu
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of
top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
First item
30px
30px
Third item
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
First item
30px
45px
Third item
Share Menu
First item
30px
45px
Third item
# max-height
Defines the maximum height the element can be.
max-height: 2000px;
If the maximum height is larger than the element's actual height, the max height has no effect.
Share
max-height: 100px; Menu
If the content does not fit within the maximum height, it will overflow. How the container will handle this
overflowing content is defined by the overflow property.
# max-width
Defines the maximum width the element can be.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
felis hendrerit sit amet. Pellentesque interdum, nisl nec interdum maximus, augue diam porttitor lorem, et sollicitudin
felis neque sit amet erat.
max-width: 2000px;
If the maximum width is larger than the element's actual width, the max width has no effect.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
felis hendrerit sit amet. Pellentesque interdum, nisl nec interdum maximus, augue diam porttitor lorem, et sollicitudin
felis neque sit amet erat.
max-width: 150px;
If the content does not fit within the maximum width, it will automatically change the height of the element to
accomodate for the wrapping of the content.
Share Menu
Lorem ipsum dolor sit
amet, consectetur
adipiscing elit. Etiam
semper diam at erat
pulvinar, at pulvinar
felis blandit.
Vestibulum volutpat
tellus diam,
consequat gravida
libero rhoncus ut.
Maecenas imperdiet
felis nisi, fringilla
luctus felis hendrerit
sit amet.
Pellentesque
interdum, nisl nec
interdum maximus,
augue diam porttitor
lorem, et sollicitudin
felis neque sit amet
erat.
# min-height
Defines the minimum height of the element.
min-height: 0; default
min-height: 200px;
If the minimum height is larger than the element's actual height, the min height will be applied.
min-height: 5px;
If the minimum height is smaller than the element's actual height, the min height has no effect.
# min-width
Defines the minimum width of the element.
min-width: 0; default
Hello world
min-width: 300px;
If the minimum width is larger than the element's actual width, the min width will be applied.
Hello world
min-width: 5px;
Share Menu
If the minimum width is smaller than the element's actual width, the min width has no effect.
Hello world
# padding-bottom
Defines the space inside the element, on the bottom side.
padding-bottom: 0; default
First item
Target
Third item
padding-bottom: 50px;
First item
Target
50px
Third item
padding-bottom: 7em;
First item
Target
7em
Share Menu
Third item
padding-bottom: 30%;
First item
Target
30%
Third item
# padding-left
Defines the space inside the element, on the left side.
padding-left: 0; default
First item
Target
Third item
padding-left: 50px;
50px
Target
Third item
padding-left: 7em;
First item
7em
Target
Third item
padding-left: 30%;
First item
30%
Target
Third item
# padding-right
Defines the space inside the element, on the right side.
padding-right: 0;
Share default
Menu
Removes any padding on the right.
First item
Target
Third item
padding-right: 50px;
First item
50px
Target
Third item
padding-right: 7em;
First item
7em
Target
Third item
padding-right: 30%;
Third item
# padding-top
Defines the space inside the element, on the top side.
padding-top: 0; default
First item
Target
Third item
padding-top: 50px;
First item
50px
Target
Third item
padding-top: 7em;
First item
Share Menu
7em
Target
Third item
padding-top: 30%;
First item
30%
Target
Third item
# padding
Shorthand property for padding-top padding-right padding-bottom and padding-left .
padding: 0; default
Target
padding: 30px;
30px
Share
30pxTarget
Menu
30px
30px
To remember the order think about the values you haven't defined.
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of
top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
30px
60px Target 60px
30px
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
30px
60px Target 60px
45px
30px
85px Target 60px
Share 45px Menu
In collection: Box-Model Permalink Share MDN
# width
Defines the width of the element.
The element will automatically adjust its width to allow its content to be displayed correctly.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus felis
hendrerit sit amet.
width: 240px;
width: 50%;
Share Menu