The best CSS Fonts (font) Tutorial In 2024, In this tutorial you can learn The difference between serif and sans-serif fonts between,CSS font,Font family,Examples,Font style,Examples,font size,Setting the font size pixel,Examples,Use em to set the font size,Examples,Use a combination of percentages and EM,Examples,More examples,All CSS font properties,
CSS font properties define the font, bold, size, text style.
On computer screens, sans-serif fonts are considered easier to read than serif fonts
In CSS, there are two types of font family names:
Generic family | Font family | Explanation |
---|---|---|
Serif | Times New Roman Georgia | End Serif fonts have extra characters in the line of decorative |
Sans-serif | Arial Verdana | "Sans" means without - these fonts at the end with no additional decoration |
Monospace | Courier New Lucida Console | All monospaced characters have the same width |
font-family property of the text font family.
font-family property should be set several font names as a "fallback" mechanism, if the browser does not support the first font, he will try the next font.
Note: If the name of the font family is more than one word, it must be enclosed in quotation marks, such as Font Family: "Times New Roman."
Multiple font family is specified by a comma-separated:
For more commonly used font combinations, look at our Web-safe fonts combinations .
Mainly attribute specifies the font style italic text.
This property has three values:
The size of the font-size property of the text.
Can manage the size of the text in the web design is very important. However, you can not adjust the font size to make paragraphs look like headings, or make the title look like paragraphs.
Be sure to use the correct HTML tags to <h1> - <h6> represents the title and <p> represents a paragraph:
Font size value can be absolute or relative size.
Absolute size:
Relative size:
If you do not specify a font size, the default size, and ordinary text paragraphs, it is 16 pixels (16px = 1em).
Setting the text size with pixels, gives you full control over the text size:
The above example 9, Firefox, Chrome, Opera, and Safari, adjust the text size by scaling Internet Explorer browser.
Although you can adjust the text size via the browser's zoom tool, however, this adjustment is the entire page, not just text
In order to avoid Internet Explorer can not be adjusted in the text, many developers use em units instead of pixels.
em-size unit is recommended by the W3C.
1em is equal to the current font size. In the browser default text size is 16px.
Therefore, the default size of 1em is 16px. The following formula can be converted to pixels em: px / 16 = em
In the above example, em size of the text is the same as the previous example in pixels. However, if you use em units, you can adjust the text size in all browsers.
Unfortunately, IE is still the browser issue. Resize the text, it will be smaller than normal or larger in size.
In all browsers solutions, set <body> element of the default font size is a percentage:
Our code is very effective. In all browsers can display the same text size, and allows all browsers to zoom the text size.
Set the font bold
This example demonstrates how to set the font bold.
You can set the font change
This example demonstrates how to set the font changes.
All the font properties in one declaration
This example demonstrates how to use the shorthand property to set the font properties in one declaration.
Property | 描述 |
---|---|
font | 在一个声明中设置所有的字体属性 |
font-family | 指定文本的字体系列 |
font-size | 指定文本的字体大小 |
font-style | 指定文本的字体样式 |
font-variant | 以小型大写字体或者正常字体显示文本。 |
font-weight | 指定字体的粗细。 |