Skip to content
\n

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
\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.

\n

I 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
\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
\n

I do not see the font being used in the generated site and I do see the following errors from the developer console:

\n
book/:1 Failed to decode downloaded font: https://fonts.googleapis.com/css2?family=Lancelot&display=swap\n\nOTS parsing error: invalid sfntVersion: 791289964\n
\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

#7834

\n

But I am hoping for something simpler

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hi @Aazih,
\nthis is incorrect:

\n
src: url(\"https://fonts.googleapis.com/css2?family=Lancelot&display=swap\");
\n

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

\n

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

\n
--md-text-font: \"<font>\"; 
\n

Ref:

\n\n

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 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 😉 :

\n","upvoteCount":1,"url":"https://github.com/squidfunk/mkdocs-material/discussions/8276#discussioncomment-13553962"}}}

Unable to successfully use a third font #8276

Answered by kamilkrzyskow
Aazih asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Aazih,
this 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.
You 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.
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

--md-text-font: "<font>"; 

Ref:

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@kamilkrzyskow
Comment options

@Aazih
Comment options

@kamilkrzyskow
Comment options

@Aazih
Comment options

@kamilkrzyskow
Comment options

Answer selected by Aazih
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants