Color: Hello World
Color: Hello World
Applies a transparent color to the text. The text will still take up the space it should.
Hello world
color: red;
When using multiple values, the font-family list of font families defines the priority in
which the browser should choose the font family.
The browser will look for each family on the user's computer and in any @font-
face resource.
The list is prioritized from left to right: it will use the first value if it's available, or go to the
next one, until the end of the list is reached. The default font family is defined by the browser
preferences.
In this example, the browser will try to use Source Sans Pro if it's available. If it can't find it,
it will try to use Arial. If it's not available either, it will use the browser's sans-serif font.
Hello world
The quick brown fox jumps over the lazy dog
font-family: serif;
The browser will use a serif font family: all characters have stroke endings.
Hello world
The quick brown fox jumps over the lazy dog
font-family: sans-serif;
The browser will use a sans-serif font family: no character has stroke endings.
Hello world
The quick brown fox jumps over the lazy dog
font-family: monospace;
The browser will use a monospace font family: all characters have the same width.
Hello world
The quick brown fox jumps over the lazy dog
font-family: cursive;
You can use relative keywords. The value is relative to the parent.
The following are available:
larger
smaller
Parent container: 18px
Font-size: smaller
Font-size: smaller
Font-size: smaller
font-size: x-large;
You can use absolute keywords. The value is relative to the root element <html>.
The following are available:
xx-small
x-small
small
medium
large
x-large
xx-large
<html> root element: 18px
Font-size: x-large
Font-size: x-large
Font-size: x-large
In collection: typographyPermalinkShareMDN
#font-style
Defines how much the text is slanted.
defaultfont-style: normal;
Use the italic version of the font: the letters are slightly slanted.
Hello world
font-style: oblique;
Use the oblique version of the font: the letters are more slanted than italic.
Hello world
In collection: typographyPermalinkShareMDN
#font-variant
Defines which glyph to use for each letter.
defaultfont-variant: normal;
You can use numeric values. They all correspond to a particular named weight:
100 Thin
200 Extra Light
300 Light
400 Normal
500 Medium
600 Semi Bold
700 Bold
800 Extra Bold
900 Ultra Bold
If the font family doesn't provide the requested weight, it will use the closest available one.
Hello world
font-weight: lighter;
You can use relative keywords: lighter or bolder. The browser will use the next available
weight.
Hello world
In collection: typographyPermalinkShareMDN
#font
Shorthand property for font-style font-variant font-weight font-size line-
height and font-family.
In collection: typographyPermalinkShareMDN
#letter-spacing
Defines the spacing between the characters of a block of text.
defaultletter-spacing: normal;
You can use em values: this allows the spacing to remain relative to the font-size.
The quick brown fox jumps over the lazy dog
In collections: box-model typographyPermalinkShareMDN
#line-height
Defines the height of a single line of text.
defaultline-height: normal;
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;
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
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.
In collection: typographyPermalinkShareMDN
#text-align
Defines how the text content of the element is horizontally aligned.
text-align: left;
The text content is aligned to the left.
Hello world
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.
text-align: right;
Removes any text transformation: the text will appear the same as in the HTML code.
Hello world!
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.
text-transform: capitalize;
Words with no space will not break. Sequences of uninterrupted characters will be displayed
on a single line.
Thequickbrownfoxjumpsoverthelazydog
word-break: break-all;
Words with no space will break as soon as they reach the end of a line.
Thequickbrownfoxjumpsoverthelazydog
In collection: typographyPermalinkShareMDN
#word-spacing
Defines the spacing between words of a block of text.
defaultword-spacing: normal;
You can use em values: this allows the spacing to remain relative to the font-size.
The quick brown fox jumps over the lazy dog
#background-attachment
Defines how the background image will behave when scrolling the page.
defaultbackground-attachment: scroll;
The background image will scroll with the page. It will also position and resize itself
according to the element it's applied to.
Hello world
background-attachment: fixed;
The background image will not scroll with the page, and remain positioned according to the
viewport. It will also position and resize itself according to the viewport. As a result, the
background image will probably only be partially visible.
Hello world
In collection: backgroundsPermalinkShareMDN
#background-clip
Defines how far the background should extend within the element.
defaultbackground-clip: border-box;
The background extends completely throughout the element, even under the border.
Hello world
background-clip: padding-box;
The background only extends to the edge of the border: it includes the padding but not the
border.
Hello world
background-clip: content-box;
The background only extends to the edge of the content: it doesn't include the padding, nor
the border.
Hello world
In collection: backgroundsPermalinkShareMDN
#background-color
Defines the color of the element's background.
defaultbackground-color: transparent;
Uses the image defined in the url path. This path can either be relative (to the css file)
or absolute (like http://cssreference.io/images/jt.png).
Hello world
background-image: linear-gradient(red, blue);
You can specify the shape of the radial gradient: circle or ellipse (default).
Hello world
background-image: radial-gradient(circle, green 0%, purple 20%, orange 100%);
Like with the background-position, you can specify the position of the gradient.
Hello world
In collection: backgroundsPermalinkShareMDN
#background-origin
Defines the origin of the background image.
defaultbackground-origin: padding-box;
The background image starts at the edge of the border: within padding but not the border.
Hello world
background-origin: border-box;
The background image only starts at the edge of the content: it doesn't include the padding,
nor the border.
Hello world
In collection: backgroundsPermalinkShareMDN
#background-position
Defines the position of the background image.
defaultbackground-position: 0% 0%;
The background image will be positioned at 0% on the horizontal axis and 0% on the
vertical axis, which means the top left corner of the element.
Hello world
background-position: bottom right;
You can use a combination of position keywords: center, top, bottom, left and right.
Hello world
background-position: center center;
The background image will repeat itself both horizontally and vertically.
Hello world
background-repeat: repeat-x;
You can use percentage values as well. Beware that this can alter the aspect ratio of the
background image, and lead to unexpected results.
Hello world
background-size: contain;
The keyword contain will resize the background image to make sure it remains fully visible.
Hello world
background-size: cover;
The keyword cover will resize the background image to make sure the element is fully
covered.
Hello world
#border-bottom-width
Like border-width, but for the bottom border only.
defaultborder-bottom-width: 0;
border-bottom-width: 4px;
In collection: box-modelPermalinkShareMDN
#border-left-width
Like border-width, but for the left border only.
defaultborder-left-width: 0;
border-left-width: 4px;
In collection: box-modelPermalinkShareMDN
#border-right-width
Like border-width, but for the right border only.
defaultborder-right-width: 0;
border-right-width: 4px;
In collection: box-modelPermalinkShareMDN
#border-top-width
Like border-width, but for the top border only.
defaultborder-top-width: 0;
border-top-width: 4px;
In collection: box-modelPermalinkShareMDN
#border-width
Defines the width of the element's borders.
border-width: 1px;
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.
defaultbox-sizing: content-box;
The width and height of the element only apply to the content of the element.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
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.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
In collection: box-modelPermalinkShareMDN
#height
Defines the height of the element.
defaultheight: auto;
The element will automatically adjust its height 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. Pellentesque interdum, nisl nec interdum maximus, augue diam porttitor lorem, et sollicitudin
felis neque sit amet erat.
height: 100px;
#line-height
Defines the height of a single line of text.
defaultline-height: normal;
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;
Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut. Maecenas imperdiet felis nisi, fringilla luctus
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.
In collection: box-modelPermalinkShareMDN
#margin-bottom
Defines the space outside the element, on the bottom side.
defaultmargin-bottom: 0;
Target
Third item
margin-bottom: 30px;
Target
Third item
margin-bottom: 2em;
You can use (r)em values.
The value is relative to the font size:
em: relative to the element's current font size
rem: relative to <html> the root element's font size
First item
Target
Third item
margin-bottom: 10%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#margin-left
Defines the space outside the element, on the left side.
defaultmargin-left: 0;
Target
Third item
margin-left: 50px;
Target
Third item
margin-left: 7em;
Target
Third item
margin-left: 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
Target
width: 200px
Third item
In collection: box-modelPermalinkShareMDN
#margin-right
Defines the space outside the element, on the right side.
defaultmargin-right: 0;
Target
Third item
margin-right: 50px;
Target
Third item
margin-right: 7em;
Target
Third item
margin-right: 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
Target
width: 200px
Third item
In collection: box-modelPermalinkShareMDN
#margin-top
Defines the space outside the element, on the top side.
defaultmargin-top: 0;
Target
Third item
margin-top: 30px;
Target
Third item
margin-top: 2em;
Target
Third item
margin-top: 10%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#margin
Shorthand property for margin-top margin-right margin-bottom and margin-left.
defaultmargin: 0;
Target
Third item
margin: 30px;
Target
Third item
Target
Third item
Target
Third item
Target
Third item
In collection: box-modelPermalinkShareMDN
#max-height
Defines the maximum height the element can be.
defaultmax-height: none;
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.
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.
In collection: box-modelPermalinkShareMDN
#max-width
Defines the maximum width the element can be.
defaultmax-width: none;
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.
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.
In collection: box-modelPermalinkShareMDN
#min-height
Defines the minimum height of the element.
defaultmin-height: 0;
If the minimum height is smaller than the element's actual height, the min height 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 minimus, augue diam porttitor lorem, et sollicitudin
felis neque sit amet erat.
In collection: box-modelPermalinkShareMDN
#min-width
Defines the minimum width of the element.
defaultmin-width: 0;
If the minimum width is smaller than the element's actual width, the min width has no effect.
Hello world
In collection: box-modelPermalinkShareMDN
#padding-bottom
Defines the space inside the element, on the bottom side.
defaultpadding-bottom: 0;
Target
Third item
padding-bottom: 50px;
Target
Third item
padding-bottom: 7em;
Target
Third item
padding-bottom: 30%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#padding-left
Defines the space inside the element, on the left side.
defaultpadding-left: 0;
Target
Third item
padding-left: 50px;
Target
Third item
padding-left: 7em;
Target
Third item
padding-left: 30%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#padding-right
Defines the space inside the element, on the right side.
defaultpadding-right: 0;
Target
Third item
padding-right: 50px;
Target
Third item
padding-right: 7em;
Target
Third item
padding-right: 30%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#padding-top
Defines the space inside the element, on the top side.
defaultpadding-top: 0;
Removes any padding on the top.
First item
Target
Third item
padding-top: 50px;
Target
Third item
padding-top: 7em;
Target
Third item
padding-top: 30%;
Target
Third item
In collection: box-modelPermalinkShareMDN
#padding
Shorthand property for padding-top padding-right padding-bottom and padding-left.
defaultpadding: 0;
padding: 30px;
In collection: box-modelPermalinkShareMDN
#width
Defines the width of the element.
defaultwidth: auto;
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%;
#align-content
Defines how each line is aligned within a flexbox/grid container. It only applies if flex-
wrap: wrap is present, and if there are multiple lines of flexbox/grid items.
defaultalign-content: stretch;
Each line will only fill the space it needs. They will all move towards the start of the
flexbox/grid container's cross axis.
1
2
3
4
5
align-content: flex-end;
Each line will only fill the space it needs. They will all move towards the end of the
flexbox/grid container's cross axis.
1
2
3
4
5
align-content: center;
Each line will only fill the space it needs. They will all move towards the center of the
flexbox/grid container's cross axis.
1
2
3
4
5
align-content: space-between;
Each line will only fill the space it needs. The remaining space will appear between the lines.
1
2
3
4
5
align-content: space-around;
Each line will only fill the space it needs. The remaining space will be distributed
equally around the lines: before the first line, between the two, and after the last one.
1
2
3
4
5
In collection: flexboxPermalinkShareCan I useMDN
#align-items
Defines how flexbox items are aligned according to the cross axis, within a line of a flexbox
container.
align-items: flex-start;
The flexbox items are aligned at the start of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will be
aligned vertically at the top.
1
2
3
4
5
align-items: flex-end;
The flexbox items are aligned at the end of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will be
aligned vertically at the bottom.
1
2
3
4
5
align-items: center;
The flexbox items are aligned at the center of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will
be centered vertically.
1
2
3
4
5
align-items: baseline;
The flexbox items are aligned at the baseline of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will align themselves in
order to have the baseline of their text align along a horizontal line.
1
2
3
4
5
align-items: stretch;
The flexbox items will stretch across the whole cross axis.
By default, the cross axis is vertical. This means the flexbox items will fill up the whole
vertical space.
1
2
3
4
5
In collection: flexboxPermalinkShareCan I useMDN
#align-self
Works like align-items, but applies only to a single flexbox item, instead of all of them.
defaultalign-self: auto;
If the container has align-items: center and the target has align-self: flex-start, only
the target will be at the start of the cross axis.
By default, this means it will be aligned vertically at the top.
1
Target
3
4
5
align-self: flex-end;
If the container has align-items: center and the target has align-self: flex-end, only
the target will be at the end of the cross axis.
By default, this means it will be aligned vertically at the bottom.
1
Target
3
4
5
align-self: center;
If the container has align-items: flex-start and the target has align-self: center, only
the target will be at the center of the cross axis.
By default, this means it will be vertically centered.
1
Target
3
4
5
align-self: baseline;
If the container has align-items: center and the target has align-self: baseline, only
the target will be at the baseline of the cross axis.
By default, this means it will be aligned along the basline of the text.
1
Target
3
4
5
align-self: stretch;
If the container has align-items: center and the target has align-self: stretch, only the
target will stretch along the whole cross axis.
1
Target
3
4
5
In collection: flexboxPermalinkShareCan I useMDN
#flex-basis
Defines the initial size of a flexbox item.
defaultflex-basis: auto;
You can define pixel or (r)em values. The element will wrap its content to avoid any
overflow.
Flexbox item
In collection: flexboxPermalinkShareCan I useMDN
#flex-direction
Defines how flexbox items are ordered within a flexbox container.
defaultflex-direction: row;
The flexbox items are ordered the same way as the text direction, along the main axis.
1. One
2. Two
3. Three
4. Four
flex-direction: row-reverse;
The flexbox items are ordered the opposite way as the text direction, along the main axis.
1. One
2. Two
3. Three
4. Four
flex-direction: column;
The flexbox items are ordered the same way as the text direction, along the cross axis.
1. One
2. Two
3. Three
4. Four
flex-direction: column-reverse;
The flexbox items are ordered the opposite way as the text direction, along the cross axis.
1. One
2. Two
3. Three
4. Four
In collection: flexboxPermalinkShareCan I useMDN
#flex-flow
Shorthand property for flex-direction and flex-wrap.
In collection: flexboxPermalinkShareCan I useMDN
#flex-grow
Defines how much a flexbox item should grow if there's space available.
defaultflex-grow: 0;
The element will not grow if there's space available. It will only use the space it needs.
Target
Item
Item
flex-grow: 1;
The element will grow by a factor of 1. It will fill up the remaining space if no other flexbox
item has a flex-grow value.
Target
Item
Item
flex-grow: 2;
Because the flex-grow value is relative, its behaviour depends on the value of the flexbox
item siblings.
In this example, the remaining space is divided in 3:
1 third goes to the green item
2 thirds go to the pink item
Nothing goes to the yellow item, who retains its initial width
Item
1
Item
2
Item
0
In collection: flexboxPermalinkShareCan I useMDN
#flex-shrink
Defines how much a flexbox item should shrink if there's not enough space available.
defaultflex-shrink: 1;
If there's not enough space available in the container's main axis, the element will shrink by
a factor of 1, and will wrap its content.
This is the flex-shrink target
Foo bar
Lorem ipsum
flex-shrink: 0;
The element will not shrink: it will retain the width it needs, and not wrap its content. Its
siblings will shrink to give space to the target element.
Because the target element will not wrap its content, there is a chance for the flexbox
container's content to overflow.
This is the flex-shrink target
Foo bar
Lorem ipsum
flex-shrink: 2;
Because the flex-shrink value is relative, its behaviour depends on the value of the flexbox
item siblings.
In this example, the green item wants to fill 100% of the width. The space it needs is taken
from its two siblings, and is divided in 4:
3 quarters are taken from the red item
1 quarter is taken from the yellow item
Width
100%
Shrink
3
Shrink
1
In collection: flexboxPermalinkShareCan I useMDN
#flex-wrap
Defines if flexbox items appear on a single line or on multiple lines within a flexbox
container.
defaultflex-wrap: nowrap;
The flexbox items will remain on a single line, no matter what, and will eventually overflow
if needed.
1. One
2. Two
3. Three
4. Four
5. Five
6. Six
flex-wrap: wrap;
The flexbox items will be distributed among multiple lines if needed. Any additional line
will appear before the previous one.
1. One
2. Two
3. Three
4. Four
5. Five
6. Six
In collection: flexboxPermalinkShareCan I useMDN
#justify-content
Defines how flexbox/grid items are aligned according to the main axis, within a flexbox/grid
container.
defaultjustify-content: flex-start;
The flexbox/grid items are pushed towards the start of the container's main axis.
1. One
2. Two
3. Three
justify-content: flex-end;
The flexbox/grid items are pushed towards the end of the container's main axis.
1. One
2. Two
3. Three
justify-content: center;
The flexbox/grid items are centered along the container's main axis.
1. One
2. Two
3. Three
justify-content: space-between;
The remaining space is distributed around the flexbox/grid items: this adds space before the
first item and after the last one.
1. One
2. Two
3. Three
In collection: flexboxPermalinkShareCan I useMDN
#order
Defines the order of a flexbox item.
defaultorder: 0;
The order of the flexbox items is the one defined in the HTML code.
One
order: 0
Two
order: 0
Target
order: 0
Four
order: 0
order: 1;
The order is relative to the flexbox item's siblings. The final order is defined when all
individual flexbox item order values are taken into account.
One
order: 0
Two
order: 0
Target
order: 1
Four
order: 0
order: -1;