CSS Font & Text Properties


CSS provides many font and text properties that control the appearance of your content. These include font size, font family, font weight, text alignment, text transformation, and more.


Font Shorthand Property

Syntax:

font: font-style font-variant font-weight font-size/line-height font-family;

Example:

font: italic normal bold 12px/16px Verdana;

Equivalent Longhand:

font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 12px;
line-height: 16px;
font-family: Verdana;


Font Embedding with @font-face

You can load custom fonts using @font-face.

Syntax:

@font-face {
  font-family: CustomFont;
  src: url("fonts/CustomFont.ttf");
}

Example:

@font-face {
  font-family: SketchRockwell;
  src: url("fonts/SketchRockwell.ttf");
}

h1 {
  font-family: SketchRockwell;
  font-size: 3.5em;
}

HTML & CSS Course (Example)


Importing Google Fonts

Syntax:

@import url('https://fonts.googleapis.com/css?family=Lato');

Example:

@import url('https://fonts.googleapis.com/css?family=Lato');

body {
  font-family: Lato, Arial, sans-serif;
}


Font-Family

Common generic families:

Examples:

p { font-family: serif; }

p { font-family: sans-serif; }

p { font-family: monospace; }

Serif text example

Sans-serif text example

Monospace text example


Font-Size

Font sizes can be defined using px, em, %, or pt.

Examples:

.font-size-10 { font-size: 10px; }

.font-size-20 { font-size: 20px; }

.font-size-30 { font-size: 30px; }

.font-size-40 { font-size: 40px; }

.font-size-50 { font-size: 50px; }

10px text

20px text

30px text

40px text

50px text


Font Color

Examples:

.color-ddd { color: #DDD; }

.color-coral { color: coral; }

.color-rgba { color: rgba(30, 106, 255, 0.75); }

Default text color

#DDD color

Coral color

RGBA color


Font-Weight

Examples:

.weight-light { font-weight: 300; }

.weight-bold { font-weight: bold; }

Light text

Bold text


Font-Style

Examples:

.font-style-italic { font-style: italic; }

.font-style-oblique { font-style: oblique; }

Italic text

Oblique text


Text-Align

Examples:

.text-align-center { text-align: center; }

.text-align-justify { text-align: justify; }

Centered text

Justified text stretches the content so that each line has equal width, making the edges of the text block align.


Text-Transform

Examples:

.uppercase { text-transform: uppercase; }

.capitalize { text-transform: capitalize; }

uppercase text

capitalized text example


Text-Decoration

Decorations include: overline, underline, line-through

Examples:

.text-overline { text-decoration: overline; }

.text-line-through { text-decoration: line-through; }

.text-underline { text-decoration: underline; }

Overlined text

Line-through text

Underlined text


Text Shadow

Syntax:

text-shadow: horizontal vertical blur color;

Example:

text-shadow: 2px 2px 7px #000;

Shadowed text example


Word Wrap

Examples:

word-wrap: normal;

word-wrap: break-word;

ThisIsAVeryLongTextWithoutSpacesThatOverflows

ThisIsAVeryLongTextWithoutSpacesThatBreaks

HTML Logo