Font properties in CSS allow you to control the appearance and styling of text on a web page. They enable you to define various aspects of the font used, such as its family, size, weight, style, and more. Here are the key font properties in CSS:
.serif { font-family: "Times New Roman", Times, serif; } .sansserif { font-family: Arial, Helvetica, sans-serif; } .monospace { font-family: "Lucida Console", Courier, monospace; }
The font-size property sets the size of the text.
Always use the proper HTML tags, like h1 - h6 for headings and paragraph tag for paragraphs.
The font-size value can be an absolute, or relative size.
Absolute size:
Relative size:
h1{ font-size: 40px; } h2{ font-size: 40pt; } h3{ font-size: 80%; }
In CSS, the font-weight property is used to control the thickness or boldness of the text. It allows you to specify the weight of a font by using different keywords or numeric values.
Here are the common ways to set the font-weight property:
It's worth noting that the availability of different font weights depends on the specific font family being used. Not all font families have multiple weights available, and the visual effect of changing the font weight may vary across fonts.
Here's an example that demonstrates the usage of font-weight property:
i { font-weight: bold; } h1 { font-weight: 300; } p { font-weight: bolder; }
In the above example, the <i> elements will have a bold font weight, the <h1> elements will have a lighter font weight (300), and the <p> elements will have a font weight increased relative to their parent's font weight.
By adjusting the font-weight property, you can control the visual weight of the text, allowing for emphasis, contrast, and better typographic hierarchy in your web pages.
The font-style property is mostly used to specify italic text.
This property has three values:
p.normal { font-style: normal; } p.italic { font-style: italic; } p.oblique { font-style: oblique; }
The font-variant property specifies whether or not a text should be displayed in a small-caps font.
In a small-caps font, all lowercase letters are converted to uppercase letters. However, the converted uppercase letters appears in a smaller font size than the original uppercase letters in the text.
p.normal { font-variant: normal; } p.small { font-variant: small-caps; }
In CSS, the font-stretch property allows you to control the width or condensedness of a font. It defines how wide or narrow the characters in a font appear. The font-stretch property is useful for adjusting the overall appearance of text, especially when working with variable fonts that provide different width variations.
Here are the common values that can be used with the font-stretch property:
Here's an example that demonstrates the usage of the font-stretch property:
h1 { font-stretch: condensed; } p { font-stretch: expanded; } span { font-stretch: 7; }
In the above example, the <h1> elements will have a condensed font stretch, the <p> elements will have an expanded font stretch, and the <span> elements will have a custom font stretch using the numeric value 7.
It's important to note that the effectiveness of the font-stretch property may vary depending on the font family being used. Not all fonts have multiple width variations available, so the visual effect may differ.
By adjusting the font-stretch property, you can control the width of the text and achieve different visual effects to enhance the overall typography of your web pages.
In CSS, the font-synthesis property is used to control how missing font styles or weights are synthesized by the browser when a requested font is not available. It determines whether the browser should attempt to simulate the missing font styles or weights using available alternatives.
The font-synthesis property accepts the following values:
Here's an example that demonstrates the usage of the font-synthesis property:
h2{ font-synthesis: weight; } span { font-synthesis: style; } p { font-synthesis: style weight; }
In the above example, the <h2> elements will enable font weight synthesis, the <span> elements will enable font style synthesis, and the <p> elements will enable both font weight and style synthesis.
It's important to note that font synthesis is a browser-dependent feature, and the effectiveness of font synthesis may vary across different browsers and operating systems. Some browsers may not support font synthesis, or the synthesized results may not match the exact appearance of the requested font.
By utilizing the font-synthesis property, you can control how missing font styles or weights are handled by the browser, providing fallback options and enhancing the visual consistency of your web typography.
In CSS, the font-display property is used to specify how a web font should be displayed and rendered while it is loading. It allows you to control the behavior of fallback text and minimize the impact of font loading on the overall user experience.
The font-display property accepts the following values:
Here's an example that demonstrates the usage of the font-display property:
@font-face { font-family: 'Wix Madefor Text'; src: url('Wix-Madefor-Text.ttf2') format('ttf2'), url('Wix-Madefor-Text.ttf') format('ttf'); font-display: swap; } h1 { font-family: 'Wix Madefor Text', sans-serif; }
<!DOCTYPE html> <html lang="en"> <head> <title>Tutor Joes</title> <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet"> <style> h1{ font-family: 'Pacifico', cursive; font-weight:normal; font-variant: small-caps; color:red; } p{ font-style:italic; font-size: 25px; } span{ font: bold 12pt Arial; } </style> </head> <body> <h1>CSS Font Properties</h1> <p> <span>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Qui, placeat eius! Error deserunt eaque sed non, laboriosam quaerat veritatis </span>veniam possimus? Facilis corporis quae at alias esse optio sint dignissimos.Lorem ipsum dolor sit, amet consectetur adipisicing elit. Qui, placeat eius! Error deserunt eaque sed non, laboriosam quaerat veritatis veniam possimus? Facilis corporis quae at alias esse optio sint dignissimos. </p> </body> </html>To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions