0

I am aware of woff2 detection and also the css based @supports variable font support detection, but is there a way to detect variable font support purely in Javascript?

1 Answer 1

1

This is the code I ended up am using now:

function variableFonts() {
    if ("CSS" in window === false || "supports" in CSS === false) {
        return false
    }

    return CSS.supports("(font-variation-settings: normal)")
}

First checking for the javascript CSS & supports API — which incidentally old browsers not supporting variable fonts also lack support for. Then, using CSS.supports to check if setting font variations is supported is trivial.

Sign up to request clarification or add additional context in comments.

4 Comments

do you know how to determine each manipulatable characteristic (or each value of font-variation-settings) that can be used on any given variable font?
@oldboy it's not possible with CSS; with something like opentype.js you could parse the font and find the axes and their extrama, but that is not very practical. in most cases the developer knows what those are.
that is fine for my use case. i will google opentype.js.org?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.