and update extra.css to override the font-family in the header and tabs.
\n/* Header */\n.md-header {\n font-family: \"Playfair\";\n}\n\n.md-tabs {\n font-family: \"PlayFair\";\n}\n
That worked as expected. But now I want to use another font and I'm having a tough time with the instructions on how to do so.
\nI added the following font face with the following code in extra.css (I retrieved the url from the google fonts site):
\n@font-face {\n font-family: \"Lancelot\";\n src: url(\"https://fonts.googleapis.com/css2?family=Lancelot&display=swap\");\n}\n\n
and then attempted to use it in the same file:
\n.bookfancy {\n text-align: center;\n font-size: 1.5rem;\n font-family: \"Lancelot\";\n}\n
I do not see the font being used in the generated site and I do see the following errors from the developer console:
\nbook/:1 Failed to decode downloaded font: https://fonts.googleapis.com/css2?family=Lancelot&display=swap\n\nOTS parsing error: invalid sfntVersion: 791289964\n
Hoping there is something obvious I am missing. I do see other discussion on how to make deeper modifications to enable this here:
\n\nBut I am hoping for something simpler
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Hi @Aazih,
\nthis is incorrect:
src: url(\"https://fonts.googleapis.com/css2?family=Lancelot&display=swap\");
as the URL leads to a text file with CSS font rules, not to a font, so download the text file and include it in your CSS.
\nYou could also use @import
, but this increases the amount of requests, so I would keep it local in your extra.css
Also another possible nitpick I would have is you should not use font-family
unless you're 100% sure that's what you want.
\nInstead, redefine the font variable as described in the docs, you can scope it to the :.md-header
etc. selectors, doesn't have to be :root
\nRead the comment below for a fixed statement
--md-text-font: \"<font>\";
Ref:
\nSide note, in the past, at Nype, I did have to deal with some issues concerning \"invisible text during load\", and the issue there was a lack of defined swap
mode for the custom font, but I guess the fonts from Google do come with it like the example above, but worth keeping a lookout for this issue 😉 :
-
Hey all, I'm using material for mkdocs on my author site and I've used up the two out of the box fonts that can be configured in mkdocs.yml:
and update extra.css to override the font-family in the header and tabs.
That worked as expected. But now I want to use another font and I'm having a tough time with the instructions on how to do so. I added the following font face with the following code in extra.css (I retrieved the url from the google fonts site):
and then attempted to use it in the same file:
I do not see the font being used in the generated site and I do see the following errors from the developer console:
Hoping there is something obvious I am missing. I do see other discussion on how to make deeper modifications to enable this here: But I am hoping for something simpler |
Beta Was this translation helpful? Give feedback.
-
Hi @Aazih, src: url("https://fonts.googleapis.com/css2?family=Lancelot&display=swap"); as the URL leads to a text file with CSS font rules, not to a font, so download the text file and include it in your CSS.
--md-text-font: "<font>"; Ref:
Side note, in the past, at Nype, I did have to deal with some issues concerning "invisible text during load", and the issue there was a lack of defined |
Beta Was this translation helpful? Give feedback.
Hi @Aazih,
this is incorrect:
as the URL leads to a text file with CSS font rules, not to a font, so download the text file and include it in your CSS.
You could also use
@import
, but this increases the amount of requests, so I would keep it local in yourextra.css
Also another possible nitpick I would have is you should not usefont-family
unless you're 100% sure that's what you want.Instead, redefine the font variable as described in the docs, you can scope it to the:.md-header
etc. selectors, doesn't have to be:root
Read the comment below for a fixed statement
Ref: