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.
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.
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.
font-size
and Text StylingAside 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.