If you wish to avoid utilizing the default fonts available in HTML, Google Fonts offer an alternative solution. With over 1000 fonts available, Google Fonts are freely accessible for use, providing a diverse selection to choose from.
Simply insert a specific style sheet link within the <head>
section of your HTML document, and subsequently make references to the desired font within your CSS code.
Example
In this case, our intention is to utilize a font called “Sofia” sourced from Google Fonts.
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Sofia”> <style> body { font-family: “Sofia”, sans-serif; } </style> </head> |
Result:
Example
In this instance, our objective is to incorporate a font named “Trirong” sourced from Google Fonts.
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Trirong”> <style> body { font-family: “Trirong”, serif; } </style> </head> |
Result:
Example
In this context, we aim to apply a font named “Audiowide” sourced from Google Fonts.
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Audiowide”> <style> body { font-family: “Audiowide”, sans-serif; } </style> </head> |
Result:
Reminder: When defining a font in CSS, it’s essential to include at least one fallback font to mitigate unforeseen issues. Therefore, ensure to append a generic font family, such as serif or sans-serif, to the end of the font list. |
To employ multiple Google fonts, simply delineate the font names by using a pipe character (|), as illustrated below:
Example
Request multiple fonts:
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Audiowide|Sofia|Trirong”> <style> h1.a {font-family: “Audiowide”, sans-serif;} h1.b {font-family: “Sofia”, sans-serif;} h1.c {font-family: “Trirong”, serif;} </style> </head> |
Result:
Please be mindful that requesting multiple fonts could potentially slow down the loading time of your web pages. |
Certainly, you have the freedom to customize Google Fonts to your preferences using CSS!
Example
Style the “Sofia” font:
<head> |
Result:
Google has introduced various font effects that you can utilize.
Start by incorporating effect=effectname into the Google API, and then assign a unique class name to the element intended for the special effect. Ensure that the class name commences with font-effect- and concludes with the effectname.
Example
Add the fire effect to the “Sofia” font:
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Sofia&effect=fire”> <style> body { font-family: “Sofia”, sans-serif; font-size: 30px; } </style> </head> <body> <h1 class=”font-effect-fire”>Sofia on Fire</h1> </body> |
Result:
To request multiple font effects, simply separate the effect names using a pipe character (|), as demonstrated below:
Example
Add multiple effects to the “Sofia” font:
<head> <link rel=”stylesheet” href=”https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple”> <style> body { font-family: “Sofia”, sans-serif; font-size: 30px; } </style> </head> <body> <h1 class=”font-effect-neon”>Neon Effect</h1> <h1 class=”font-effect-outline”>Outline Effect</h1> <h1 class=”font-effect-emboss”>Emboss Effect</h1> <h1 class=”font-effect-shadow-multiple”>Multiple Shadow Effect</h1> </body> |
Result: