In this tutorial you will learn about the CSS Fonts and its application with practical example.
CSS Fonts property allows us control the way content or text being presented on the web page, using CSS Fonts we can add more styling and formatting to the content on a web page.
Here is the list of common CSS Fonts Properties –
Property | Description |
---|---|
font-family | This property specifies the face/family of the font for the HTML Element. Example – Serif,Sans-serif,Mono space |
font-style | This property specifies the style of the font for the HTML Element. Example – Normal,Italic,Oblique |
font-variant | This property sets the font to be small-caps for HTML Element |
font-stretch | This property can be used for condensing or expanding your font for the HTML Element. Example – Normal,Wider,Narrower etc. |
font-weight | This property specifies how bold will be the the font for the HTML Element. Example – Bold,Bolder,Lighter etc. |
font-size | This property specifies the size of the font for the HTML Element. Example – Small,Medium,Large etc. |
font | This is shorthand property can be used to set all properties of the font for the HTML Element. |
CSS Font Family
This property specifies the face/family of the font for the HTML Element. Example – Serif,Sans-serif, Monospace
Example Code:
1 |
<p style="font-family:sans-serif;">This text is rendered in sans serif font .</p> |
Output:
This text is rendered in sans serif font .
CSS Font Style
This property specifies the style of the font for the HTML Element. Example – Normal,Italic,Oblique
Example Code:
1 |
<p style="font-style:italic;">This text is in italics.</p> |
Output:
This text is in italics.
CSS Font Variant
This property sets the font to be small-caps for HTML Element.
Example Code:
1 |
<p style="font-variant:small-caps;">This Text in Small Caps.</p> |
Output:
This Text in Small Caps.
CSS Font Stretch
This property can be used for condensing or expanding your font for the HTML Element. Example – Normal,Wider,Narrower etc.
Example Code:
1 2 |
<p style="font-stretch:ultra-expanded;">Expanded version of the font.</p> |
Expanded version of the font.
CSS Font Weight
This property specifies how bold will be the the font for the HTML Element. Example – Bold,Bolder,Lighter etc.
Example Code:
1 |
<p style="font-weight:bold;">This text is in bold.</p> |
Output:
This text is in bold.
CSS Font Size
This property specifies the size of the font for the HTML Element. Example – Small,Medium,Large etc.
Example Code:
1 |
<p style="font-size: x-large;">This text is using a font size x-large;.</p> |
Output:
This text is using a font size x-large;.
CSS Font Property
This is shorthand property can be used to set all properties of the font for the HTML Element.
Example Code:
1 2 3 |
<p style="font:italic small-caps bold 20px georgia,garamond,serif;"> The styles for this text has been specified with the 'font' shorthand property. </p> |
Output:
The styles for this text has been specified with the ‘font’ shorthand property.