Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brenopolanski/44de516d95d2302cb308596a11033cc8 to your computer and use it in GitHub Desktop.
Save brenopolanski/44de516d95d2302cb308596a11033cc8 to your computer and use it in GitHub Desktop.
Responsive font-size for Tailwindcss
const plugin = require('tailwindcss/plugin')
module.exports = plugin(function ({ addBase, theme }) {
addBase({
':root': {
'--min-fs': theme('variable-font.min-fs'),
'--max-fs': theme('variable-font.max-fs'),
'--min-vw': theme('variable-font.min-vw'),
'--max-vw': theme('variable-font.max-vw'),
'--min-fs-rem': 'var(--min-fs) * 1rem',
'--max-fs-rem': 'var(--max-fs) * 1rem',
'--min-vw-rem': 'var(--min-vw) * 1rem',
'--slope': '(var(--max-fs) - var(--min-fs)) * (100vw - var(--min-vw-rem)) / (var(--max-vw) - var(--min-vw))',
'font-size': 'clamp(var(--min-fs-rem), var(--min-fs-rem) + var(--slope), var(--max-fs-rem))',
},
})
}, {
theme: {
'variable-font': {
'min-fs': '1', // 16px
'max-fs': '1.25', // 20px
'min-vw': '20', // 320px
'max-vw': '45', // 720px
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment