You can view RSS feeds from my friends and colleagues.
Introducing TODS, an open source typography and opentype default stylesheet. One of the great things about going to conferences is the way it can spark an idea and kick start something. This project was initiated following a conversation with Roel Nieskens (of Wakamai Fondue fame) at CSS Day, where he demonstrated his Mildly Opinionated Prose Styles (MOPS).
The idea is to set sensible typographic defaults for use on prose (a column of text), making particular use of the font features provided by OpenType. The main principle is that it can be used as starting point for all projects, so doesn’t include design-specific aspects such as font choice, type scale or layout (including how you might like to set the line-length).
Within the styles is mildly opinionated best practice, which will help set suitable styles should you forget. This means you can also use the style sheet as a checklist, even if you don't want to implement it as-is.
TODS uses OpenType features extensively and variable font axes where available. It makes full use of the cascade to set sensible defaults high up, with overrides applied further down. It also contains some handy utility classes.
You can apply the TODS.css
stylesheet in its entirety, as its full functionality relies on progressive enhancement within both browsers and fonts. Anything that is not supported will safely be ignored. The only possible exceptions to this are sub/superscripts and application of a grade axis in dark mode, as these are font-specific and could behave unexpectedly depending on the capability of the font.
In order to preview some of the TODS features, you can check out the preview page tods.html
and toggle TODS.css
on and off. (This needs more work as the text is a bit of a mish-mash of examples and instructions, and it's missing some of the utility classes and dark mode. But that’s what open source is for… feel free to fork, improve and add back into the repo.)
TODS.css
stylesheetYou can download a latest version of the stylesheet from the TODS Github repo (meaning some of the code may have changed a bit).
Table of contents:
Based on Andy Bell’s more modern CSS reset. Only the typographic rules in his reset are used here. You might like to apply the other rules too.
Prevent font size inflation when rotating from portrait to landscape. The best explainer for this is by Kilian. He also explains why we still need those ugly prefixes too.
Remove default margins in favour of better control in authored CSS.
Inherit fonts for inputs and buttons.
Use modern variable font syntax so that only supporting browsers get the variable font. Others will get generic fallbacks.
Include full possible weight range to avoid unintended synthesis of variable fonts with a weight axis. Same applies to stretch range for variable fonts with a width axis.
For main body fonts, use fallback
for how the browser should behave while the webfont is loading. This gives the font an extremely small block period and a short swap period, providing the best chance for text to render.
For italics use swap
for an extremely small block period and an infinite swap period. This means italics can be synthesised and swapped in once loaded.
When monospace fonts are used inline with text fonts, they often need tweaking to appear balanced in terms of size. Use size-adjust
to do this without affecting reported font size and associated units such as em
.
Set some sensible defaults that can be used throughout the whole web page. Override these where you need to through the magic of the cascade.
Set a nice legible line height that gets inherited. The font-
properties are set to default CSS and OpenType settings, however they are still worth setting specifically just in case.
Set shorter line heights on interactive elements. We’ll do the same for headings later on.
Reinstate block margins we removed in the reset section. We’re setting consistent spacing based on font size on primary elements within ‘flow’ contexts. The entire ‘prose’ area is a flow context, but so might other parts of the page. For more details on the ‘flow’ utility see Andy Bell’s favourite three lines of CSS.
Rule says that every direct sibling child element of .flow
has margin-block-start
added to it. The >
combinator is added to prevent margins being added recursively.
Set generous spacing between primary block elements (in this case it’s the same as the line height). You could also choose a value from a fluid spacing scale, if you are going down the fluid typography route (recommended, but your milage may vary). See Utopia.fyi for more details and a fluid type tool.
Helper utilities matching on/off Opentype layout features available through high level CSS properties.
Other Opentype features can have multiple glyphs, accessible via an index number defined in the font – these will be explained in documentation that came with your font. These vary between fonts, so you need to set up a new @font-font-features
rule for each different font, ensuring the font name matches that of the font family. You then give each feature a custom name such as ‘swoopy’. Note that stylesets can be combined, which is why swoopy
has a space-separated list of indices 7 16
.
Handy utility classes showing how to access the font feature values you set up earlier using the font-variant-alternates
property.
Set custom properties for OpenType features only available through low level font-feature-settings
. We need this approach because font-feature-settings
does not inherit in the same way as font-variant
. See Roel’s write-up, including how to apply the same methodology to custom variable font axes.
Some utilities to help ensure best typographic practice.
When centring text you’ll almost always want the text to be ‘balanced’, meaning roughly the same number of characters on each line.
When fully capitalising text, ensure punctuation designed to be used within caps is turned on where available, using the Opentype ‘case’ feature.
Transform both upper and lowercase letters to small caps, and use old style-numerals within runs of small caps so they match size-wise.
Assign a .prose
class to your running text, that is to say an entire piece of prose such as the full text of an article or blog post.
Firstly we get ourselves better widow/orphan control, aiming for blocks of text to not end with a line containing a word on its own. Also we use proportional old-style numerals in running text.
Also adjust the size of fallback fonts to match the webfont to maintain legibility with fallback fonts and reduce visible reflowing. The font-size-adjust
number is the aspect ratio of the webfont, which you can calculate using this tool.
Apply a different adjustment to elements which are typically emboldened by default, as bold weights often have a different aspect ratio – check for the different weights you may be using, including numeric semi-bolds (eg. 650). Headings are dealt with separately as the aspect ratio may be affected by optical sizing.
Set shorter line heights on your main headings. Set an aspect ratio for fallback fonts – check for different weights of headings. Use lining numerals in headings, especially when using Title Case.
Turn on fancy ligatures for main headings. If the font has an optical sizing axis, you might need to adjust the aspect ratio accordingly.
When setting a heading in all caps, use titling capitals which are specially designed for setting caps at larger sizes.
Use proper super- and subscript characters. Apply to sub
and sup
elements as well as utility classes for when semantic sub/superscripts are not required.
If font-variant-position is not specified, browsers will synthesise sub/superscripts, so we need to manually turn off the synthesis. This is the only way to use a font’s proper sub/sup glyphs, however it’s only safe to use this if you know your font has glyphs for all the characters you are sub/superscripting. If the font lacks those characters (most only have sub/superscript numbers, not letters), then only Firefox (correctly) synthesises sup and sub – all other browsers will display normal characters in the regular way as we turned the synthesis off.
For chemical formulae like H2O, use scientific inferiors instead of sub
.
Make sure all numbers in tables are lining tabular numerals, adding slashed zeroes for clarity. This could usefully apply where a time is specifically marked up, as well as in mathematics.
Use curly quotes and hang punctuation around blockquotes.
Set punctuation order for inline quotes. Quotes are language-specific, so set a lang
attribute on your HTML
element or send the language via a server header. Note the narrow non-breaking spaces encoded in the French example.
Insert quotes before and after q
element content.
Punctuation order for blockquotes, using a utility class to surround with double-quotes.
Append quotes to the first and last paragraphs in the blockquote.
Hang the punctuation outside of the blockquote. Firstly manually hang punctuation with a negative margin, then remove the manual intervention and use hanging-punctuation
if supported.
Turn on hyphenation for prose. Language is required in order for the browser to use the correct hyphenation dictionary.
Include additional refinements to hyphenation. Respectively, these stop short words being hyphenated, prevent ladders of hyphens, and reduce overall hyphenation a bit. Safari uses legacy properties to achieve some of the same effects, hence the ugly prefixes and slightly different syntax.
Turn hyphens off for monospace and headings.
Reduce grade if available to prevent bloom of inverted type.
Not all fonts have a grade (GRAD
) axis, and the grade number is font-specific. We’re using the customer property method because font-variation-settings
provides low-level control meaning each subsequent use of the property completely overrides prior use – the values are not inherited or combined, unlike with font-variant
for example.
There are probably better ways of doing some of these things, and the preview page is rather lacking at the moment. Please let me know on Github, or better still fork it, edit and resubmit.
I seem to have left pieces of myself scattered around the internet. This is my attempt to pull some of those pieces together.