Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Fonts

CSS CODES & EXAMPLES

CSS Fonts

Learn how to control text appearance using CSS font properties such as font-family, font-size, font-weight, font-style and line-height.

01

What are CSS Fonts?

Control the appearance of text

CSS provides several properties for controlling how text is displayed. These properties allow you to select a font, change its size, make it bold or italic, adjust spacing and create readable layouts.

Remember: Fonts affect readability, visual hierarchy and the overall design of a website.
02

Basic Font Properties

Important properties to learn
font-family

Specifies the typeface.

font-size

Controls the size of text.

font-weight

Controls text thickness.

font-style

Controls normal, italic or oblique text.

line-height

Controls vertical space between lines.

font

Shorthand for several font properties.

03

font-family

Choose a typeface

The font-family property specifies the font used to display text.

font-family.css
body {
  font-family: Arial, sans-serif;
}
Arial Font Example
Georgia Font Example
Courier New Font Example
04

font-size

Change text size

The font-size property controls the size of text. Common units include px, em, rem and percentages.

font-size.css
.small {
  font-size: 14px;
}

.medium {
  font-size: 20px;
}

.large {
  font-size: 32px;
}
14px Text
20px Text
32px Text
05

font-weight

Control text thickness

The font-weight property controls how thick or light the characters appear.

font-weight.css
.normal {
  font-weight: 400;
}

.medium {
  font-weight: 500;
}

.bold {
  font-weight: 700;
}

.heavy {
  font-weight: 900;
}
Weight 400
Weight 500
Weight 700
Weight 900
07

line-height

Improve text readability

The line-height property controls the vertical distance between lines of text. It is especially important for paragraphs and long-form content.

line-height.css
p {
  font-size: 16px;
  line-height: 1.7;
}
Good Line Height

CSS line-height makes paragraphs easier to read. Proper spacing between lines creates a cleaner and more comfortable reading experience.

08

Font Shorthand

Write multiple font properties together

The font property can combine several font properties into one declaration.

font-shorthand.css
.text {
  font: italic 700 20px/1.6 Arial, sans-serif;
}
Structure: font-stylefont-weightfont-size/line-heightfont-family
09

System Font Stack

Use fonts available on the user’s device
system-font.css
body {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

A font stack provides fallback choices so the browser can use an available font when the first choice is not installed.

10

Google Fonts Example

Using an external web font

Web fonts can be loaded from external font services. For example, a website can use the Poppins family.

google-font.css
<link
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap"
  rel="stylesheet">

body {
  font-family: "Poppins", sans-serif;
}
Poppins Font Example
12

Responsive Font Size

Use modern responsive typography
responsive-font.css
h1 {
  font-size: clamp(28px, 5vw, 52px);
}
Responsive Heading

clamp() can create a font size that grows with the viewport while staying within a minimum and maximum size.

13

Important Points

Quick revision

font-family selects the typeface.

font-size controls the size of text.

font-weight controls thickness.

font-style controls italic and related styles.

line-height controls vertical text spacing.

font can combine multiple font properties.

14

Practice Task

Create a professional course heading

🎯 Your Challenge

Create a course title and paragraph using CSS typography.

  • Use a suitable font-family.
  • Set the heading to at least 32px.
  • Use font-weight: 700.
  • Set paragraph line-height: 1.7.
  • Make the heading responsive using clamp().
15

CSS Fonts Live Runner

Run and experiment with typography
LIVE PREVIEW
`;document.getElementById( "sncecFontsPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFontsRun();} );

CSS Flex Shrink

  • 19/08/2026

CSS Flex Basis

  • 19/08/2026

CSS Flex Wrap

  • 19/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *