Which CSS property controls the text size?

Understanding the CSS Property: Font-Size

In CSS (Cascading Style Sheets), the property that controls the text size is font-size. This property is essential in web development and design, as it allows developers and designers to adjust text size to improve readability and overall UX (User Experience).

font-size can be specified in different units such as pixels (px), ems (em), rems (rem), or percentages (%), among others. However, the two most widely used units are pixels and ems.

Practical Example of font-size

Here is an example demonstrating the use of font-size in CSS:

p { 
  font-size: 16px; 
}

In the example above, all paragraph (<p>) elements' text is set to a size of 16 pixels.

Best Practices for font-size

While using the font-size property, it's recommended to use relative units like em or rem rather than absolute units like px. This is because relative units are scalable with respect to the parent element's font-size or the root element's font-size, hence, leading to better responsive design.

Here's an example of font-size usage with relative units:

p { 
  font-size: 1em; 
}

In this case, the size of the text in a paragraph (<p>) is set to be the same as that of the parent's font size.

Additional Insights on font-size and Text Styling

Aside from setting the text size, CSS also includes other properties for controlling text appearance, such as font-weight, text-decoration, and text-transform. It's worth noting that although font-weight and text-style were options in the quiz, they are used for different purposes. The font-weight property controls the thickness of the text, while text-style isn't an actual CSS property at all.

Therefore, to control text size in CSS, font-size is the correct property to use.

Do you find this helpful?