DEV Community

Cover image for Important CSS Properties You Must Know
Dhananjay Warade
Dhananjay Warade

Posted on

Important CSS Properties You Must Know

Color and Background Properties

Color
Changes the color of text.

H1 { 
    color: blue;
   }
Enter fullscreen mode Exit fullscreen mode

or

H2 { 
   color: #000080;
   }
Enter fullscreen mode Exit fullscreen mode

Background-Color
Sets the background color of an element.

BODY { 
background-color: white; 
} 
Enter fullscreen mode Exit fullscreen mode
H1 { 
background-color: #000080;
 } 

Enter fullscreen mode Exit fullscreen mode

Background-Image
Sets the background image of an element.

BODY { 
background-image: url(/images/foo.gif); 
} 
Enter fullscreen mode Exit fullscreen mode
P { 
background-image: url(http://www.htmlhelp.com/bg.png);
 } 

Enter fullscreen mode Exit fullscreen mode

Background-Repeat
Determines how a specified background image is repeated.
The repeat-x value will repeat the image horizontally while the
repeat-y value will repeat the image vertically.

BODY { 
background: white url(candybar.gif); 
background-repeat: repeat-x; 
} 
Enter fullscreen mode Exit fullscreen mode

Background-Attachment
Determines if a specified background image will scroll with the
content or be fixed with regard to the canvas.

BODY {
 background: white url(candybar.gif); 
background-attachment: fixed; 
} 

Enter fullscreen mode Exit fullscreen mode

Background
Used to combine all properties of background.

BODY { 
background: white url(http://www.htmlhelp.com/foo.gif); 
} 
BLOCKQUOTE {
 background: #7fffd4; 
} 
Enter fullscreen mode Exit fullscreen mode
P { 
background: url(../backgrounds/pawn.png) #f0f8ff fixed; 
} 
TABLE {
 background: red url(leaves.jpg) no-repeat bottom right; 
}
Enter fullscreen mode Exit fullscreen mode

Font Properties

Font-Family
Changes the font family of certain words, sentences,
paragraphs, etc.

P {
 font-family: "New Century Schoolbook", Times, serif; 
}
Enter fullscreen mode Exit fullscreen mode

Font-Style
Changes text: normal, oblique, and italics.

H1 {
 font-style: oblique; 
}

Enter fullscreen mode Exit fullscreen mode
P {
 font-style: normal; 
} 

Enter fullscreen mode Exit fullscreen mode

Font-Variant
Used to display font in normal or small-caps.

SPAN {
 font-variant: small-caps; 
} 
Enter fullscreen mode Exit fullscreen mode

Font-Weight
Used to specify the weight of the font.

H1 {
 font-weight: 800; 
}
Enter fullscreen mode Exit fullscreen mode

or

P {
 font-weight: normal; 
}
Enter fullscreen mode Exit fullscreen mode

Font-Size
Used to modify the size of the displayed font.

H1 {
 font-size: large; 
}
Enter fullscreen mode Exit fullscreen mode

or

P {
 font-size: 12pt; 
} 
Enter fullscreen mode Exit fullscreen mode
LI {
 font-size: 90%; 
} 

Enter fullscreen mode Exit fullscreen mode
STRONG {
 font-size: larger; 
} 

Enter fullscreen mode Exit fullscreen mode

Font
Used to combine all properties of fonts.

P {
 font: italic bold 12pt/14pt Times, serif; 
} 
Enter fullscreen mode Exit fullscreen mode

Text Properties

Word-Spacing
Defines an additional amount of space between words.

P EM {
 word-spacing: 0.4em; 
} 

Enter fullscreen mode Exit fullscreen mode
P.note {
 word-spacing: -0.2em; 
}

Enter fullscreen mode Exit fullscreen mode

Letter-Spacing
Defines an additional amount of space between characters.

H1 { 
letter-spacing: 0.1em; 
}

Enter fullscreen mode Exit fullscreen mode
P.note {
 letter-spacing: -0.1em; 
}

Enter fullscreen mode Exit fullscreen mode

Text-Decoration
Allows text to be decorated through one of five properties:
underline, overline, line-through, blink, none.

A:link, A:visited, A:active {
 text-decoration: none; 
}

Enter fullscreen mode Exit fullscreen mode

Vertical-Align
Used to alter the vertical positioning of an inline element,
relative to its parent element or to the element's line.

IMG.middle {
 vertical-align: middle; 
} 

Enter fullscreen mode Exit fullscreen mode
IMG {
 vertical-align: 50%; 
} 

Enter fullscreen mode Exit fullscreen mode
.exponent {
 vertical-align: super; 
} 

Enter fullscreen mode Exit fullscreen mode

Text-Transform
Allows for capitalizing the first letter of each word (capitalize),
capitalizing all letters of a word (uppercase), using all small
letters in each word(lowercase), and the inital value(none).

H1 {
 text-transform: uppercase; 
} 

Enter fullscreen mode Exit fullscreen mode
H2 {
 text-transform: capitalize; 
}

Enter fullscreen mode Exit fullscreen mode

Text-Align
Used to justify text left, center, right, and justify.

H1 {
 text-align: center; 
}

Enter fullscreen mode Exit fullscreen mode
P.newspaper {
 text-align: justify; 
}

Enter fullscreen mode Exit fullscreen mode

Text-Indent
Used to specify the amount of indentation prior to the first line
of text.

P {
 text-indent: 5em; 
}

Enter fullscreen mode Exit fullscreen mode

Line-Height
Used to control the spacing between baselines of text.

P {
 line-height: 200%; 
}
Enter fullscreen mode Exit fullscreen mode

Classification Properties

List-Style-Type

Specifies the type of list-item marker, and is used if list-styleimage is none or if image loading is turned off.

LI.square {
 list-style-type: square; 
}

Enter fullscreen mode Exit fullscreen mode
UL.plain {
 list-style-type: none; 
}

Enter fullscreen mode Exit fullscreen mode
OL {
 list-style-type: upper-alpha; 
} 
/* A B C D E etc. */

Enter fullscreen mode Exit fullscreen mode
OL OL {
 list-style-type: decimal; 
} 
/* 1 2 3 4 5 etc. */

Enter fullscreen mode Exit fullscreen mode
OL OL OL {
 list-style-type: lower-roman; 
} 
/* i ii iii iv v etc. */

Enter fullscreen mode Exit fullscreen mode

List-Style-Image
Specifies the image that will be used as a list-item marker when
image loading is turned on, replacing the marker specified in
the list-style-type property.

UL.check {
 list-style-image: url(/LI-markers/checkmark.gif); 
}

Enter fullscreen mode Exit fullscreen mode
UL LI.x {
 list-style-image: url(x.png); 
} 

Enter fullscreen mode Exit fullscreen mode

List-Style-Position
Determines where the marker is placed in regard to the list
item. If the value inside is used, the lines will wrap under the
marker instead of being indented. outside is default.

UL {
 list-style-position: inside;
}

Enter fullscreen mode Exit fullscreen mode

Box Properties

Margin-Top
Sets the top margin of an element by specifying a length or a
percentage.

BODY { 
margin-top: 5pt; 
}

Enter fullscreen mode Exit fullscreen mode

Margin-Right
Sets the right margin of an element by specifying a length or a
percentage.

P.narrow {
 margin-right: 50%; 
}

Enter fullscreen mode Exit fullscreen mode

Margin-Bottom
sets the bottom margin of an element by specifying a length or
a percentage.

DT {
 margin-bottom: 3em; 
}

Enter fullscreen mode Exit fullscreen mode

Margin-Left
sets the left margin of an element by specifying a length or a
percentage.

ADDRESS {
 margin-left: 50%; 
}

Enter fullscreen mode Exit fullscreen mode

Margin
Sets the margins of an element by specifying top, bottom, left
and right margins -- all either specifying length or percentage.

BODY {
 margin: 5em; 
} /* all margins 5em */
Enter fullscreen mode Exit fullscreen mode
P {
 margin: 2em 4em; 
} /* top & bottom 2em, left & right 4em */
Enter fullscreen mode Exit fullscreen mode
DIV {
 margin: 1em 2em 3em 4em; 
} 
/* top margin 1em, right 2em, bottom 3em, left 4em */
Enter fullscreen mode Exit fullscreen mode

Padding-Top
Describes the amount of space between the top border and
the content of the selector.

P {
 padding-top: 20%; 
}
Enter fullscreen mode Exit fullscreen mode

Padding-Right
Describes the amount of space between the right border and
the content of the selector.

P {
 padding-right: 20 px; 
}

Enter fullscreen mode Exit fullscreen mode

Padding-Bottom
Describes the amount of space between the bottom border
and the content of the selector.

P {
 padding-bottom: 5 em; 
}

Enter fullscreen mode Exit fullscreen mode

Padding-Left
Describes the amount of space between the left border and
the content of the selector.

P {
 padding-left: 15 pt; 
}

Enter fullscreen mode Exit fullscreen mode

Padding
Shorthand for the padding-top, padding-right, padding-bottom,
and padding-left properties.

BLOCKQUOTE {
 padding: 2em 4em 5em 4em; 
}

Enter fullscreen mode Exit fullscreen mode

Border-Top-Width
Used to specify the width of an element's top border.

P {
 border-top: 20%; 
} 

Enter fullscreen mode Exit fullscreen mode

Border-Right-Width
Used to specify the width of an element's right border.

P {
 border-right: 20%; 
} 

Enter fullscreen mode Exit fullscreen mode

Border-Bottom-Width
Used to specify the width of an element's bottom border.

P {
 border-bottom: 20%; 
}

Enter fullscreen mode Exit fullscreen mode

Border-Left-Width
Used to specify the width of an element's left border.

P {
 border-left: 20%; 
}

Enter fullscreen mode Exit fullscreen mode

Border-Width
Used to set the width of an element's border (either all
borders, or specifying top border, right border, bottom border,
left border).

P {
 border-width: 20%; 
}
Enter fullscreen mode Exit fullscreen mode
P {
 border-width: 10px 5px 10px 5px; 
}
Enter fullscreen mode Exit fullscreen mode

Border-Color
Used to set the color of an element's border.

P {
 border-color: #00000; 
}

Enter fullscreen mode Exit fullscreen mode

Border-Style
Sets style of a border - none, dotted, dashed, solid, double.

P {
 border-style: dotted; 
} 
Enter fullscreen mode Exit fullscreen mode

Border-Top
Sets the width, style, and color of an element's top border.

P {
 border-top: 10px, red, double; 
} 
Enter fullscreen mode Exit fullscreen mode

Border-Right
Sets the width, style, and color of an element's right border.

P {
 border-right: 10px, red, double; 
} 

Enter fullscreen mode Exit fullscreen mode

Border-Bottom
Sets the width, style, and color of an element's bottom border.

P {
 border-bottom: 10px, red, double; 
}

Enter fullscreen mode Exit fullscreen mode

Border-Left
Sets the width, style, and color of an element's left border.

P {
 border-left: 10px, red, double; 
}

Enter fullscreen mode Exit fullscreen mode

Border
Sets the width, style, and color of an element's border.

P {
 border: 10px, red, double; 
}

Enter fullscreen mode Exit fullscreen mode

Width
Each block-level or replaced element can be given a width,
specified as a length, a percentage, or as auto.

P {
 width: 15px; 
}

Enter fullscreen mode Exit fullscreen mode
H1 {
 width: 35%; 
}

Enter fullscreen mode Exit fullscreen mode
.foo {
 width: auto; 
}

Enter fullscreen mode Exit fullscreen mode

Height
Each block-level or replaced element can be given a height,
specified as a length or as auto.

P {
 height: 15px; 
}

Enter fullscreen mode Exit fullscreen mode
H1 {
 height: 35%; 
}

Enter fullscreen mode Exit fullscreen mode
.foo {
 height: auto; 
}

Enter fullscreen mode Exit fullscreen mode

Float
Allows text to wrap around an element (left, right, none).

P {
 float: left; 
}

Enter fullscreen mode Exit fullscreen mode
H1 {
 float: right; 
}

Enter fullscreen mode Exit fullscreen mode
.foo {
 float: none; 
}

Enter fullscreen mode Exit fullscreen mode

Clear
Specifies whether an element allows floating elements to its
sides (left, right, none).

P {
 clear: left; 
}

Enter fullscreen mode Exit fullscreen mode
H1 {
 clear: right; 
}

Enter fullscreen mode Exit fullscreen mode
.foo {
 clear: none; 
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)