Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Font Size

CSS Font Size

CSS CODES & EXAMPLES

CSS Font Size

Learn how to control text size in CSS using px, em, rem, percentage, viewport units and responsive typography.

01

What is font-size?

Control the size of text

The CSS font-size property defines how large or small text should appear on a webpage.

Syntax: font-size: value;
02

Basic Font Size

Using pixels
font-size.css
p {
  font-size: 20px;
}

This text has a font size of 20px.

03

Font Size in Pixels

Absolute unit example
12px

Small text example

16px

Normal text example

24px

Medium heading example

32px

Large heading example

48px

Very large heading

04

Font Size with em

Relative to the parent element

The em unit is relative to the font size of the element’s parent.

em-example.css
.parent {
  font-size: 20px;
}

.child {
  font-size: 1.5em;
}
Parent text — 20px
Child text — 1.5em
05

Font Size with rem

Relative to the root font size

The rem unit is relative to the root HTML element’s font size. It is widely used for scalable and consistent typography.

rem-example.css
html {
  font-size: 16px;
}

h1 {
  font-size: 2rem;
}

p {
  font-size: 1rem;
}

2rem Heading

1rem paragraph text.

06

Percentage Font Size

Relative sizing
percentage.css
body {
  font-size: 16px;
}

p {
  font-size: 125%;
}

This paragraph uses 125% font size.

08

Responsive Font Size with clamp()

Modern CSS typography

The CSS clamp() function allows you to define a minimum, preferred and maximum font size.

clamp.css
h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

Responsive CSS Heading

09

Small, Medium and Large Text

Create a simple type scale
Small

Small text for supporting information.

Medium

Medium text for normal content.

Large

Large text for important content.

Extra Large

Extra large heading text.

10

Different Font Sizes for Elements

Build a clear hierarchy
typography.css
h1 {
  font-size: 42px;
}

h2 {
  font-size: 30px;
}

h3 {
  font-size: 24px;
}

p {
  font-size: 16px;
}

small {
  font-size: 13px;
}

H1 Main Heading

H2 Section Heading

H3 Subheading

Normal paragraph text.

Small supporting text.
11

Font Size with CSS Variables

Reusable typography values
variables.css
:root {
  --heading-size: 36px;
  --body-size: 16px;
}

h1 {
  font-size: var(--heading-size);
}

p {
  font-size: var(--body-size);
}
12

Responsive Heading Example

Practical website design

Build Your Digital Future

Learn computer skills with practical lessons and hands-on learning resources.

responsive-heading.css
h2 {
  font-size: clamp(1.8rem, 4vw, 3rem);
}

p {
  font-size: clamp(1rem, 1.5vw, 1.2rem);
}
13

Common Font Size Units

Quick reference
px

Fixed CSS pixel unit.

em

Relative to the parent’s font size.

rem

Relative to the root font size.

%

Relative percentage value.

vw

Relative to viewport width.

vh

Relative to viewport height.

15

Quick Revision

Important points
font-size Controls the size of text.
px Pixel-based sizing.
em Relative to the parent.
rem Relative to the root element.
vw Relative to viewport width.
clamp() Creates flexible responsive sizing.
16

Practice Task

Test your CSS skills

🎯 Your Challenge

Create a responsive course page heading.

  • Use clamp() for the main heading.
  • Use rem for paragraph text.
  • Create three different heading levels.
  • Make the design readable on mobile screens.
  • Test the result by resizing the browser.
17

CSS Font Size Live Runner

Experiment with font-size values
LIVE PREVIEW
`;document.getElementById( "sncecFSPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFSRun();} );

CSS Colors

  • 17/08/2026

CSS Flex Wrap

  • 19/08/2026

HTML CSS

  • 17/08/2026

Leave a Reply

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