Home » CSS » CSS Fonts

CSS Fonts

CSS Fonts

In this lecture we learn about css fonts. The CSS font properties define the font family, boldness, size, and the style of a text.

CSS Font Families

In CSS, there are two types of font family names:
  1. generic family  a group of font families with a similar look (like “Serif” or “Monospace”)
  2. font family  a specific font family (like “Times New Roman” or “Arial”)
The font family of a text is set with the font-family property. The font-family property should hold several font names as a “fallback” system. If the browser does not support the first font, it tries the next font, and so on.
Start with the font you want, and end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available.
Note: If the name of a font family is more than one word, it must be in quotation marks, like: “Times New Roman”.
More than one font family is specified in a comma-separated list:
p {
font-family: “Times New Roman”, Times, serif;}

Font Style

The font-style property is mostly used to specify italic text.
This property has three values:
  1. normal  The text is shown normally
  2. italic  The text is shown in italics
  3. oblique  The text is “leaning” (oblique is very similar to italic, but less supported)
p.normal {
font-style: normal;}p.italic {
font-style: italic;}p.oblique {
font-style: oblique;}

Font Size

The font-size property sets the size of the text.
Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs. Always use the proper HTML tags, like <h1> to <h6> for headings and <p> for paragraphs. The font-size value can be an absolute, or relative size.

Absolute size:

  1. Sets the text to a specified size
  2. Does not allow a user to change the text size in all browsers (bad for accessibility reasons)
  3. Absolute size is useful when the physical size of the output is known

Relative size:

  1. Sets the size relative to surrounding elements
  2. Allows a user to change the text size in browsers

Font Size With Pixels

Setting the text size with pixels gives you full control over the text size:-
h1 {
font-size: 40px;}h2 {
font-size: 30px;}p {
font-size: 14px;}
Note: If you use pixels, you can still use the zoom tool to resize the entire page.

Font Weight

The font-weight property specifies the weight of a font:-
p.normal {
font-weight: normal;}p.thick {
font-weight: bold;}

Font Variant

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;}

All CSS Font Properties

Property Description
font Sets all the font properties in one declaration
font-family Specifies the font family for text
font-size Specifies the font size of text
font-style Specifies the font style for text
font-variant Specifies whether or not a text should be displayed in a small-caps font
font-weight Specifies the weight of a font

You Can Also Visit: Lists In CSS

You Can Also Visit My YouTube Channel: s1school

, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *


error: Sorry You Have Not Permission To Copy!