I know this question is asked and answered before in the links below. I want to change the default font without having to add to every css.
Things I have tried:
For Ionic 2: Download the fonts from fonts.google.com and paste it in your assets folder. Now in your scss file do the following:
@font-face {
font-family: MyFont;
src: url("../assets/fonts/Lato-Regular.ttf");
}
body, span, button, h1, h2, h3, h4, h5, h6, p, ion-item, ion-title {
font-family: 'MyFont' !important;
}
The correct solution for Ionic 2 should be to change the $font-family-base
variable and its friends. That's the way Ionic is made to do it. It gives you more control (like having different fonts per platform), and it avoids the !important
keyword, which is always a good thing.
Using Ionic 3.3, go to your variables.scss
and find the section "Shared variables". Add these lines:
$font-family-base: 'MyFont';
$font-family-ios-base: 'MyFont';
$font-family-md-base: 'MyFont';
$font-family-wp-base: 'MyFont';
You don't want to replace the icon font by the way, so you should use the CSS3 not() property
For example, in app.scss :
@import url(https://fonts.googleapis.com/css?family=Varela+Round);
*:not(ion-icon) {
font-family: 'Varela Round', sans-serif!important;
}
You can simply include your icons as svg
format.
Here's a list with all the latest ionicons
: https://github.com/Orlandster1998/ionicons-svg
Import all the font files
in to your app.
Example:
@font-face {
font-family: 'Lato-Light';
src: url('../fonts/Lato-Light.eot') format('embedded-opentype'), url('../fonts/Lato-Light.woff') format('woff'), url('../fonts/Lato-Light.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
If you want this font in entire app ,Just give like this
* {
font-family: 'Lato-Light' !important;
}
If you have any doubt.Please let me know.Thanks
There are global variables that are shared across components. --ion-font-family
is one of them.
Add this in property under :root
in variables.scss
:
:root {
--ion-font-family: 'MyFont';
}
Ionic 4 Docs: Advanced Theming Documentation