Bird
Raised Fist0
CSSmarkup~20 mins

Font size in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Font Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the computed font size of the paragraph?
Given the CSS below, what will be the font size of the paragraph text in the browser?
CSS
html {
  font-size: 16px;
}
body {
  font-size: 1.25rem;
}
p {
  font-size: 120%;
}
A24px
B19.2px
C16px
D20px
Attempts:
2 left
💡 Hint
Remember that 1rem equals the font size of the root element (html).
rendering
intermediate
2:00remaining
Which CSS rule will make the heading twice as large as the base font size?
Assuming the base font size is 16px, which CSS rule will render the heading text at 32px?
Ah1 { font-size: 2rem; }
Bh1 { font-size: 200%; }
Ch1 { font-size: 32px; }
DAll of the above
Attempts:
2 left
💡 Hint
Think about how rem, percentage, and px units relate to the base font size.
selector
advanced
2:00remaining
Which CSS selector targets only paragraphs with font size exactly 1.5rem?
Given multiple paragraphs with different font sizes, which selector matches only those with font size 1.5rem?
Ap[style$='font-size: 1.5rem']
Bp[style^='font-size: 1.5rem']
Cp[style*='font-size: 1.5rem']
Dp[style='font-size: 1.5rem']
Attempts:
2 left
💡 Hint
The *= attribute selector matches if the value contains the substring anywhere.
layout
advanced
2:00remaining
How does changing font size affect Flexbox layout?
In a flex container with items sized by font size (using em units), what happens if the container's font size increases?
AFlex items grow larger because em units scale with the container's font size.
BFlex items stay the same size because em units are fixed to the root font size.
CFlex items shrink because font size increase reduces available space.
DFlex items disappear because em units become invalid.
Attempts:
2 left
💡 Hint
Remember that em units depend on the font size of the element itself or its parent.
accessibility
expert
2:00remaining
Which font size practice best supports accessibility for users with low vision?
Choose the CSS font size approach that best supports accessibility and user control.
AUse fixed pixel font sizes like 14px for all text.
BUse relative font sizes like rem or em and allow user scaling.
CUse very small font sizes to fit more content on screen.
DUse absolute font sizes with !important to prevent changes.
Attempts:
2 left
💡 Hint
Think about how users can adjust text size in their browsers or devices.

Practice

(1/5)
1. What does the CSS property font-size control on a webpage?
easy
A. The color of the text
B. The background color of the text
C. The spacing between letters
D. The size of the text displayed

Solution

  1. Step 1: Understand the role of font-size

    The font-size property in CSS sets how big or small the text appears on the screen.
  2. Step 2: Compare with other text properties

    Other properties like color or spacing control different aspects, not size.
  3. Final Answer:

    The size of the text displayed -> Option D
  4. Quick Check:

    font-size controls text size [OK]
Hint: Font size changes text height, not color or spacing [OK]
Common Mistakes:
  • Confusing font-size with color or spacing properties
  • Thinking font-size changes background color
  • Mixing font-size with letter-spacing
2. Which of the following is the correct CSS syntax to set the font size to 16 pixels?
easy
A. font-size: '16px';
B. font-size = 16px;
C. font-size: 16px;
D. font-size: 16;

Solution

  1. Step 1: Recall CSS property syntax

    CSS uses a colon (:) to assign values, and units like px must be without quotes.
  2. Step 2: Check each option

    font-size: 16px; uses correct syntax: property, colon, value with unit, and semicolon.
  3. Final Answer:

    font-size: 16px; -> Option C
  4. Quick Check:

    Correct CSS syntax uses colon and units without quotes [OK]
Hint: Use colon and units without quotes for CSS properties [OK]
Common Mistakes:
  • Using equal sign instead of colon
  • Putting units inside quotes
  • Omitting units like px
3. What will be the visual result of this CSS on a paragraph?
p { font-size: 2rem; }
medium
A. The paragraph text will be half the root font size
B. The paragraph text will be twice the root font size
C. The paragraph text will be 2 pixels tall
D. The paragraph text size will not change

Solution

  1. Step 1: Understand the unit rem

    rem means "root em" and is relative to the root (html) font size.
  2. Step 2: Interpret 2rem

    Setting font-size to 2rem means text will be twice as big as the root font size.
  3. Final Answer:

    The paragraph text will be twice the root font size -> Option B
  4. Quick Check:

    2rem doubles root font size [OK]
Hint: rem units scale relative to root font size [OK]
Common Mistakes:
  • Thinking rem is pixels
  • Confusing rem with em
  • Assuming no change in size
4. Identify the error in this CSS code snippet:
h1 { font-size: 20; }
medium
A. Missing unit after the number
B. Incorrect property name
C. Missing semicolon
D. Font size cannot be set on h1

Solution

  1. Step 1: Check the font-size value format

    CSS requires a unit like px, em, rem after numeric values for font-size.
  2. Step 2: Identify the missing unit

    The code uses "20" without any unit, which is invalid.
  3. Final Answer:

    Missing unit after the number -> Option A
  4. Quick Check:

    Font size needs units like px or rem [OK]
Hint: Always add units like px or rem after font-size numbers [OK]
Common Mistakes:
  • Omitting units like px or rem
  • Assuming numbers alone are valid
  • Confusing semicolon errors
5. You want to make all paragraph text larger but keep it responsive to user settings. Which CSS rule is best?
p { font-size: ?; }
hard
A. font-size: 1.2rem;
B. font-size: 18px;
C. font-size: 120%;
D. font-size: 1.2em;

Solution

  1. Step 1: Understand responsiveness and user settings

    To respect user font preferences (e.g., browser font size settings), use units relative to the root element.
  2. Step 2: Compare options for responsiveness

    px is fixed and doesn't scale with user changes. em and % are relative to parent and can compound in nesting. rem is relative to root font size, scaling perfectly with user settings.
  3. Step 3: Choose the best option

    1.2rem increases size by 20% relative to root, ideal for accessibility and responsiveness.
  4. Final Answer:

    font-size: 1.2rem; -> Option A
  5. Quick Check:

    rem units scale with root font size and user settings [OK]
Hint: Use rem units for scalable font sizes responsive to user preferences [OK]
Common Mistakes:
  • Using fixed px units ignoring user preferences
  • Using em which can compound unexpectedly
  • Confusing em/% with root-relative rem