|
| 1 | +# `font-tech()` and `font-format()` `<supports-feature>` Extensions to CSS `@supports` |
| 2 | + |
| 3 | +## Authors |
| 4 | + |
| 5 | +* Dominik Röttsches, [@drott](drott@chromium.org) |
| 6 | +* Chris Lilley, [@svgeesus](chris@w3.org) |
| 7 | +* Jonathan Kew, [@jfkthame](jfkthame@gmail.com) |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +`font-tech()` and `font-format()` are extensions to the CSS Conditional Syntax |
| 12 | +which enable declarative syntax to use a different set of style rules depending |
| 13 | +on font format support, as well as programmatic feature detection of |
| 14 | +capabilities of the font stack. The latter covers a lack of functionality in web |
| 15 | +platform APIs, as most JS APIs and DOM functionality can be easily feature |
| 16 | +detected, but the abilities of the font stack could not be queried in that way |
| 17 | +so far. |
| 18 | + |
| 19 | +The proposed syntax was introduced following discussion in [TAG review |
| 20 | +#666](https://github.com/w3ctag/design-reviews/issues/666) on a previous syntax |
| 21 | +for the `src:` descriptor, and subsequent [resolutions in the CSS |
| 22 | +WG](https://github.com/w3c/csswg-drafts/issues/6520#issuecomment-947810568) to |
| 23 | +harmonize functionality between the `src:` descriptor parsing, and CSS |
| 24 | +Conditional behavior with respect to font feature detection. This had been a |
| 25 | +[request of the |
| 26 | +TAG](https://github.com/w3ctag/design-reviews/issues/666#issuecomment-901220221) |
| 27 | +review. |
| 28 | + |
| 29 | +## Use cases |
| 30 | + |
| 31 | +Background: The use cases listed below for are very similar to the `tech()` and |
| 32 | +`format()` extensions to parsing the `src:` line of the `@font-face` |
| 33 | +declaration, [see |
| 34 | +here](https://github.com/w3c/csswg-drafts/blob/main/css-fonts-4/src-explainer.md#use-cases). There, |
| 35 | +the focus is on resource loading on the `@font-face` level. Here the focus is |
| 36 | +more on more general feature detection outside the `src:` line for progressive |
| 37 | +enhancement through style rule or programmatic detection of feature support. |
| 38 | + |
| 39 | +1. I want to progressively enhance my site depending on font format capabilities |
| 40 | +of the UA. Examples: If OpenType variations are supported, I want to use a set |
| 41 | +of different style rules than when variations are not available. If color font |
| 42 | +support is available, I want to enhance my site with a color fonts plus style |
| 43 | +rules affecting other parts of my page. |
| 44 | + |
| 45 | +2. I want to know programmatically on the client side in my script code what |
| 46 | + level of font support is available. |
| 47 | + |
| 48 | +Where 2. is in line in line with the TAG design principles, which recommend |
| 49 | +[detectability of a feature](https://w3ctag.github.io/design-principles/#feature-detect). |
| 50 | + |
| 51 | +## Non-Goals |
| 52 | + |
| 53 | +This proposal is not intended as a server-side content negotiation solution. In |
| 54 | +many cases, third-party font providers currently choose based on User Agent |
| 55 | +which resources they deliver to clients at the time of the request to the |
| 56 | +included CSS. This is a different content negotiation mechanism from what is |
| 57 | +discussed in this proposal. |
| 58 | + |
| 59 | +## Proposed Syntax |
| 60 | + |
| 61 | +See "2. Extensions to the the `@supports` rule" in [CSS Conditionals |
| 62 | +5](https://www.w3.org/TR/css-conditional-5/#at-supports-ext). |
| 63 | + |
| 64 | +Examples: |
| 65 | + |
| 66 | +### Use Case 1 - Progressive Enhancement with color fonts |
| 67 | + |
| 68 | +``` |
| 69 | +.icons { |
| 70 | + font-family: monochromatic_icons; |
| 71 | +} |
| 72 | +
|
| 73 | +@supports font-tech(color-COLRv0) { |
| 74 | + .icons { |
| 75 | + font-family: colored_icons; |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +### Use Case 2 - Programmatic font support detection |
| 81 | + |
| 82 | +``` |
| 83 | +let vectorColorFontsAvailable = CSS.supports("font-tech(color-COLRv1)") || |
| 84 | + CSS.supports("font-tech(color-COLRv0)") || |
| 85 | + CSS.supports("font-tech(color-SVG)"); |
| 86 | +
|
| 87 | +``` |
0 commit comments