skip to Main Content

We’re working on a html reader, and the content could be any html. We want to set a default font family if the font set in the content is not available.

For example,

<body style="font-family: A"><div style="font-family: B"></div></body>

If font B is not available, I prefer to use A to render. But we’re not able to change the style on div since it’s user content.

Or if it’s possible to change browser’s default fallback font?

2

Answers


  1. <body style="font-family: A"><div style="font-family: inherit; font-family: B;"></div></body>
    

    You can set the CSS property as above, if B is valid, the browser will apply the last one, if not, the browser will ignore the invalid property.

    Login or Signup to reply.
  2. That should be the default behavior. Font is calculated in this order getting the first availabe:

    1. The desired font.
    2. The earliest available one from the font-fallbacks (font-family: "Times New Roman", Times, serif;).
    3. The parent’s font or the closest parent’s font going up in the DOM tree getting the first available.
    4. The browser’s original font.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search