Home 〉 CSS Tutorials 〉 CSS Font Properties Tutorial with Examples | font-family, font-size, font-style
CSS Font Properties Tutorial with Examples | font-family, font-size, font-style !
Are you aiming to enhance your website's typography? CSS font properties like `font-family`, `font-size`, and `font-style` allow you to control the appearance of text. This tutorial explains how to select appropriate fonts, adjust sizes, and apply styles like italic or bold. Improve readability and aesthetics by mastering these properties. Read the post on CSS Font Properties
In this guide, we'll cover important CSS font properties like:
CSS font properties let you control how text appears on a webpage. These properties help you define the font family, font size, style, 'weight', 'variant', and more. Fonts play a key role in website readability and design.
Let's break down each property with examples so you can easily apply them in your projects.
Specifies the font of the text.
<!DOCTYPE html>
<html>
<body>
<p style="font-family: Arial, sans-serif;">This is Arial font with sans-serif fallback.</p>
</body>
</html>
output 📌
This is Arial font with sans-serif fallback.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
If Arial isn't available, the browser will use a similar sans-serif font.
Defines the size of the text.
<!DOCTYPE html>
<html>
<body>
<p style="font-size: 20px;">This text is 20px in size.</p>
</body>
</html>
output 📌
This text is 20px in size.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Acceptable Units:
Controls if the text is normal, italic, or oblique.
<!DOCTYPE html>
<html>
<body>
<p style="font-style: italic;">This text is italic.</p>
</body>
</html>
output 📌
This text is italic.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values:
Displays text in small-caps (uppercase in smaller font).
<!DOCTYPE html>
<html>
<body>
<p style="font-variant: small-caps;">This text uses small-caps.</p>
</body>
</html>
output 📌
This text uses small-caps.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'small-caps', 'normal'
Defines the thickness of the text.
<!DOCTYPE html>
<html>
<body>
<p style="font-weight: bold;">This text is bold.</p>
</body>
</html>
output 📌
This text is bold.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values:
You can combine font properties using the 'font' shorthand.
<!DOCTYPE html>
<html>
<body>
<p style="font: italic bold 16px Arial, sans-serif;">
This is shorthand for font.
</p>
</body>
</html>
output 📌
This is shorthand for font.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Order:
'font-style font-variant font-weight font-size/line-height font-family'
Controls the space between lines of text.
<!DOCTYPE html>
<html>
<body>
<p style="line-height: 1.8;">This paragraph has more space between lines.</p>
</body>
</html>
output 📌
This paragraph has more space between lines.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Sets the space between characters.
<!DOCTYPE html>
<html>
<body>
<p style="letter-spacing: 2px;">Letters are spaced further apart.</p>
</body>
</html>
output 📌
Letters are spaced further apart.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Sets space between words.
<!DOCTYPE html>
<html>
<body>
<p style="word-spacing: 10px;">Words are spaced out more.</p>
</body>
</html>
output 📌
Words are spaced out more.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Controls the text capitalization.
<!DOCTYPE html>
<html>
<body>
<p style="text-transform: uppercase;">This becomes UPPERCASE.</p>
</body>
</html>
output 📌
This becomes UPPERCASE.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'uppercase', 'lowercase', 'capitalize', 'none'
Aligns the text inside a block.
<!DOCTYPE html>
<html>
<body>
<p style="text-align: center;">This text is centered.</p>
</body>
</html>
output 📌
This text is centered.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'left', 'right', 'center', 'justify'
Font properties are essential for good web typography. With 'font-family', 'font-size', 'font-style', 'font-weight', and related properties, you can create clean and readable designs. Start experimenting and apply them in your own projects for better user experience.
Use 'em' or 'rem' for responsive design and 'px' for fixed designs.
Import the font from [Google Fonts](https://fonts.google.com) and apply it via 'font-family'.
'italic' uses a specific italic font, while 'oblique' slants the normal font.