How to add fonts to a Vue app
In this tutorial, we will learn how to add fonts to a vue app which is created using the vue-cli.
Adding local fonts
-
Open the vue app in your favorite code editor.
-
Create a new folder called
fontsinside thesrcfolder. -
Download your favorite fonts and place them inside the
fontsfolder. -
Open your
App.vuefile and include the font by referencing the path.
<style>
@font-face {
font-family: "Merienda";
src: local("Merienda"), url(./fonts/Merienda/Merienda-Regular.ttf) format("truetype");}
</style>Here I added a Merienda font.
Now, we can use this font throughout our app like this.
<style>
.description{
font-family: "Merienda", Helvetica, Arial;
font-size: 20px;
}
</style>Adding Google fonts
We can also use google fonts (api) instead of local fonts by using @import rule.
<style>
@import url('https://fonts.googleapis.com/css2?family=Merienda&display=swap');
</style>

