CSS Font property is used to make your fonts attractive and pleasing to the eyes. You can use different fonts for your headings, paragraphs, and word emphasizing.
CSS Font property is way smarter than HTML Font Tag. HTML font Tag was used till HTML 4, but in HTML 5, it was deprecated. You can no longer use it, but it was an inferior option compared to the CSS Font property.
CSS Fonts has multiple options to give style to the fonts. You can alter the color, size, weight, and family of the fonts. You can assign various font families at once as a replacement if one is not supported. Let's look at multiple CSS Font properties and their uses:
Values | Description |
---|---|
Font family | Assign font-families to the text. |
Font color | It assigns the color of the text. |
Font style | It makes the font bold, italic or oblique. |
Font variant | It creates a small-caps effect. |
Font size | It assigns the size of the font. |
Font weight | It controls the thickness of the font. |
Font Families are a set of different fonts with a similar design. These fonts under one family differ in size, weight, and style, but the characters' basic design would be the same. For example - Arial is a Font family with fonts Arial regular, Arial Bold, Arial Italic, etc.
CSS Font family property let us assign multiple font families at once. It doesn't mean that all families will be loaded and used together. Instead, the second one will be used if the browser does not support the first font, and the third one will be used if the second font is not supported. It works in a particular order of priority.
Look at the example below and go to our online editor and change the font order to see the changes.
This is a paragraph, shown in the Times New Roman font.
This is a paragraph, shown in the Arial font.
Fonts' color is very important for the look and feel of the website. You can give colors to hyperlinks, to highlight them. Headings can be colored in a different color than regular paragraph text.
To change the color of a particular section of the website like paragraph and headings, Class, ID, and tag selectors will always help. If you don't know about class, ID, and other selectors, please read our CSS Selectors article.
There are three methods to give color to the font:
This is a paragraph.
CSS font-size
font-size property is used to specify size of the font.
The default size is 16px
. Font size can be given in pixels, em(1em=16px)
,
or in percentage value. There are also some other predefined values given below :
Font Size Values | Description |
---|---|
x-small | It displays extra small text. |
xx-small | It display extremely small text. |
small | It displays small text. |
smaller | It displays comparatively smaller text. |
medium | It displays medium text size. |
large | It displays large text size. |
x-large | It displays extra large text size. |
xx-large | It displays extremely large text size. |
larger | It displays comparatively larger text size. |
Size in pixels or % | It sets the value in percentage and pixels. |
You can check the example below to see the changes made by all the values.
This font size is extremely small.
This font size is extra small
This font size is smaller.
This font size is small
This font size is medium.
This font size is large.
This font size is larger.
This font size is 20 pixels.
This font size is extra large.
This font size is extremely large.
This font size is set on 200%.
Font Styles property in CSS is used to make the font italic. The Italic font is slightly tilted towards the right.
Font style property has three values. One is normal and the other two are slightly different versions of italic:
This paragraph is shown in normal style.
This paragraph is shown in italic style.
This paragraph is shown in oblique style.
Font variant property is fun. It changes the font into small caps. In Small-caps font, all the lowercase alphabets are changed to uppercase, but their size doesn't change. It means that the changed uppercase alphabets are displayed in the size of lowercase alphabets.
There are two values of font-variant property:
This paragraph is shown in small font.
CSS font-weight
property defines the weight of the font, i.e., how thick a font is. It is used to emphasize a particular piece of text or in headings.
Font-weight can be applied either by using specific text values or by numbers:
This is a paragraph.
This is a paragraph.
This is a paragraph.
This is a paragraph.
Follow Us: