I recently started a new project using React, and I have integrated a custom font in my index.css file. I have also included the necessary font files.
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind variants;
@import url(assets/font/iransans/index.css);
html {
margin: 0;
font-family:
"iransans",
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
"Roboto",
"Oxygen",
"Ubuntu",
"Cantarell",
"Fira Sans",
"Droid Sans",
"Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: "iransans", source-code-pro, Menlo, Monaco, Consolas,
"Courier New", monospace;
}
html {
scrollbar-gutter: scroll;
}
body {
margin: 0;
font-family:
"iransans",
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
"Roboto",
"Oxygen",
"Ubuntu",
"Cantarell",
"Fira Sans",
"Droid Sans",
"Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
In my tailwind.config.ts file, I have included my custom font in the font family section.
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ["iransans", ...defaultTheme.fontFamily.sans],
serif: ["iransans", ...defaultTheme.fontFamily.serif],
mono: ["iransans", ...defaultTheme.fontFamily.mono],
iransans: "iransans",
},
},
},
...
}
However, I have encountered an issue where the custom font is not automatically applied to all elements. For instance, if I want a span element to use this custom font, I must set the font manually.
<span className="font-iransans">تست</span>