
CSS Attribute Selectors: Syntax and Examples
23/07/2023How to Use Google Material Icons and Symbols on a Website
24/07/2023
The lesson on CSS font properties explains how to set a font’s size, family, weight, and style. Here we look at web font formats and ways to load a font into a project.
CSS web font formats
Sites used to ship several formats to support older browsers. For current projects, WOFF2 is a common default. Add WOFF if your browser support requirements call for it. The table also includes formats you may encounter in older stylesheets.
| Format | Description |
| EOT | Embedded OpenType, a legacy Internet Explorer format |
| TTF | TrueType font |
| WOFF | Web Open Font Format |
| WOFF2 | Web Open Font Format 2, with improved compression |
| SVG | Scalable Vector Graphics font, a legacy web font format |
1. The CSS
font-face rule
Use to make a local or downloadable font available by name. This example registers Open Sans and provides a fallback file. Use font files you have permission to host.
font-face
@font-face {
font-family: "Open Sans";
src: url("opensans.woff2") format("woff2"),
url("opensans.woff") format("woff");
font-style: normal;
font-weight: 400;
font-display: swap;
}
2. Font repositories
A font repository provides files or a stylesheet you can use to load a typeface on your website.
Google Fonts is one example. It offers:
- Cost: A catalog of fonts available at no charge under their respective licenses.
- Convenience: Tools for browsing typefaces and choosing weights and styles.
- Delivery: A hosted stylesheet and font files served over a CDN. You can also self-host when the license permits it.
2.1. How to use Google Fonts
Use these steps to choose and add a family from Google Fonts:
- Open Google Fonts in your browser.
- Browse the available families. Filter by category, style, or weight, or search for a typeface by name.
- Choose a family and open its specimen page.
- Choose the styles and weights you need. Check that the selected family covers the characters your site uses.
- Open the family’s embed options and copy the stylesheet code.
- Use a
<link>in HTML or anin CSS. The examples below show both methods.
import

You can also use Google’s scalable icons. See the lesson on Material Icons for instructions and examples.
Proposed exercise
Add Tangerine to a new project. Find the family on Google Fonts and choose either the HTML link or CSS import method.
Using
import
Add this rule before other style rules in your CSS file:
@import url('https://fonts.googleapis.com/css2?family=Tangerine&display=swap');
Then use font-family: 'Tangerine', cursive; on the elements you want to style.
Using <link>
Add this link in the HTML document’s <head>:
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/c
Use font-family: 'Tangerine', cursive; in your stylesheet.
Compare the code and result in CodePen:
3. Tools
3.1. Online font libraries
| Name | URL |
| Font Squirrel | fontsquirrel.com |
| Da Font | dafont.com |
| Google Fonts | google.com/fonts |
3.2. Online font converters
| Name | URL |
| Font Squirrel converter | fontsquirrel.com/tools/webfont-generator |
| Online Font Converter | onlinefontconverter.com |
| Files conversion | files-conversion.com/font-converter.php |
| Font converter | fontconverter.org |
3.3. Icon libraries
| Name | URL |
| Flaticon | flaticon.com |
| Linecons | designmodo.com/linecons-free/ |
| Flaticons.co | flaticons.co |
| Flaticons.net | flaticons.net |
| Iconshock | iconshock.com/flat-icons/ |
Proposed exercise
Find an icon on Font Awesome and add it to a new project. Give any icon-only control an accessible name.