1 Answers
📚 CSS font-size Examples: Making Headings Bigger and Body Text Smaller
The font-size property in CSS controls the size of text. It's essential for creating readable and visually appealing web pages. You can set sizes using absolute units (like pixels) or relative units (like ems and rems). Let's explore how to make headings bigger and body text smaller!
Quick Study Guide
- 📏 Absolute Units: Pixels (
px) provide fixed sizes. - ⚖️ Relative Units:
em: Relative to the font-size of the element.1emis equal to the current font-size.rem: Relative to the font-size of the root element (html).
- 🧮 Formulas & Conversions:
- To calculate
em: Target Size / Parent Size =emValue. - Example: If the parent font-size is 16px and you want the element to be 24px: $24 \div 16 = 1.5em$
- To calculate
- 💡 Best Practices: Use
remfor overall scalability andemfor local component sizing. - 💻 CSS Syntax:
font-size: 16px;,font-size: 1.2em;,font-size: 1rem;
Practice Quiz
-
What CSS property is used to control the size of text?
- A.
text-size - B.
font-size - C.
text-height - D.
font-height
- A.
-
Which unit is an absolute unit for font-size?
- A.
em - B.
rem - C.
px - D.
%
- A.
-
What does
1emrepresent?- A. 10 pixels
- B. The font-size of the root element
- C. The current font-size of the element
- D. 1 rem
-
Which unit is relative to the root element's font-size?
- A.
em - B.
px - C.
rem - D.
pt
- A.
-
If the parent font-size is 20px and you set an element's font-size to
1.5em, what is the computed font-size of the element?- A. 15px
- B. 20px
- C. 30px
- D. 35px
-
Which of the following is the correct CSS syntax to set the font-size to 18 pixels?
- A.
font-size: 18; - B.
font: 18px; - C.
font-size = 18px; - D.
font-size: 18px;
- A.
-
Why is it recommended to use relative units like
remfor font-size?- A. To make the text look smaller
- B. For better scalability and accessibility
- C. To make the text look bigger
- D. Because absolute units are not supported
Click to see Answers
- B
- C
- C
- C
- C
- D
- B
Join the discussion
Please log in to post your answer.
Log InEarn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀