Font Directives
There are two types of typography classes, let's take a look at the types that are related to fonts.
Font Family
font-sans
font-serif
font-mono
theme: {
fontFamily: {
'sans': ['Helvetica', 'Arial', 'sans-serif'],
'display': ['Custom Font', 'Other Font'],
}
}
There are three diferent classes that you can use to specify what type of font you want to use in a project. The default styles
The font-sans
style is already applied to the page by default. By default, it will try to apply default system fonts for the styles, but you can override any of the default families by modifying the theme.fontFamily element in
tailwind.config.js`
You can even create a new font by adding one or more elements to that object.
Font Size
text-SIZ
- SIZ (font-size/line-height...in rems)
xs
.75/1sm
.875/1.25base
1/1.5lg
1.125/1.75xl
1.25/1.752xl
1.5/23xl
1.875/2.254xl
2.25/2.55xl
3/16xl
3.75/17xl
4.5/18xl
6/19xl
8/1
- SIZ (font-size/line-height...in rems)
Font size is handled through the text class and you add a size option here. this changes two parameters at the same time...font-size and line-height and you can see the values here.
The size and height is in rems so it's relative to the root size of the browser, which is usually 16 pixels.
Font Weight
font-WGT
- WGT (font-weight)
thin
100extralight
200light
300normal
400medium
500semibold
600bold
700extrabold
800black
900
- WGT (font-weight)
Font weight is handled through a series of named classes starting with the font keyword. I'm not sure I like this, I think it'd be better if they just made them numbers, but the names seem to make sense...just harder to remember.
If you're checking out the example, you'll notice that I loaded up a font here to make sure you could see the differences between the weights. Some fonts will only contain specific weights.
Font Style
italic
not-italic
(font-style)
There are only two styles you can modify under font style, wether an item is italic or not. not-italic
sets font-style to normal and it's obviously for changing things that would normally be bold, like headlines to not display as bold.
Font Smoothing
antialiased
subpixel-antialiased
There are two different types of font smoothing you can use. The default is called subpixel antialiased, if you want to switch it you simply add the aliased keyword and to override it, you use subpixel-antialiased. Note, these are pretty cutting edge classes and might not work in every browser.
Font Variant Numeric
normal-nums
ordinal
slashed-zero
lining-nums
oldstyle-nums
proportional-nums
tabular-nums
diagonal-fractions
stacked-fractions
Tailwind comes with some pretty esoteric classes for controlling advanced styles for fonts.
The important thing to know is that not all fonts support these features and as a matter of fact most Google Fonts, even ones that point to fonts that would normally support these features will work.
Apparently, it needs to be a font in the OpenType format, so just be careful.
Having said that, you can see what they do in the example, you can control how ordinal numbers are formatted, wether a 0 character has a internal line or dot as in this font that shows it's not an O.
The oldstyle numbers show better looking numbers that go below and above the baseline.
With tabular numbers, you force numbers to line up the numbers sort of like with mono-spaced fonts.
Finally, you have a couple of options for showing fractions. They look pretty good, specially diagonal fractions.
I think these styles look pretty good and will still look fine if the font doesn't support it, so it doesn't hurt to use them.