svg @font-face works in svg but not when included in a page svg @font-face works in svg but not when included in a page xml xml

svg @font-face works in svg but not when included in a page


According to this answer to a related question, embedded svg images have to be standalone images. As mentioned in the comments above, one can make an svg 'standalone' by embedding all external assets into it. So in my case, i'd have to do either one of these things:

  1. embed the fonts using a data uri: src: url("data:application/font-woff;base64,<base64 encoded font here"),
  2. embed the fonts as svg glyphs, which I had already ruled out because the lack of firefox support
  3. turn the fonts into paths in my editing software (e.g. expand path in adobe illustrator).

Not one of these methods seemed satisfactory, since I really like to keep the svg files as lightweight as possible.

Another solution to circumvene the whole problem is to use a html object tag instead of an img tag. This way the svg is allowed to be more than a standalone image and it can use the full range of xml inclusion methods to include other assets. This was pointed out already in the aforementioned question.

I chose to use the object method of embedding the svg. I'll update this answer if I find out there is something fundamentally wrong with doing this instead of using a proper img element.