How do I override the base font size? #1611
Replies: 14 comments 25 replies
-
If you just want to change the root font size globally and have everything else scale automatically, do it by changing the font size on the html {
font-size: 20px
} |
Beta Was this translation helpful? Give feedback.
-
Tailwind seems to promote using rem for spacing. And being new to tailwind, I got the impression that this was in the interest of being able to automatically scale dimensions based on rem. But it seems that out of the box, tailwind does not currently support modifying the base font size via utility classes. Here is a suggestion for how to add this to tailwind - but I haven't tested it yet. This article provides a good discussion of the idea of scaling via rem and this article provides a quite interesting critical discussion of the idea as well as an interesting suggestion for how to deal with some of the pitfalls. This might be a candidate for where the skilled tailwind folks could come up with a well considered solution, like with the typography plugin. Would love to see that, @adamwathan :-) |
Beta Was this translation helpful? Give feedback.
-
It would be nice to be able to only set the base font-size for tailwind classes as well. I just found out when adding tailwind to an existing project with a base font-size of 10, all of the rem values need to be changed manually. Would be nice if you could change it in the tailwind.config somewhere. |
Beta Was this translation helpful? Give feedback.
-
Here's the config conversion for font size, spacing, border-radius, max-width, and line height (assuming base 10px) in case someone needs it.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I wrote a small mod to iterate through the default theme and convert rem to px at a fixed size, runs in my tailwind.config.js
|
Beta Was this translation helpful? Give feedback.
-
This is really bad. We have a npm package coded in tailwindcss. As soon as it got integrated we realised that it broke |
Beta Was this translation helpful? Give feedback.
-
It would be great if we could use Use case: we create a package or control that integrates in a page that we have no control over.
|
Beta Was this translation helpful? Give feedback.
-
This is what I love so much about Tailwind, all I need is a basic CSS property and the entire base font can be different. It's so clean. |
Beta Was this translation helpful? Give feedback.
-
Figured I would leave my modification of the above answers here in case anyone needs in the future ^.^
|
Beta Was this translation helpful? Give feedback.
-
For anyone that is looking for a way to set the base font size to 10px but preserve the relative proportions of tailwind's utility classes, I recently published a Tailwind CSS plugin 'tailwindcss-base-font-size' that allows you to do just that. You can check it out here. Give it a try and let me know, if you have any questions! 👍 |
Beta Was this translation helpful? Give feedback.
-
I'm using Next.js 14 and to achieve responsive base text size, I used @apply in the html tag block of my globals.css file between @tailwind components and @tailwind utilities like this: globals.css:
This ensures that on large screens down to the small size cutoff the text will be 20pts, but any other size (i.e. below the cutoff) it will be 16. It also allows for this to be overridden by tailwind utilities if needed in places |
Beta Was this translation helpful? Give feedback.
-
I use this css var workaround to have a fine grained font-size control per element and keeping ratios : import { fontSize } from 'tailwindcss/defaultTheme';
const sizes = Object.keys(fontSize)
// ... config
fontSize: Object.fromEntries(sizes.map(
size => [ size, [`calc( var(--font-scale) * ${fontSize[size][0]})`, `calc( var(--font-scale) * ${fontSize[size][1].lineHeight})`] ]
))
// ... config That way you can use : @layer base {
:root{
--font-scale: 1;
}
html {
font-size: calc( 16px * var(--font-scale) );
}
}
.my-element-10px-base{
--font-scale: 0.625
}
.richtext{
--font-scale: 1.3
} That's also convenient when using multiple fonts which font-size doesn't match |
Beta Was this translation helpful? Give feedback.
-
I'd like to adjust the font size system by setting the base font size. How do I set this?
Beta Was this translation helpful? Give feedback.
All reactions