Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Working with Fonts and Font Properties | Formatering av Text för Läsbarhet
CSS-Grunder

Working with Fonts and Font Properties

Svep för att visa menyn

Fonts strongly influence the tone and readability of a web page. In this chapter, we explore the most commonly used font-related CSS properties: font-family, font-size, font-weight, and font-style.

Note
Note

All examples use the same text to show how these properties change appearance.

font-family

The font-family property defines which typeface is used to display text.

p {
  font-family: 'Montserrat', Arial, sans-serif;
}

Multiple fonts can be listed as fallbacks, separated by commas. If the first font is not available, the browser uses the next one in the list. It is recommended to always include a generic fallback such as: serif, sans-serif, monospace.

diff+font+family

font-size

The font-size property controls how large text appears.

p {
  font-size: 16px;
}

Common units:

  • px: fixed size;
  • em: relative to parent element;
  • rem: relative to root element.
diff+font+size
diff+font+size

font-weight

Controls the thickness of text. Numeric values: 100–900. Keywords: normal, bold, lighter.

diff+font+weight

font-style

Specifies the style of the text: normal, italic, or oblique.

diff+font+style

Pseudo-class ::first-letter

::first-letter targets the first letter of an element (typically a paragraph or heading), allowing decorative or stylized effects.

selector::first-letter {
 /* some styles */
}

Let's run the next example to see how it works.

index.html

index.html

styles.css

styles.css

Note
Summery

font-family defines the typeface and fallbacks.

font-size controls text size in px, em, or rem.

font-weight adjusts thickness using numbers or keywords.

font-style changes the font style.

::first-letter styles the first letter of a text block.

1. Which property determines the thickness of the font?

2. What is the default value for the font-style property in CSS?

question mark

Which property determines the thickness of the font?

Vänligen välj det korrekta svaret

question mark

What is the default value for the font-style property in CSS?

Vänligen välj det korrekta svaret

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Avsnitt 2. Kapitel 2
some-alt