Skip to main content

Understanding Font Properties in CSS Typography (Live Playground)

Font properties in CSS help style and format the text on your web pages. In this tutorial, you will learn about the most important font properties and how to use them, along with sample code and simple explanations.

Font family

The font-family property is used to specify the typeface for an element.

Example:

CSS
body {
font-family: Arial, Helvetica, sans-serif;
}

In this example, the font-family property is set to a prioritized list of typefaces. The browser will use the first available typeface in the list.

Font size

The font-size property is used to set the size of the text.

Example:

CSS
h1 {
font-size: 2rem;
}

In this example, the font-size property is set to 2rem, making the text twice as large as the base font size.

Font weight

The font-weight property is used to set the thickness or boldness of the text.

Example:

CSS
strong {
font-weight: bold;
}

In this example, the font-weight property is set to bold, making the text inside the <strong> element bold.

Font style

The font-style property is used to set the style of the text, such as italic or oblique.

Example:

CSS
em {
font-style: italic;
}

In this example, the font-style property is set to italic, making the text inside the <em> element italic.

Text transform

The text-transform property is used to control the capitalization of the text.

Example:

CSS
.uppercase {
text-transform: uppercase;
}

In this example, the text-transform property is set to uppercase, making the text inside elements with the uppercase class uppercase.

Live Playground, Try it Yourself

Conclusion

By understanding and using font properties in CSS, you can style and format the text on your web pages to create visually appealing and easy-to-read content. These properties allow you to fine-tune the appearance of your text, ensuring that it matches your design requirements and improves the overall user experience.