CSS Properties and Values
Sources
- This reference sheet is based on material from w3schools.com and Liz Castro's HTML book (5th edition: Appendix B).
- The properties follow CSS recommendation 2 from W3C (WWW Consortium).
Selectors
This reference covers all the CSS2 properties and values you can implement in your styles. Of course, you will also need to specify which elements in your web documents are affected by using selectors in your external style sheets (styles defined in separate files and linked to one or more of your HTML pages) and internal style sheets (styles defined within HEAD section of an HTML page). Selectors are not required for inline styles since these style definitions are embedded within the element tags they affect.
Here's the style definition syntax: selector { property: value(s); }
where property:value(s); can be repeated any number of times within a style definition and multiple values are separated by spaces (but a space ater the colon is optional).
And here are a few pointers regarding selectors (the rest of this document covers properties and values):
1. The selector is often set to an HTML element tag. For example, to render all level 1 headers in red:
h1 { color: red; }
2. Mutiple HTML element tags can be separated by commas, e.g:
h1,h2,h3 { color: red; }
3. To specify particular instances of an HTML element, a class attribute can be included within each tag definition, as shown int he following example:
<h1 class="major"> a class of important headings </h1>
...and then used in a single style definition like so:
h1.major { color: red; } /* class uses period */
4. To specify a particular instance of an element, an id attribute can be used in the tag definition:
<h1 id="special"> identifying a specific heading </h1>
...and then used in the style definition like so:
h1#special { color: blue; } /* id uses number sign */
5. To specify a style that affects a class or id for any type of element, just leave out the tag portion:
.major { color: red; } /* class uses period */
#special { color: blue; } /* id uses number sign */
6. Two special HTML tags are often used in conjuction with styles (and have no other purpose except in programming):
<span id="reference"> encloses a portion of a line </span>
<div id="notes">
encloses several lines
encloses several lines
encloses several lines
</div>
...now the selector can refer to these HTML tags with the specified class or id, like so:
span#reference { color: green; }
div#notes { color: olive; }
Notation
- Each CSS Property is shown as a row in the table below, along with a brief description, a list of possible values, and an indication of whether the property is inherited from its parent.
- A value shown in bold is the default for that particular property (i.e. if the property is not set)
- A value shown in italics is a placeholder and must be replaced with an appropriate literal value
- A value name followed by a percent sign (%) must be specified as a number from 0..100, followed by a % at the end (e.g. 50%)
- UNITS: A value name followed by a "pos" or appearing as length must be specified as a measurement with one of the following unit specifiers:
- relative units: px (pixels) and em (text-height or "em-size"), for example 120px and 2em... these are relative to the screen resolution and current text height respectively
- absolute units: in (inches), cm (centimetres), mm (millimetres), pt (points = 1/72 inch), and pc (pica = 1/6 in = 12 pts). Here are examples that represesent the same distance expressed in the various units: 0.5in, 1.27cm, 12.7mm, 36pt, 3pc
- Refer to the w3schools CSS Units page for more information
- COLOURS: In CSS, colours can be specified in one of four ways:
- by name - like HTML, except there are many more named colours available with CSS
- by Hexadecimal RGB values: #rrggbb where r,g,b = 0..9,A..F as in HTML
for example: #22FF44
- by Decimal RGB values with the rgb function: rgb(n,n,n) where n = 0..255
for example: rgb(34,255,68)
- by Percentage RGB values: rgb(p%,p%,p%) where p = 0..100
for example: rgb(13%,100%,26%)
- For colour samples refer to the w3schools CSS Colour Reference page or to our own JavaScript-generated 5,000 Colour Samples
Sections
- Background - background colour and/or image for elements
- Border - all aspects of a border on every sides of an element
- Control - element position, float, display and visibility (and cursor types)
- Dimension - element height, width, min/max range, and text line height
- Font - font characteristics incl: family, size, style, weight (see Text properties also)
- Generated Content - to add content to a page using pseudo-elements
- List and Marker - list characteristics: style, position, type , and offset
- Margin - spacing outside each of the four sides of an element
- Outlines - element outline colour, size, and width
- Padding - spacing inside each of the four sides of an element
- Positioning - element placement in relation to parent or page (plus depth index)
- Table - fine border, caption, cell, and layout settings
- Text - color, line/word/char spacing, alignment, decoraton, indent, etc. (see Font also)
- Pseudo-classes - elements can be formatted based on their state or dynamics
- Pseudo-elements - isolates a part of an element to be formatted separately
| Property |
Description |
Values |
Inherit |
| background |
A shorthand property for setting all background properties in one declaration |
background-color
background-image
background-repeat background-attachment background-position |
No |
| background-attachment |
Sets whether a background image is fixed or scrolls with
the rest of the page |
scroll
fixed
inherited
|
No |
| background-color |
Sets the background color of an element |
color-rgb
color-hex
color-name
transparent |
No |
| background-image |
Sets an image as the background |
url
none |
No |
| background-position |
Sets the starting position of a background image |
top left
top center
top right
center left
center center
center right |
bottom left
bottom center
bottom right
x% y%
xpos ypos |
No |
| background-repeat |
Sets if/how a background image will be repeated |
repeat
repeat-x
repeat-y
no-repeat |
No |
| Property |
Description |
Values |
Inherit |
| border |
A shorthand property for setting all of the properties for the four borders in one declaration |
border-width
border-style
border-color |
No |
| border-bottom |
A shorthand property for setting all of the properties for the bottom
border in one declaration |
border-bottom-width
border-style
border-color |
No |
| border-bottom-color |
Sets the color of the bottom border |
border-color |
No |
| border-bottom-style |
Sets the style of the bottom border |
border-style |
No |
| border-bottom-width |
Sets the width of the bottom border |
thin
medium
thick
length |
No |
| border-color |
Sets the color of the four borders, can have from one to four colors |
color |
No |
| border-left |
A shorthand property for setting all of the properties for the left
border in one declaration |
border-left-width
border-style
border-color |
No |
| border-left-color |
Sets the color of the left border |
border-color |
No |
| border-left-style |
Sets the style of the left border |
border-style |
No |
| border-left-width |
Sets the width of the left border |
thin
medium
thick
length |
No |
| border-right |
A shorthand property for setting all of the properties for the right
border in one declaration |
border-right-width
border-style
border-color |
No |
| border-right-color |
Sets the color of the right border |
border-color |
No |
| border-right-style |
Sets the style of the right border |
border-style |
No |
| border-right-width |
Sets the width of the right border |
thin
medium
thick
length |
No |
| border-style |
Sets the style of the four borders, can have from one to four styles |
none
hidden
dotted
dashed
solid |
double
groove
ridge
inset
outset |
No |
| border-top |
A shorthand property for setting all of the properties for the top border in one declaration |
border-top-width
border-style
border-color |
No |
| border-top-color |
Sets the color of the top border |
border-color |
No |
| border-top-style |
Sets the style of the top border |
border-style |
No |
| border-top-width |
Sets the width of the top border |
thin
medium
thick
length |
No |
| border-width |
A shorthand property for setting the width of the
four borders in one declaration, can have from one to four values |
thin
medium
thick
length |
No |
| Property |
Description |
Values |
Inherit |
| clear |
Sets the sides of an element where other floating elements are not allowed |
left
right
both
none |
No |
| cursor |
Specifies the type of cursor to be displayed |
url
auto
crosshair
default
pointer
move
e-resize
ne-resize
nw-resize |
n-resize
se-resize
sw-resize
s-resize
w-resize
text
wait
help |
Yes |
| display |
Sets how/if an element is displayed |
none
inline
block
list-item
run-in
compact
marker
table |
inline-table
table-row-group
table-header-group
table-footer-group
table-row
table-column-group
table-column
table-cell
table-caption |
No |
| float |
Sets where an image or a text will appear in another element |
left
right
none |
No |
| position |
Places an element in a static, relative, absolute or fixed position |
static
relative
absolute
fixed |
No |
| visibility |
Sets if an element should be visible or invisible |
visible
hidden
collapse
inherit
|
No |
| Property |
Description |
Values |
Inherit |
| height |
Sets the height of an element |
auto
length
%
inherit
|
No |
| line-height |
Sets the distance between lines |
normal
number
length
%
inherit |
Yes |
| max-height |
Sets the maximum height of an element |
none
length
%
inherit |
No |
| max-width |
Sets the maximum width of an element |
none
length
%
inherit |
No |
| min-height |
Sets the minimum height of an element |
length
%
inherit |
No |
| min-width |
Sets the minimum width of an element |
length
%
inherit |
No |
| width |
Sets the width of an element |
auto
%
length
inherit |
No |
| Property |
Description |
Values |
Inherit |
font
|
A shorthand property for setting all of the properties for
a font in one declaration |
font-style
font-variant
font-weight
font-size
line-height
font-family
|
caption
icon
menu
message-box
small-caption
status-bar |
Yes |
font-family
|
A prioritized list of font family names and/or generic
family names for an element |
family-name
generic-family |
Yes |
font-size
|
Sets the size of a font |
xx-small
x-small
small
medium
large
x-large |
xx-large
smaller
larger
length
% |
Yes |
| font-size-adjust
|
Specifies an aspect value for an element that will preserve
the x-height of the first-choice font |
none
number |
|
| font-stretch
|
Condenses or expands the current font-family |
normal
wider
narrower
ultra-condensed
extra-condensed
condensed |
semi-condensed
semi-expanded
expanded
extra-expanded
ultra-expanded |
|
font-style
|
Sets the style of the font |
normal
italic
oblique
inherit
|
Yes |
font-variant
|
Displays text in a small-caps font or a normal font |
normal
small-caps |
Yes |
font-weight
|
Sets the weight of a font |
normal
bold
bolder
lighter
100
200
300 |
400
500
600
700
800
900 |
Yes |
| Property |
Description |
Values |
Inherit |
| content
|
Generates content in a document. Used with the :before and :after
pseudo-elements |
string
url
counter(name)
counter(name, list-style-type)
counters(name, string)
counters(name, string, list-style-type)
attr(X)
open-quote
close-quote
no-open-quote
no-close-quote |
|
| counter-increment
|
Sets how much the counter increments on each occurrence of a
selector |
none
identifier number |
|
| counter-reset
|
Sets the value the counter is set to on each occurrence of
a selector |
none
identifier number |
|
| quotes
|
Sets the type of quotation marks |
none
string string |
|
| Property |
Description |
Values |
Inherit |
| list-style |
A shorthand property for setting all of the properties for
a list in one declaration |
list-style-type
list-style-position
list-style-image |
Yes |
| list-style-image |
Sets an image as the list-item marker |
none
url |
Yes |
| list-style-position |
Sets where the list-item marker is placed in the list |
inside
outside |
Yes |
| list-style-type |
Sets the type of the list-item marker |
none
disc
circle
square
decimal
decimal-leading-zero
lower-roman
upper-roman
lower-alpha
upper-alpha
lower-greek
lower-latin |
upper-latin
hebrew
armenian
georgian
cjk-ideographic
hiragana
katakana
hiragana-iroha
katakana-iroha |
Yes |
| marker-offset |
|
auto
length |
|
| Property |
Description |
Values |
Inherit |
| margin
|
A shorthand property for setting the margin properties in
one declaration |
margin-top
margin-right
margin-bottom
margin-left |
No |
|
margin-bottom
|
Sets the bottom margin of an element |
auto
length
%
inherit |
No |
|
margin-left
|
Sets the left margin of an element |
auto
length
%
inherit |
No |
|
margin-right
|
Sets the right margin of an element |
auto
length
%
inherit |
No |
| margin-top
|
Sets the top margin of an element |
auto
length
%
inherit |
No |
| Property |
Description |
Values |
Inherit |
| outline
|
A shorthand property for setting all the outline properties in
one declaration |
outline-color
outline-style
outline-width |
|
|
outline-color
|
Sets the color of the outline around an element |
color
invert |
|
|
outline-style
|
Sets the style of the outline around an element |
none
dotted
dashed
solid
double |
groove
ridge
inset
outset |
|
|
outline-width
|
Sets the width of the outline around an element |
thin
medium
thick
length |
|
| Property |
Description |
Values |
Inherit |
| padding |
A shorthand property for setting all of the padding properties in
one declaration |
padding-top
padding-right
padding-bottom
padding-left
inherit |
No |
|
padding-bottom
|
Sets the bottom padding of an element |
length
%
inherit |
No |
|
padding-left
|
Sets the left padding of an element |
length
%
inherit |
No |
|
padding-right
|
Sets the right padding of an element |
length
%
inherit |
No |
| padding-top |
Sets the top padding of an element |
length
%
inherit |
No |
| Property |
Description |
Values |
Inherit |
| bottom |
Sets how far the bottom edge of an element is above/below the
bottom edge of the parent element |
auto
%
length
inherit |
No |
| clip |
Sets the shape of an element. The element is clipped into
this shape, and displayed |
shape
auto
|
|
| left |
Sets how far the left edge of an element is to the right/left of
the left edge of the parent element |
auto
%
length
inherit |
No |
overflow
|
Sets what happens if the content of an element overflow its
area |
visible
hidden
scroll
auto |
No |
| position |
Places an element in a static, relative, absolute or fixed position |
static
relative
absolute
fixed
inherit |
No |
| right |
Sets how far the right edge of an element is to the left/right of
the right edge of the parent element |
auto
%
length
inherit |
No |
| top |
Sets how far the top edge of an element is above/below the
top edge of the parent element |
auto
%
length
inherit |
No |
| vertical-align |
Sets the vertical alignment of an element |
baseline
sub
super
top
text-top
middle |
bottom
text-bottom
length
%
inherit |
No |
| z-index |
Sets the stack order of an element |
auto
number
inherit |
No |
| Property |
Description |
Values |
Inherit |
| border-collapse |
Sets the border model of a table |
collapse
separate |
|
| border-spacing |
Sets the distance between the borders of adjacent cells
(only for the "separated borders" model) |
length length |
Yes |
| caption-side
|
Sets the position of the caption according to the table |
top
bottom
left
right |
|
| empty-cells
|
Sets whether cells with no visible content should have borders or not (only
for the "separated borders" model) |
show
hide |
|
| table-layout
|
Sets the algorithm used to lay out the table |
auto
fixed |
|
| Property |
Description |
Values |
Inherit |
| color |
Sets the color of text (or any element ) |
color |
Yes |
| direction |
Sets the text direction as left-to-right or right-to-left |
ltr
rtl |
|
| letter-spacing |
Increase or decrease the space between characters |
normal
length |
Yes |
| line-height |
Sets the distance between lines |
normal
number
length
%
inherit |
Yes |
| text-align |
Aligns the text in an element |
left
right
center
justify |
Yes |
| text-decoration |
Adds decoration to text |
none
underline
overline |
line-through
blink
inherit |
No |
| text-indent |
Indents the first line of text in an element |
length
% |
Yes |
| text-shadow |
|
none
color
length |
|
| text-transform |
Controls the letters in an element |
none
capitalize
uppercase
lowercase |
Yes |
| unicode-bidi |
Text in some languages flows from right-to-left, while many other languages flow from left-to-right. The 'unicode-bidi' and 'direction' properties specify how document content maps to the Unicode algorithm to handle both directions on a single wab page. |
normal
embed
bidi-override |
|
| white-space |
Sets how white space inside an element is handled |
normal
pre
nowrap |
Yes |
| word-spacing |
Increase or decrease the space between words |
normal
length |
Yes |
| Pseudo-class |
Purpose |
| :active |
Adds special style to an activated element |
| :focus |
Adds special style to an element while the element has
focus |
| :hover |
Adds special style to an element when you mouse over it |
| :link |
Adds special style to an unvisited link |
| :visited |
Adds special style to a visited link |
| :first-child |
Adds special style to an element that is the first child of some other element |
| :lang |
Allows the author to specify a language to use in a specified element |
| Pseudo-element |
Purpose |
| :first-letter |
Adds special style to the first letter of a text |
| :first-line |
Adds special style to the first line of a text |
| :before |
Inserts some content before an element |
| :after |
Inserts some content after an element |
Updated: 4 February 2006
|
| |
|