This page has a list of the common words in the CSS language, with examples of code and results.
To make it most useful, follow the steps below (this is how we learn programming as well!)
Contents
The box model: Think of each html tag as making a box:
p
The <p> tag opens the box, and the </p> tag closes the box.
h1
The <h1> tag opens the box, and the </h1> tag closes the box.
img
The <img /> tag opens and closes the box.
li
li
The <ul> tag opens the outer box.
An <li> tag opens an inner box, and an </li> tag closes an inner box.
Then the </ul> tag closes the outer box.
Every box is an html tag. Every box has margin and padding:
Styling the box
This means we can give "style" to the different parts of the box.
His Holiness Dalai Lama
This has three "boxes" (tags):
div, img, and p.
We give the styles to the "boxes" like this:
<div style="margin: auto;
margin-top: 20px;
width: 250px;
border: 8px solid #cc0000;
background-color: #ff9933;
text-align: center;
padding: 30px;
padding-bottom: 0;">
<img src="images/dalai_lama-sm.jpg"
style="padding: 10px;
background-color: #ffff00;
border: 2px solid #cc0000;" />
<p style="font-size: 90%; color: green;">
His Holiness Dalai Lama
</p>
</div>
More about the box model:
Read on to learn how to use these styles!
(I promise they won't always look so confusing :)
We can put the CSS code in three places:
Read here for more information.
Two new html tags were invented just for using with CSS styles. These are <div> and <span>
The <div> is for giving a style to a
block.
This would have other block tags inside it, such as paragraph, image, list, etc.
Simple explanation of div:
http://webdesign.about.com/od/htmltags/p/aadivtag.htm
(See the HTML tutorial page, section on the "three kinds of tags", for more about block tags.)
The <span> tag is for giving a style to something that is
inline, such as some words in a line of text.
Simple explanation of span:
http://webdesign.about.com/od/htmltags/p/aaspantag.htm
(See the HTML tutorial page, section on the "three kinds of tags", for more about inline tags.)
Examples: Use your browser's search to find examples of using <div and <span on this page.
|
"property name" Outlined properties
are the most used —
|
"possible values" Values in orange color are the values allowed for a property.
Values in angle brackets, such as
|
"example code"
To keep things clear, i am only showing one property
for each example.
|
"example Here will be what should show in the browser. |
"default"
The value that the web browser will use if you don't specify anything
for this property.
|
"Use in" The elements that would use this property. |
"Percentages
If the style uses percent measurement,
what it is a percent of.
|
Here are the main codes that we use in CSS. Try them in your web page.
| properties for text: Fonts | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| font-family |
any <family-name>,
such as
verdana
or
"times roman"
or <generic-family> [ serif, sans-serif, cursive, fantasy, monospace] |
<p style="font-family: Times, serif;"> Here is a paragraph in Times font. </p> <p style="font-family: 'Times roman', serif;"> If you use a font name that has more than one word, use quotes. </p> |
Here is a paragraph in Times font. If you use a font name that has more than one word, use quotes. |
The font set in the user's browser. | Any element that holds text. | n/a |
| font-style | [ normal, italic ] |
<p> We will learn some <span style="font-style: italic;">very useful</span> css coding. </p> |
We will learn some very useful css coding. |
The font size set in the user's browser. | Any element that holds text. | n/a |
| font-weight |
[
normal,
bold,
100,
200,
300,
400,
500,
600,
700,
800,
900
]
(The numbers are supposed to give shades of light to dark, but not all browsers do this yet. So we usually just use the bold property.) |
<p> We will learn some <span style="font-weight: bold">very useful</span> css coding. </p> |
We will learn some very useful css coding. |
normal | Any element that holds text. | n/a |
| font-size |
[ <absolute size>, <relative size>, <length>, <percentage> ]
Examples:
|
<p style="font-size: 80%;"> We usually use some kind of relative size for our font size. Then our reader can make the size bigger and smaller in the browser if they want to, to be more useful to their needs. </p> |
We usually use some kind of relative size for our font size. Then our reader can make the size bigger and smaller if they want, to be more useful to their needs. |
100% | Any element that holds text. | The original base size of the font. |
| properties for text: Color | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| color | <color>
(such as #000000 or #ffffcc) |
<p style="color: #669966;"> It is better to use color codes (like |
It is better to use color codes
(like |
... | Any element that holds text. (This property is like "font-color".) | n/a |
| properties for text: Spacing | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| line-height |
[
normal,
<number>,
<length>,
<percentage>
]
(Using a decimal number is most useful in all browsers.) |
(See the CSS faq page, section on class and id for how to use the "class" below.)
p.spacer {
line-height: 1.3;
}
p.more-spacer {
line-height: 1.9;
}
<p> The "normal" or default |
The default
The Just like on paper, having some spacing between the lines makes it easier to read. This may be even more important on the web, since reading on the screen is harder on the eyes than reading from paper. |
100% to 120%, depending on the browser | Any element that holds text. | The original base size of the font. |
| word-spacing |
[
normal,
<length>
]
(Using the relative measurement em is most useful in all browsers.) |
<h3> Here is a normal h3. </h3> <h3 style="word-spacing: .5em;"> Here is h3 with some extra space between the words. </h3> |
Here is a normal h3.Here is h3 with some extra space between the words. |
... | Any element that holds text. | |
| word-wrap
word-wrap is CSS3 - so it's not yet in SitePoint or W3Schools references.
This would be useful to use if the browser isn't wrapping long lines of Tibetan. The latest Firefox seems to wrap long words by default -- but other or older browsers may not. |
[ normal, break-word ] |
<p> Here-is-a-long-much-too-long-word-that-goes-on-and-on-with-no-word-wrap </p> <p style="word-wrap: break-word;"> Here-is-a-long-much-too-long-word-that-goes-on-and-on-but-wraps-with-word-wrap </p> |
Here-is-a-long-much-too-long-word-that-goes-on-and-on-with-no-word-wrap Here-is-a-long-much-too-long-word-that-goes-on-and-on-but-wraps-with-word-wrap |
... | Any element that holds text. | |
| letter-spacing |
[
normal,
<length>
]
(Using the relative measurement em is most useful in all browsers.) |
<p> Here is a normal paragraph. </p> <p style="letter-spacing: .2em;"> Here is a paragraph with some extra space between the letters. </p> |
Here is a normal paragraph. Here is a paragraph with some extra space between the letters. |
... | Any element that holds text. | The original base size of the font. |
| white-space
Good explanation at http://www.impressivewebs.com/css-white-space/ |
[ normal, pre, nowrap ] |
(See the CSS faq page, section on class and id for how to use the "class" below.)
p.one {
white-space: pre;
}
p.two {
white-space: nowrap;
}
<p>
The <code>pre</code> value is
like the <pre> tag in html.
It makes the browser display all
white space.
</p>
<p class="one">
However, the html
<pre> tag displays in a
monospace font, and the
<code>pre</code> value does not.
</p>
<p class="two">
The <code>nowrap</code> value
ignores white space
and line breaks, and will not wrap the lines.
</p>
|
The
However, the html
<pre> tag displays in a
monospace font, and the
The |
normal | Any element that holds text. | n/a |
| text-indent | [ <length>, <percentage> ] |
p {
text-indent: 3em;
}
<p> This will make some indentation to appear in the first line of text. ... </p> |
This will make some indentation to appear in the first line of text. Values can be specified in any unit of length, or as a percentage of the line length. |
none | Any element that holds text. | The original base size of the font. |
| properties for text: Alignment | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| text-align | [ left, right, center, justify ] |
p {
text-align: center;
}
<p> This property is used only to align things <i>inside</i> a block (paragraph, header, table cell, etc.). We will learn other ways to align the block itself. </p> |
This property is used only to align things inside a block tag (paragraph, header, table cell, etc.). We will learn other ways to align the block itself. (See the HTML tutorial page, section on the "three kinds of tags", for more about block tags.) |
left | Any element that holds text. It will center images inside the element also. | n/a |
| vertical-align | [ baseline, bottom, middle, sub, super, text-bottom, text-top, top, <percentage> ] |
p {
vertical-align: bottom;
}
<p> This property is used only for content of block tags. </p> |
This property is used only for content of block tags. |
... | Any block element. | n/a |
| properties for text: Appearance | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| text-decoration | [ none, underline, overline, line-through ] |
a {
text-decoration: none;
}
span.delete {
text-decoration: line-through;
}
<p> The <code>text-decoration</code> property is usually used for <a href="http://www.sitepoint.com/">links</a>, <span class="delete">but can also be used for other parts of text</span>. </p> |
The |
underline for <a> tags; none for all others. | Any element that holds text. | n/a |
| text-transform | [ capitalize, uppercase, lowercase, none ] |
h1 {
text-transform: uppercase;
}
h2 {
text-transform: capitalize;
}
<h1> Using text-transform </h1> <h2> This makes it easy to change our mind about CAPITALS </h2> |
Using text-transformThis makes it easy to change our mind about CAPITALS |
none | Any element that holds text. | n/a |
|
– What is a "box"?
Picture each html tag as making a box. There can be boxes inside of boxes. A "block-level tag" means a tag that really displays as a separate box (block), like <p>, <div>, <image>, <td> An "inline tag" is a box that displays in line with other text, images, or elements, like <a> and <span>. Below are the properties we can use in boxes. |
||||||
|---|---|---|---|---|---|---|
| properties for boxes: Margin and Padding | ||||||
| property name | possible values | example code | example display | default | use in | percentages refer to |
| margin |
[ <length>, <percentage>,
auto ]
(sequence: t r b l)
The (Using pixel measurements for margin is most useful in all browsers.) |
p {
margin: 8px 4px 8px 4px;
}
<p> It is nice to have some space around paragraphs, images, and so on so the other things on the web page don't crowd up against them. </p> |
It is nice to have some space around paragraphs, images, and so on so the other things on the web page don't crowd up against them. |
... | All elements, except those with table display types. (Except not table and inline-table) (confusing? yes! just try things.) | the width of the containing block. |
| margin-top | [ <length>, <percentage>, auto ] |
p {
margin-left: 30px;
}
<p> It is often useful to make a margin just for one or two sides of the "box". </p> |
It is often useful to make a margin just for one or two sides of the "box". |
|||
| margin-right | [ <length>, <percentage>, auto ] | |||||
| margin-bottom | [ <length>, <percentage>, auto ] | |||||
| margin-left | [ <length>, <percentage>, auto ] | |||||
| padding |
[ <length>, <percentage>,
auto ]
(sequence: t r b l)
The (Using pixel measurements for padding is most useful in all browsers.) |
p {
padding: 8px 4px 8px 4px;
}
<p> Sometimes we want some space between our text or image, and the edge of the box it is in. </p> |
Sometimes we want some space between our text or image, and the edge of the box it is in. |
... | All elements, except those with table display types. (Except not table and inline-table) (confusing? yes! just try things.) | the width of the containing block. |
| padding-top | [<length>, <percentage>] |
p {
padding-left: 30px;
}
<p> It is often useful to make a padding just for one or two sides of the "box". </p> |
It is often useful to make a padding just for one or two sides of the "box". |
|||
| padding-right | [<length>, <percentage>] | |||||
| padding-bottom | [<length>, <percentage>] | |||||
| padding-left | [<length>, <percentage>] | |||||
| properties for boxes: Border | ||||||
|---|---|---|---|---|---|---|
|
The border appears outside the padding, and inside the margin. |
||||||
| property name | possible values | example code | example display | default | use in | percentages refer to |
| border |
<border-width>
<border-style>
<color>
This shows the short way to set all three in one declaration. See below for the individual properties. |
p {
border: 1px solid #cc0000;
padding: 4px 8px 4px 8px;
}
<p> We can do lots of nice things with borders. </p> |
We can do lots of nice things with borders. |
... | All elements | n/a |
| border-width | Usually as px |
table {
border: 4px groove #cc6633;
}
<table> <tr valign="top"> <td> <img src="images/bullit1.gif" /> </td> <td> With css we can easily make a border around a table, but no borders for the cells. </td> </tr> </table> |
|
|||
| border-style | [ solid, dashed, dotted, double, groove, ridge, inset, outset ] | |||||
| border-color |
<color>
(such as #000000 or #cc0000) |
|||||
| border-top border-right border-bottom border-left |
<border-width>
<border-style>
<color>
Again, we use the short way to set all three properties in one declaration. See above for the individual properties. |
p {
border-left: 4px double #cc0000;
padding: 4px 8px 4px 8px;
}
<p> We can do lots of nice things with borders. </p> |
We can do lots of nice things with borders. |
... | ||
| properties for boxes: Background | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| background-color | <color>
(such as #000000 or #ffffcc) |
(See the CSS faq page, section on class and id for how to use the "class" below.)
div.special {
color: #cccccc;
background-color: #669966;
padding: 1ex 1em 1ex 1em;
}
<div class="special"> With some padding so the words aren't so close to the edges! </p> |
With some padding so the words aren't so close to the edges! |
... | All elements | n/a |
| background-image |
url(<path to file>)
The image file can be in the same folder or another folder. Or — it can even be on another website! url(http://www.webwalker.to/images/sand.jpg); |
div.special {
background-image: url(images/grid.gif);
padding: 2pt 4pt 2pt 4pt;
}
<div class="special">
<img src="images/bullit1.gif"
align="left" alt="image here" />
A background image is useful for
a repeating pattern. ...
</p>
|
|
... | All elements | n/a |
|
background-repeat |
[
repeat-x ,
repeat-y ,
no-repeat
]
|
... | All elements | n/a | n/a | |
|
background-attachment |
[
scroll,
fixed
]
|
... | All elements | n/a | n/a | |
|
background-position |
background-position has many options!
Here are some to try out:
|
... | All elements | n/a | n/a | |
| properties for boxes: Size and Display | ||||||
|---|---|---|---|---|---|---|
| property name | possible values | example code | example display | default | use in | percentages refer to |
| width | [ <length>, <percentage>, auto ] |
(See the CSS faq page, section on class and id for how to use the "class" below.)
p.one {
width: 70%;
}
p.two {
width: 10em;
}
p.three {
width: 150px;
}
<p class="one"> This paragraph should be 70% of the containing block. ... </p> <p class="two"> An "em" is the width of a letter "m" in that font". This paragraph should be 10 "ems" wide. ... </p> <p class="three"> This paragraph should be 150 pixels wide. ... </p> |
This paragraph should be 70% of the "containing block" (the box it is inside). The paragraph width should change if the browser window (and block) get narrow or wide. An "em" is the width of a letter "m" in that font". This paragraph should be 10 "ems" wide. The width should resize if you make the browser font size bigger or smaller. This paragraph should be 150 pixels wide. The paragraph width will depend on your screen resolution (how big your screen pixels are). |
... | All elements except inline elements and table rows. | width of the containing block. |
| height |
[ <length>, <percentage>,
auto ]
We very rarely use "height". It is better to let the box stretch to its height depending on what is inside it. |
(See the CSS faq page, section on class and id for how to use the "class" below.)
p.one {
height: 20%;
}
p.two {
height: 8ex;
}
p.three {
height: 100px;
}
<p class="one"> The height of this paragraph should be 20% of the height of the containing block. ... </p> <p class="two"> An "ex" is the height of a letter "x" in that font. This paragraph should be 8 "ex" high. ... </p> <p class="three"> This paragraph should be 100 pixels high. ... </p> |
Note: I put borders around each paragraph so you can see the paragraph height. ('height' does not actually make borders!) The height of this paragraph should be 20% of the height of the containing block. The paragraph height should change if the block gets shorter or taller. An "ex" is the height of a letter "x" in that font. This paragraph should be 8 "ex" high. The height should resize if you make the browser font size bigger or smaller. This paragraph should be 100 pixels high. The paragraph height will depend on your screen resolution (how big your screen pixels are). |
... | All elements except inline elements and table columns (cells). | height of the containing block. |
| clear |
[
none,
left,
right,
both
]
This property says which sides of a box may not be next to an earlier floating box. |
(See the CSS faq page, section on class and id for how to use the "class" below.)
p.under-image {
clear: both;
}
<img src="images/dalai_lama.jpg" alt="The Dalai Lama" /> <p class="under-image"> The image is set to "float: right". Normally, the paragraph text will float to the side of the image. So we use "clear" to make it go at the bottom. </p> |
The image is set to "float: right". Normally, the paragraph text will float to the side of the image. So we use "clear" to make it go at the bottom. |
... | Block-level elements | n/a |
| display | [ block, inline, list-item, none ] |
Remember that all boxes (html tags) are either block or inline.
a {
display: block;
border-bottom: 1px solid #cccccc;
background-color: #ffccff;
}
<a href="how_to_learn_css.html">How to learn css</a> <a href="css_tutorial.html">CSS Tutorial</a> <a href="how_to_fix_css_problems.html">How to fix css problems</a> <a href="4-css_faq.html">CSS FAQ</a> |
CSS Tutorial How to fix problems How to learn html HTML FAQ | ... | All elements. | n/a |
| properties for List | ||||||
|---|---|---|---|---|---|---|
| selector name | possible values | example code | example display | default | use in | percentages refer to |
| list-style-type | [ disc, circle, square, decimal, lower-roman, upper-roman, lower-alpha, upper-alpha, none ] |
ul {
list-style-type: square;
}
<ul> <li> something </li> <li> another thing </li> </ul> |
|
disc | li element, or any element with display: list-item | n/a |
| list-style-image | [ url(), none ] |
ul {
list-style-image: url(bullit1.gif);
}
<ul> <li> something </li> <li> another thing </li> </ul> |
|
none | li element, or any element with display: list-item | n/a |
| More information |
|---|
|
|
This page has only the most common properties and their values. There are more! |
|
| This is too hard!! |
|---|
|
"I don't understand about 'values' and 'properties'."
|
| copyright / license |
top ↑ |
|---|---|
|
Q: Can i copy this file? Can i give to other people? Answer: Sure, you can give it to anyone, according to the terms of the license below. It is copyright © 2004 James Walker. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included here. If not found, find it at www.fsf.org - the Free Software Foundation. |
|
| translation |
top ↑ |
|---|---|
|
It would be very useful to have translations of this document in any language. Most preferred would be Tibetan and Chinese. Please contact me if you can do a translation for us. |
|
| contact |
top ↑ |
|---|---|
|
Was this helpful? Is it clear, or confusing? I would be happy to hear anything about how to make this better. You can contact me at the email address i have given you, or at http://www.webwalker.to/contact.php |
|
All content not copyright by anyone else is
copyright © 2003–2012 James Walker.
License for use is the GNU Free Documentation License.
Find it:
here in the
License directory
or
at the Free Software Foundation,
www.fsf.org