I'm using Tailwind and React, now I need to set font size dynamically from API.
tailwind.config code:
plugins: [
plugin(function({ addBase }) {
addBase({
'html' : {fontSize:"10px"} //this font size should come from API
})
})
],
API response:
{fontSize:"14px",fontFamily:'poppins'}
How can I make fontSize dynamically?
You can achieve this by using CSS variables and manually setting that variable using JS once the response is received from the server.
CSS variables are set on the document (HTML) object itself, so we can easily change it using JS later by accessing the style object like so:
tailwind.config.jsset thefontSizeto a CSS variable instead.--html-font-sizevariable like so:You can do something similar for the
fontFamilyif you want by creating another variable and setting that as well.