aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-08-18 13:45:31 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-08-18 20:43:44 +0200
commit72efde6922c3110d09dd13e8988be387d3cb2a69 (patch)
tree21f39fa7109f36151abdff07c06495659a0f056d
parentchore(deps); bump dependencies (diff)
downloadblog-72efde6922c3110d09dd13e8988be387d3cb2a69.tar.gz
blog-72efde6922c3110d09dd13e8988be387d3cb2a69.tar.zst
blog-72efde6922c3110d09dd13e8988be387d3cb2a69.zip
Blog post readability
Also use .md file extension to enable spellchecking.
-rw-r--r--.prettierignore1
-rw-r--r--blog/2024-04-05/variable-css-font-features.md (renamed from blog/2024-04-05/variable-css-font-features.mdx)28
2 files changed, 14 insertions, 15 deletions
diff --git a/.prettierignore b/.prettierignore
index 4f92f13..59243de 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -12,3 +12,4 @@ node_modules/
12 12
13# See https://github.com/orgs/mdx-js/discussions/2067 13# See https://github.com/orgs/mdx-js/discussions/2067
14*.mdx 14*.mdx
15*.md
diff --git a/blog/2024-04-05/variable-css-font-features.mdx b/blog/2024-04-05/variable-css-font-features.md
index 184aa69..ce7f379 100644
--- a/blog/2024-04-05/variable-css-font-features.mdx
+++ b/blog/2024-04-05/variable-css-font-features.md
@@ -6,8 +6,8 @@ title: Variable CSS font features
6description: How to set up and use font variation axes in CSS, create a custom subset with OpenType font features, and make the font features switch based on variation settings automatically. 6description: How to set up and use font variation axes in CSS, create a custom subset with OpenType font features, and make the font features switch based on variation settings automatically.
7tags: 7tags:
8 - css 8 - css
9 - design
10 - frontend 9 - frontend
10 - docusaurus
11authors: kris 11authors: kris
12--- 12---
13 13
@@ -53,9 +53,9 @@ Recursive defines **5 variation axes:**
53 We don't have to do anything special to use this axis, because it is mapped to the `font-weight` CSS property by browsers automatically. 53 We don't have to do anything special to use this axis, because it is mapped to the `font-weight` CSS property by browsers automatically.
54- The `"slnt"` axis controls the slant of the font[^oblique]. 54- The `"slnt"` axis controls the slant of the font[^oblique].
55 I couldn't get the browser to map this to `font-style: italic` properly, so we'll have to take care of this axis manually[^italic]. 55 I couldn't get the browser to map this to `font-style: italic` properly, so we'll have to take care of this axis manually[^italic].
56- The `"MONO"` axis blends the font between proportional and monospaced. Browsers don't support this out of the box. 56- The `"MONO"` axis blends the font between proportional and monospaced. For values greater than `0.5`, monospace-specific letterforms kick in for some characters. Browsers don't support this axis out of the box.
57- The `"CASL"` axis blends the font between serious and casual. Browsers don't support this out of the box either. 57- The `"CASL"` axis blends the font between serious and casual. Browsers don't support this axis out of the box either.
58- The `"CRSV"` axis is the most interesting. At 0, you get normal letters, while at 1 you get <span style={/** @type {import('react').CSSProperties} */ ({ '--crsv': 1 })}>cursive</span> ones. At 0.5, you get **automatic switching:** normal letters for upright type and italic ones for text slanted more than 14 degrees[^slant]. 58- The `"CRSV"` axis is the most interesting. At `0`, you get normal letters, while at `1` you get cursive ones. At `0.5`, you get **automatic switching:** normal letters for upright type and italic ones for text slanted more than 14 degrees[^slant].
59 59
60[^oblique]: It goes in the direction opposite to the [`font-style: oblique`][font-style-prop] property. 60[^oblique]: It goes in the direction opposite to the [`font-style: oblique`][font-style-prop] property.
61 61
@@ -139,7 +139,7 @@ Docusarus shifts the sizes of headings up by one for text generated from Markdow
139 139
140Some letters now look a little awkward: the two-story letter '<span style={/** @type {import('react').CSSProperties} */ ({ '--casl': 0.01 })}>g</span>' can be hard to read in small body text. Also, the '@' gets squished horizontally in monospace text way too much. There's even a [GitHub issue](https://github.com/arrowtype/recursive/issues/509) for that in the Recursive repository! 140Some letters now look a little awkward: the two-story letter '<span style={/** @type {import('react').CSSProperties} */ ({ '--casl': 0.01 })}>g</span>' can be hard to read in small body text. Also, the '@' gets squished horizontally in monospace text way too much. There's even a [GitHub issue](https://github.com/arrowtype/recursive/issues/509) for that in the Recursive repository!
141 141
142Luckily, Recursive has a number of **OpenType font features** that can change the shape of the characters. You can take a look at them in Recursive's [README page](https://github.com/arrowtype/recursive?tab=readme-ov-file#opentype-features). I also reproduced the image below, but it's a bit large, so you'll need to click to reveal it. 142Handily for us, Recursive has a number of **OpenType font features** that can change the shape of the characters. You can take a look at them in Recursive's [README page](https://github.com/arrowtype/recursive?tab=readme-ov-file#opentype-features). I also reproduced the image below, but it's a bit large, so you'll need to click to reveal it.
143 143
144import recursiveFeatures from './recursive-v1.064-opentype_features.png?placeholder=true&sizes[]=360&sizes[]=559&sizes[]=930&sizes[]=1504&rl'; 144import recursiveFeatures from './recursive-v1.064-opentype_features.png?placeholder=true&sizes[]=360&sizes[]=559&sizes[]=930&sizes[]=1504&rl';
145import recursiveFeaturesOriginal from './recursive-v1.064-opentype_features.png?url'; 145import recursiveFeaturesOriginal from './recursive-v1.064-opentype_features.png?url';
@@ -207,7 +207,7 @@ Recursive doesn't declare any RFN, so we can keep referring to our custom subset
207 207
208::: 208:::
209 209
210Now we can include our custom subset in our CSS: 210We can now include our custom subset in our CSS:
211 211
212```css 212```css
213@font-face { 213@font-face {
@@ -222,7 +222,7 @@ Now we can include our custom subset in our CSS:
222} 222}
223``` 223```
224 224
225For this website, I actually wrote a [small Python script](https://git.marussy.com/blog/tree/scripts/subset_fonts.py) to generate the font subsets. I also use a [template](https://git.marussy.com/blog/tree/scripts/fonts.css.jinja2) for generating the corresponding CSS. Both files can be found in the [Git repository](https://git.marussy.com/blog/) of this website with <MITLicenseLink />. 225For this website, I actually wrote a [small Python script](https://git.marussy.com/blog/tree/scripts/subset_fonts.py) to generate the font subsets. I also use a [template](https://git.marussy.com/blog/tree/scripts/fonts.css.jinja2) for generating the corresponding CSS. Both files can be found in the [Git repository](https://git.marussy.com/blog/) of this website under <MITLicenseLink />.
226 226
227### Selecting features 227### Selecting features
228 228
@@ -230,11 +230,11 @@ I decided to take the features `ss02`, `ss05`, `ss10`, `ss12`, and `titl` for a
230 230
231<VariableAxisSettingsWithFontFeaturesToggle /> 231<VariableAxisSettingsWithFontFeaturesToggle />
232 232
233After a bit of experimentation, I decided to use the features in the following way: 233After a bit of experimentation, I ended up using the features as follows:
234 234
235* The simplified look of the letter 'g' with the `ss02` feature is suitable for body text, but I prefer the two-story '<span style={/** @type {import('react').CSSProperties} */ ({'--casl': 0.01})}>g</span>' for headings. 235* The simplified look of the letter 'g' with the `ss02` feature is suitable for body text, but I prefer the two-story '<span style={/** @type {import('react').CSSProperties} */ ({'--casl': 0.01})}>g</span>' for headings.
236* The `ss05` feature does nothing for proportional text, but makes the letter `l` more similar to that in my favorite coding font, [Fira Code](https://github.com/tonsky/FiraCode) in monospace text. We can safely set this for all text. 236* The `ss05` feature does nothing for proportional text, but makes the letter `l` more similar to that in my favorite coding font, [Fira Code](https://github.com/tonsky/FiraCode) in monospace text. We can safely set this for all text.
237* The `ss10` (dotted zero) and `ss12` (simplified `@`) features affect proportional text, too, so we shouldn't set them for all text. But, for me, they make text more readable once the monospace letter shapes kick in after `--mono: 0.5`. 237* The `ss10` (dotted zero) and `ss12` (simplified `@`) features affect proportional text, too, so we shouldn't set them for all text. However, they do make text more readable for me once the monospace letterforms kick in after `--mono: 0.5`.
238* The alternative '<span style={/** @type {import('react').CSSProperties} */ ({'--casl': 0.01})}>Q</span>' with `titl` is nice for headings, but I prefer the default 'Q' with descender for body text. 238* The alternative '<span style={/** @type {import('react').CSSProperties} */ ({'--casl': 0.01})}>Q</span>' with `titl` is nice for headings, but I prefer the default 'Q' with descender for body text.
239 239
240### Automatic feature switching 240### Automatic feature switching
@@ -266,13 +266,13 @@ In short, we want something like
266``` 266```
267 267
268We will use [`calc()`](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) to determine the values of [`font-feature-settings`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-feature-settings). 268We will use [`calc()`](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) to determine the values of [`font-feature-settings`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-feature-settings).
269However, looking through the list of [CSS math function](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Functions#math_functions), we find few options for creating [discontinuous expressions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Functions#stepped_value_functions). The [`round()`][round] function sounds promising, but it ~isn't~ wasnt't supported by Chromium until May&nbsp;2024. 269However, looking through the list of [CSS math functions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Functions#math_functions), we find few options for creating [discontinuous expressions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Functions#stepped_value_functions). The [`round()`][round] function sounds promising, but it ~isn't~ wasn't supported by Chromium until May&nbsp;2024.
270 270
271[round]: https://developer.mozilla.org/en-US/docs/Web/CSS/round 271[round]: https://developer.mozilla.org/en-US/docs/Web/CSS/round
272 272
273:::info 273:::info
274 274
275Because browsers now support [`round()`][round] near universally, I added an [update](#the-round-function) to this blog post on August&nbsp;16, 2024 below. 275Since browsers now support [`round()`][round] near universally, I added an [update](#the-round-function) to this blog post detailing its use below on August&nbsp;16, 2024.
276 276
277::: 277:::
278 278
@@ -326,10 +326,8 @@ You can set the variables axes below with up to 0.01 precision:
326 326
327### The `round()` function 327### The `round()` function
328 328
329 329Since May&nbsp;2024, the [`round()`][round] CSS math function became widely available in browsers.
330 330This allows use to write the font feature computations is a more straightforward way, and also avoids the problem of variation axis values like `0.0005` or `0.5005`.
331Since May&nbsp;2024, the [`round()`][round] CSS math function became widely avaiable in browsers.
332This allows use to write the font feature computeations is a more straightforward way, and also avoids the problem of variation axis values like `0.0005` or `0.5005`.
333 331
334The updated code snippet looks like this: 332The updated code snippet looks like this:
335 333