anki
anki copied to clipboard
Explore font stacks
TL;DR
Currently using Verdana and DejaVu fonts. I might find more elegant fonts later. Would like to use a variable fonts? when better browser support. Here's the current way to declare multiple fonts properly.
- [x] Views correctly in Safari, Chrome
- [x] Requires override on
<body>for Anki apps.
Fonts are a bit of an arse to do cross-browser, cross-device, so if you want complete control and consistency use @font-face and save your .ttf font files to Anki's collection.media folder. Loading speed on iOS/Android may be an issue, so probably two custom fonts max.
You'll find variables/typography.less, partials/headings.less and themes/cards/... css files are the places to go to make your edits.
Good monospaced fonts
- [ ] Variable fonts?
- [ ] 5 monospaced fonts with ligatures — FIRA looks nice.
- [ ] Menlo is also another good option for a monospace font.
- [ ] Intel One Mono
Have already checked over these ...
- Beware that
@font-faceshould not be nested inside a selector or class.- Font calculations: Verdana is now our base font, but it's a bit too big by default. The global
font-size: 1rem;is inherited by, for example, headers so making the font smaller globally will fuck up everything else. For now I'm targeting just the card notes.[^1]
- [x] I think
system-uiwill use San Francisco on a Mac[^2] - [x]
ui-monospacehas poor support in browsers. - [x] ⚠️ Changing the default
--font-sizeremscrews everything else up. Increases size of all fonts, so be careful. Also,1remshould allow user-editedfont-sizeoptions in the browser. - [ ] Is setting the default
--font-sizewithrema bad idea? (this article sets up a percentage) - [x]
Does changing— It's safe to change elements withremon an element cascade? (like changingpaffects<code>even if that tag has it's ownremdeclared?rem. - [x]
Page speed time in iOS / Android apps?— Anki's loading speed seems fine so far. - [ ] Use base 64 encoding for fonts?
- [x] YES!!
Does the release deck import the custom font? - [x]
Edit thetypography.lessandheadings.less; orthemes/...files?- It seems to be "all of the above" here.
- [x] Using multiple
@font-facefonts? (seems to work on desktop)
Using default --system font stacks
Monospace (
ui-monospace) fails on Anki (but works in Safari). Manually writing'San Francisco Mono'or'SF Mono'is unpredictable in Safari and Anki. System font withsystem-uiseems to work on both.[^3]![]()
Left:
system-ui(SF Monoon MacOS); Right:DejaVu Sans MonoIt's a subtle difference (I actually prefer SF Mono), but a good starting point for custom themes. You can see the
Lhas a straight foot in SF Mono, but curve in DejaVu.
I feel the Print First CSS system-ui font stack is pretty good, but allowing custom fonts is a nice-to-have (and could help with code readability). However, after playing around with system-ui I'm now confused about the best route![^2]
- [x] Child themes — inheriting from
print-first-css(basic font stack) - [x] Fonts in Anki must be local files.
Verdana looks a bit shit at default --font-size
🤔 Anki custom font quirks
See the steps in the Anki documentation to add a custom font. The docs say to name your font
myfontbut on desktop I've named it the real font name and seems to work. Add the font to thecollection.mediafolder.
Naming the font properly
On Anki desktop, using the proper
font-family: 'Font Family Name';seems to work. However, here only the second image will work — use the font name only ('DejaVu Sans') and usefont-weightandfont-styleto specify the type of font (bold, italic, whatever).
⏳Card loading speed
You can use a hosted— Anki doesn't expose the<link ...>tag<header>, so usesrc: url(...)to load custom fonts from yourcollection.mediafolder.
There seems to be a potential issue with page load speed when using a custom font on Anki. I also can't find any useful information on using a URL for an @font-face with Anki.
[^1]: This is where things get tricky as both font-size and line-height is dependent on the font type, so if it's a bigger font by default, that's potentially going to fuck up all our hard work with the baseline. Also, it's a bit uncertain where to put those font-size changes and there's some who say that you should use global utility classes to do so (like Tailwind).
[^2]: I'm like 70% sure. It might just fallback to sans-serif. See below.
[^3]: Annoying quirks with Anki and Safari: 'San Francisco Pro', or 'SF Pro' aren't available on the Font Book app but they are available as a system default. In Safari, system-ui seems to pick 'SF Pro' as it's default, as does ui-monospace with 'SF Pro Mono' — ui-monospace has poor support with Anki and browsers! Manually typing in the font-family (using the name of the San Francisco font) doesn't seem to work on Safari anymore, nor with Anki (I think my previous font stack was falling back to sans-serif. monospace weirdness: selects 'Courier' on Safari and 'Menlo' on Anki 🤦♂️🤬 ... I "think".
Probably keep this simple with one for Mac/iOS and one for Android. Possibly allow a custom font if using base 64 encoding