CSS font-family
Published Jun 29, 2021Updated Sep 21, 2023
Contribute to Docs
Specify the typeface in a rule set.
Syntax
font-family: <font-family-name>;
Where <font-family-name> can be the following:
Roboto"Open Sans"- or can be selected from Google Fonts that suites you.
If a font family name is not available, browsers will display their default font. When using a multi-word font name, wrap them in quotes.
Example 1
Set the h1 tag to Roboto:
h1 {font-family: Roboto;}
Example 2
Set the p tag to Roboto and Noto Sans:
p {/* Font stack */font-family: Roboto, 'Noto Sans';}
If the primary font-family is not supported it will defer to the fallback font. Multiple fonts can be chained to create a font stack.
Note: To use multiple languages in the same tag, like ‘你好 World!’, the declared font may not be supported for the Chinese language. In that case, the Chinese text will be shown in the default font.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours