Skip to content

How to extend theme with TwMerge in Tailwind v4 #521

Answered by dcastil
JacobArrow asked this question in Help
Discussion options

You must be logged in to vote

Hey @JacobArrow! 👋

I know it is repetitive, but I think the best way to do it is to just hardcode the font sizes into the tailwind-merge config, possibly using validators.

E.g. if you're using a number scale like --text-1, --text-2, etc. you can just use a config like this:

import { extendTailwindMerge, validators } from 'tailwind-merge'

const twMerge = extendTailwindMerge({
    override: {
        theme: {
            text: [validators.isNumber],
        },
    },
})

Then you don't need to touch the tailwind-merge config if you add more font-size variables that are essentially just new numbers on the scale.

If you use specific names that don't match any validator, e.g. --text-tiny, --te…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JacobArrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
context-v3 Related to tailwind-merge v3
2 participants