CSS font styles are used to control the appearance of text on a webpage. Some common CSS font styles include:
- font-family: Specifies the font type for the text (e.g., Arial, Times New Roman, sans-serif).
- Standard Format: font-family: <font name1, font name2, ...>
- browser will first try to apply the first font, and if it's not available, it will try the next one.
- font-size: Specifies the size of the text (e.g., absolute: 16px, xx-small, small, medium, large, x-large, xx-large, relative: 1.2em, 120%, 1.5rem).
- Absolute Units(px, xx-small, small, medium, large, x-large, xx-large): These specify the exact size of the text in pixels or predefined sizes.
- Relative Units(em, rem, %): These specify the size of the text relative to the parent element's font size (em), the root element's font size (rem), or a percentage of the parent element's font size (%).
- font-weight: Specifies the thickness of the text (e.g., normal, bold, 100-900 (400:normal, 700:bold)).
- font-style: Specifies the style of the text (e.g., normal, italic, oblique(tilts the text. italic has its tilted font already designed.)).
CSS Web Fonts
CSS web fonts allow developers to use custom fonts on their websites, even if the user doesn't have those fonts installed on their device. This is done by linking to a font file hosted on a server or using a font service like Google Fonts.
To use a web font, you can include a link to the font file in your HTML document's <head> section, and then use the font-family property in your CSS to apply the font to specific elements.
Example:
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
CSS Icon Fonts
Icon fonts are a way to display icons using web fonts. They allow you to use icons as if they were regular text, making them easy to style and manipulate with CSS.
You can find a variety of icon fonts online, such as Font Awesome and Bootstrap Icons.