Font in CSS
In CSS, font properties determine family font, density, size and style for text.
Font Family in CSS
In CSS there are two types of names of family fonts:
- generic family - font family group with similar appearance (eg serif or monospace)
- font family - certain family font groups (eg Times New Roman or Arial)
Times News Roman
Georgia
Font serif has the last small tiles of some Sans-serif charactersArial
Verdana
'Sans' means 'no', this font does not have a Monospace character (uniquely)Courier New
Lucida Console
Single-character characters have the same widthSerif is the footer of the word, the sans-serif font is a font without a foot.
The difference between serif and sans-serif fonts
Font family
The family font of a piece of text is defined by the font-family.
This feature should have several font styles to reserve. If the browser does not support this font, it will try the following font and so on.
Select the font you want first and end with a font belonging to the generic family group so that the browser selects the same font in this group if there are no other fonts available. Fonts separated by commas.
Note: If the family font name has more than one word, it must be placed in quotation marks.
p {
font-family: "Times New Roman", Times, serif;
}
Font style
The font-style
feature is often used to define italic text; it has three values:
- normal - normal text
- italic - italics
- oblique - italic text in italic but less supported
p.normal {
font-style: normal;
}
p.italic {
font-style: italic;
}
p.oblique {
font-style: oblique;
}
Font size
font-size
properties used to specify text size. Control of text size is very important in web design. However, the text size should not be used to make text that looks like a title or title look like a piece of text.
Always use appropriate HTML tags, like
next
for good titles
for text paragraphs. Text size values can be absolute or relative.
Absolute size
- Select a specific size for the text
- Do not allow users to change the text size on all browsers (not good for readers' accessibility)
- Useful when it comes to specifying the physical size of the output
Relative size
- Set the text size relative to the surrounding elements
- Allow users to change the text size on the browser
Note : If you do not specify the font size, the default default size of the text (paragraph) is 16px (16px = 1em).
Set font size in pixels
Select the text size in pixels for you to have full control over the text size.
h1 {
font-size: 40px;
}
h2 {
font-size: 30px;
}
p {
font-size: 14px;
}
Note: If using pixels, you can still use the zoom in / out tool to resize the whole page.
Set font size by em
To allow users to change text (on the Browser Menu), many developers use me instead of pixels. I am also a unit encouraged by W3C.
1em is equivalent to the current font size. The default text on the browser of the text is 16px. So the default size of 1em is 16px. To convert from pixel to em using the formula: pixel / 16 = you.
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}
h2 {
font-size: 1.875em; /* 30px/16=1.875em */
}
p {
font-size: 0.875em; /* 14px/16=0.875em */
}
In the above example, the text size is equal to the previous pixel usage example but for me it is possible to change the text size in all browsers. However, on older versions of IE there is still a problem, when the text is enlarged it will look bigger than the correct size, similarly when scaled it will be smaller than the actual level.
Use a combination of percent and me
The solution that works for all browsers is to set the default text size as a percentage of the element .
body {
font-size: 100%;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 1.875em;
}
p {
font-size: 0.875em;
}
Weight font
The font-weight
is used to specify normal or bold text.
p.normal {
font-weight: normal;
}
p.thick {
font-weight: bold;
}
Text size with feedback
Text size can be set in units of vw, ie viewport width. Then the text size will follow the browser window size.
Hello
Note: Viewport is the browser window size. 1vw - 1% of viewport width. If the viewport is 50cm wide, 1vw is 0.5cm.
Variant font
The font-variant
determines whether the text is displayed in small-caps. In small-caps, lowercase letters are converted to uppercase but smaller in size than regular capital letters.
p.normal {
font-variant: normal;
}
p.small {
font-variant: small-caps;
}
Previous article: Text in CSS
The following article: Icon in CSS
You should read it
- Instructions for setting the default font in Microsoft Word
- What is Icon Font and how to create Icon Font
- 8 tools to 'identify' fonts used on applications or websites
- Set the default font and font size in Excel
- How to change the Zalo font on the phone
- How to set the default font and font size on Excel
- How to use Primary font
- New font full of broken lines enhances memory
May be interested
- How to change fonts in Windows 11tired of windows 11's default fonts? here's how to set them to whatever you like. this article shows you how to change the windows 11 system font so that different areas of the os will use the font type you prefer.
- Microsoft released Font Maker, allowing users to freely create their own font on Windows 10font maker is a font creation application that allows windows 10 users to create their own personalized font by writing each letter and symbol.
- How to download and install Vietnamese fonts for computersfull vietnamese font set will help you not to have font error or vietnamese typing when writing, chatting, surfing the web or adding text in your graphic designs. download the full set of vietnamese fonts and install the font on your computer according to the quick instructions below.
- How to set the default font and font size on Excelon windows operating systems, excel uses the calibri font as the default font. however, if you want to use another font or simply change the default font size, you just need to adjust some settings on excel.
- Set the default font and font size in Excelevery time you open excel, you must align the font format and font size accordingly. the following article will guide you how to set the default font size and font size in excel.
- How to change the font in WordPressonce you have successfully installed and set up wordpress on localhost, you realize one thing: wordpress's default font when typing vietnamese does not look good, it is not beautiful when using large font size, or zoom in. .. or simply, we want to change the default font of wordpress, how to do it?
- How to Add Font in Microsoft Wordthis wikihow teaches you how to install a font on your windows or mac computer in order to use the font in microsoft word. download the font from a trusted website. fonts are a common way to transmit viruses, so take care to only download...
- Set the default font in Word 2007 2010 2013before drafting, you usually install the font and font size in the first font. it is simple but if you have to work a lot with word, then setting the font and font size will be very time consuming.
- How to change the system font after updating Windows 10 Creator's Updatechanging the size of the system font is probably just a small but surprisingly useful feature.
- Font format on Wordinstructions on how to format fonts in word. 1. font format before editing the text you should format the font first. to format the font perform the following steps: step 1: go to the home tab - click the font icon below (or click the