CSS | @font-face rule
In the CSS @font-face rule is used to associate a font name that can be used in a style sheet. A font-family descriptor is used within the rule to name the font and an src descriptor is associated with an external font name. This can be used with downloadable fonts. This CSS @font-face rule can contain more than one properties (max 24).
Syntax:
@font-face { font-family: fontname; src: url(fontfile path);
font-stretch: font-stretch Property; font-weight: font-weight Property;
font-style: font-style Property; }
Parameter: The @font-face rule accepts four parameter as mentioned above and described below:
- font-family: It is used to hold the fonat-family.
- src: It is used to hold the src file path(url)
- font-stretch: It is used to set the text wider or narrower.
- font-weight: It is used to hold the font-weight.
- font-style: It is used to hold the font-weight.
Few hosted font services: This services will provide you various types of fonts.
- Fonts.com
- Google Fonts
- Typotheque
- Typography
There are so many others are also available some of them are paid and some og them are free.
Example 1:
<!DOCTYPE html> <html> <head> <title>CSS @font-face rule</title> <style> @font-face { font-family: myFirstFont; src: url(sansation_light.woff); } @font-face { font-family: myFirstFont; src: url(sansation_bold.woff); font-weight: bold; } div { font-family: myFirstFont; } h1 { color: green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <div>A Computer Sciecne Portal fo Geeks</div> </center> </body> </html> |
Output:

Example 2:
<!DOCTYPE html> <html lang="en"> <head> <title>CSS @font-face rule</title> <style type="text/css"> @font-face { font-family: "OpenSans"; src: url("/examples/fonts/OpenSans-Regular.eot"); src: url("/examples/fonts/OpenSans-Regular.ttf") format("truetype"); font-stretch: normal; font-weight: normal; font-style: normal; } @font-face { font-family: "OpenSansBold"; src: url("/examples/fonts/OpenSans-Bold.eot"); src: url("/examples/fonts/OpenSans-Bold.ttf") format("truetype"); font-stretch: normal; font-weight: normal; font-style: normal; } /* Specify the OpenSans bold font */ h1 { font-family: "OpenSansBold", Arial, sans-serif; color:green; } p { font-family: "OpenSans", Arial, sans-serif; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <p>A Computer Science Portal for Geeks</p> </center> </body> </html> |
Output:

Note: There are five Font format those are: TTF/OTF, WOFF, WOFF2, SVG and EOT.
Supported Browsers: The browsers supported by CSS | @font-face rule are listed below:
- Google Chrome (TTF/OTF, WOFF, WOFF2 and SVG)
- Interenet Explorer (TTF/OTF, WOFF and EOT)
- Firefox (TTF/OTF, WOFF and WOFF2)
- Safari TTF/OTF, WOFF and SVG)
- Opera TTF/OTF, WOFF, WOFF2 and SVG
Recommended Posts:
- What does the CSS rule “clear: both” do?
- CSS | @media Rule
- CSS | @import rule
- CSS | @charset Rule
- CSS | @page rule
- CSS | @keyframes Rule
- CSS | column-rule Property
- CSS | column-rule-color Property
- CSS | column-rule-style Property
- CSS | column-rule-width Property
- 10 Node.js Framework to be used in 2019
- Difference between VueJS and AngularJS
- How to check if a scrollbar is visible?
- How to change an element color based on value of the color picker value using onclick?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



