Using Google fonts under MediaWiki

From Not a Wiki
Revision as of 12:15, 12 June 2023 by Fifo F (talk | contribs)

Did you know that you can use Google fonts under MediaWiki? It’s not too hard, just do the following:

  1. Go to https://fonts.google.com and choose the typeface of your choice.
  2. Choose the Select option next to the fonts. I went with the most common styles (regular, italic, bold, bold italic).
  3. Click on the View selected families icon on the top right.
  4. Choose the @import radio button and copy the import line between the <style></style> tags.
  5. Go to the Appearance tab in your preferences page.
  6. Click on the Custom CSS link, either next to the skin you want to style, or below “Shared CSS/JavaScript for all skins”.
  7. Paste the @import line you copied in step 4 into the editor.
  8. Enter body { font-family: <FONT NAME HERE>; }, replacing <FONT NAME HERE> with the name of the font you chose, i.e. Lato.
  9. Choose the Publish changes option. If you don’t see the changes, refresh your browser’s cache (click for instructions).
  10. Enjoy!

Here’s an example of the resulting CSS:

Special:MyPage/common.css
@import url('https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap');

body { font-family: Lato; }

By the way, it works on Wikipedia, too.