My apologies if this is a very simple question, but how do you use google material icons without a
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
?
I would like my app to be able to display the icons even when the user does not have an internet connection
Kaloyan Stamatov method is the best. First go to https://fonts.googleapis.com/icon?family=Material+Icons. and copy the css file. the content look like this
paste the source of the font to the browser to download the woff2 file https://fonts.gstatic.com/s/materialicons/v37/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2 Then replace the file in the original source. You can rename it if you want No need to download 60MB file from github.Dead simple My code looks like this
}
while materialIcon.woff2 is the downloaded and replaced woff2 file.
Use material-design-icons-iconfont
I've created material-design-icons-iconfont to address these major issues:
npm install
- all irrelevant svg/xml/... files has been removedGoogle Fonts
CDNInstall via
npm
It depends on how you pack your web application (
webpack
/gulp
/bower
/...), you'll need to import the.css
/.scss
file (and might change the relative fonts path)Import Using SCSS
Import in one of your sass files
Later on, reference your desired icon
<i class="material-icons">
+ icon-id +</i>
Demo page
It comes with a light demo page to assist searching and copy-pasting fonts
I'm building for Angular 4/5 and often working offline and so the following worked for me. First install the NPM:
Then add the following to styles.css:
The question title asks how to host material icons offline but the body clarifies that the objective is to use the material icons offline (emphasis mine).
Using your own copy of the material icons files is a valid approach/implementation. Another, for those that can use a service worker is to let the service worker take care of it. That way you don't have the hassle of obtaining a copy and keeping it up to date.
For example, generate a service worker using Workbox, using the simplest approach of running workbox-cli and accepting the defaults, then append the following text to the generated service worker:
You can then check it was cached in Chrome using F12 > Application > Storage > IndexedDB and look for an entry with googleapis in the name.
If you use webpack project, after
you just need to
I have tried to compile everything that needs to be done for self-hosting icons in my answer. You need to follow these 4 simple steps.
Open the iconfont folder of the materialize repository
link- [https://github.com/google/material-design-icons/tree/master/iconfont]
Download these three icons files ->
MaterialIcons-Regular.woff2 - format('woff2')
MaterialIcons-Regular.woff - format('woff')
MaterialIcons-Regular.ttf - format('truetype');
Note- After Download you can rename it to whatever you like.
Now, go to your CSS and add this code
Note : The address provided in src:url(...) should be with respect to the 'CSS File' and not the index.html file. For example it can be src : url(../myicons/MaterialIcons-Regular.woff2)
Click here to see all the icons that can be used.