amiryxe/next-persian-fonts
About
Persian fonts package for Next.js
Design & MediaWhat you can do
- Fully offline: font files ship inside the package; your build and site never depend on Google or a CDN.
- No layout shift: loaded with next/font/local, preloaded automatically, font-display: swap.
- Only what you import ends up in your build (one subpath per font).
- Persian-digit (FD) variants for the Iranian fonts.
Measured star growth
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +3
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalnext-persian-fonts
فونتهای فارسی رایگان برای Next.js، داخل خود پکیج. بدون گوگل و CDN، حتی اگر اینترنت محدود باشد.
Free Persian (Farsi) fonts for Next.js, bundled in the package. No Google, no CDN, works offline.
🎨 دموی زنده و گالری · Live demo · فارسی · English · فهرست فونتها · Fonts
⭐ اگر این پکیج به کارتان آمد، با یک ستاره در گیتهاب حمایتش کنید.
⭐ If this package helped you, please give it a star on GitHub.
فارسی
ویژگیها
- ۴۴ خانوادهٔ فونت فارسی و ۶۲ نسخهٔ آماده: وزیرمتن، استعداد، ساحل، صمیم، شبنم، میخک، آراد، پرستو، گندم، تنها، وزیر کد، بهداد، نیکا، سپهر، سورنا، گنجنامه، شهاب، ناهید، نرمال سنس، آریو، رویین، نقطه و ۲۲ فونت فارسی Google Fonts مثل لالهزار، نوتو نسخ، نوتو نستعلیق، امیری و بدین.
- کاملاً آفلاین: فایل فونتها داخل پکیج است؛ build و سایت شما به گوگل یا CDN وابسته نیست.
- بدون پرش صفحه (CLS): بارگذاری با
next/font/local، پیشبارگذاری خودکار وfont-display: swap. - فقط همان فونتی که ایمپورت میکنید در خروجی میآید (هر فونت مسیر جداگانه دارد).
- نسخههای ارقام فارسی (FD) برای فونتهای ایرانی.
- تایپاسکریپت و سازگار با Next.js ۱۳.۲ تا ۱۶، App Router و Pages Router، Turbopack و webpack.
- بدون Next.js هم: برای Vite، Gatsby، Astro و HTML ساده، هر فونت یک فایل CSS آماده دارد (توضیح). برای کاربران Next.js هیچ هزینهای ندارد.
- مجوز آزاد (بیشتر SIL OFL 1.1)؛ استفاده در پروژههای تجاری مجاز است.
نصب و استفاده در ۳ قدم
۱. نصب کنید
npm install next-persian-fonts
با pnpm یا yarn: pnpm add next-persian-fonts@^1.2 (نسخه را صریح بنویسید؛ pnpm بستههای تازهمنتشرشده را تا مدتی نصب نمیکند).
۲. فونت را در app/layout.tsx ایمپورت کنید
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
۳. کلاس فونت را روی <body> بگذارید
<body className={vazirmatnVariable.className}>
تمام! حالا کل سایت با فونت وزیرمتن نمایش داده میشود.
پروژهٔ تازهٔ create-next-app؟ در
app/layout.tsxایمپورت فونتهای Geist ازnext/font/googleرا حذف کنید (باید هنگام build از گوگل دانلود شوند) و درglobals.cssخطfont-family: Arial, Helvetica, sans-serif;را از قانونbodyپاک کنید تا جلوی فونت فارسی را نگیرد.
مثال کامل: App Router
// app/layout.tsx
import './globals.css'
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="fa" dir="rtl">
<body className={vazirmatnVariable.className}>{children}</body>
</html>
)
}
مثال کامل: Pages Router
// pages/_app.tsx
import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
export default function App({ Component, pageProps }: AppProps) {
return (
<main className={vazirmatnVariable.className}>
<Component {...pageProps} />
</main>
)
}
و در next.config این را اضافه کنید (در Pages Router لازم است، چون Next.js پکیجهای node_modules را در Pages Router باندل نمیکند و بدون آن build با خطای ERR_UNSUPPORTED_DIR_IMPORT متوقف میشود؛ برای Jest هم لازم است و در App Router بیضرر است):
// next.config.mjs
export default {
transpilePackages: ['next-persian-fonts'],
}
برای راستچین شدن صفحه، در pages/_document.tsx بنویسید: <Html lang="fa" dir="rtl">.
استفاده با Tailwind
بهجای className از variable استفاده کنید:
<html lang="fa" dir="rtl" className={vazirmatnVariable.variable}>
Tailwind نسخهٔ ۴ (globals.css):
@import 'tailwindcss';
@theme inline {
--font-sans: var(--font-vazirmatn-variable), sans-serif;
}
Tailwind نسخهٔ ۳ (tailwind.config.js):
module.exports = {
theme: {
extend: {
fontFamily: { sans: ['var(--font-vazirmatn-variable)', 'sans-serif'] },
},
},
}
حالا font-sans همان وزیرمتن است. نام متغیر CSS هر فونت --font- بهعلاوهٔ مسیر ایمپورت آن است؛ مثلاً next-persian-fonts/estedad ← --font-estedad.
استفاده در پروژههای غیر Next.js (Vite، Gatsby، Astro، HTML ساده)
از نسخهٔ ۱.۲ برای هر فونت یک فایل CSS آماده هم هست: next-persian-fonts/css/<نام>.css. نام فایل همان مسیر ایمپورت است (مثلاً vazirmatn-variable.css یا sahel-fd.css؛ فهرست کامل در ستون CSS جدول FONTS.md). هر فایل:
- قانونهای
@font-faceرا با همان فایلهای فونت داخل پکیج تعریف میکند (font-display: swapو بازهٔ وزن درست برای فونتهای متغیر)، - متغیر CSS را روی
:rootمیگذارد، مثلاً--font-vazirmatn-variable(همان نام متغیر نسخهٔ Next.js)، - و یک کلاس آماده میسازد، مثلاً
.font-vazirmatn-variable.
Vite (React، Vue، Svelte، vanilla)، Gatsby و Astro: فایل CSS را یک بار ایمپورت کنید؛ باندلر فایل فونت را خودش کپی میکند.
// main.jsx (Vite) · gatsby-browser.js (Gatsby) · frontmatter فایل Layout.astro (Astro)
import 'next-persian-fonts/css/vazirmatn-variable.css'
<body class="font-vazirmatn-variable">
یا در CSS خودتان: body { font-family: var(--font-vazirmatn-variable); }. ایمپورت از داخل CSS هم کار میکند: @import 'next-persian-fonts/css/vazirmatn-variable.css';.
Tailwind نسخهٔ ۴:
@import 'tailwindcss';
@import 'next-persian-fonts/css/vazirmatn-variable.css';
@theme inline {
--font-sans: var(--font-vazirmatn-variable);
}
(در Tailwind نسخهٔ ۳: fontFamily: { sans: ['var(--font-vazirmatn-variable)'] }.)
HTML ساده (بدون باندلر): فایل CSS را با <link> اضافه کنید. آدرس فونتها نسبی است، پس کافی است پوشهٔ پکیج (یا کل node_modules) کنار صفحه باشد:
<link rel="stylesheet" href="node_modules/next-persian-fonts/css/vazirmatn-variable.css">
<body class="font-vazirmatn-variable">
برای کاربران Next.js هیچ چیزی تغییر نمیکند: این فایلها فقط وقتی وارد خروجی میشوند که خودتان ایمپورتشان کنید. در Next.js همان روش
next/fontبالا را استفاده کنید (preload و بدون پرش صفحه).
چرا آفلاین؟ (برای توسعهدهندههای ایرانی)
اگر اینترنت محدود باشد، next/font/google ممکن است هنگام build نتواند فونت را دانلود کند و فونتهای CDN هم برای کاربران باز نشوند. در این پکیج فایل فونتها همراه npm install میآیند و Next.js آنها را روی سایت خودتان میزبانی میکند. کافی است پکیج یک بار از npm یا یک آینهٔ داخلی نصب شده باشد.
پرسشهای رایج
چطور چند فونت را با هم استفاده کنم؟
variable هر فونت را روی <html> بگذارید و هر جا لازم است از متغیرش استفاده کنید:
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
import { lalezar } from 'next-persian-fonts/lalezar'
<html lang="fa" dir="rtl" className={`${vazirmatnVariable.variable} ${lalezar.variable}`}>
body { font-family: var(--font-vazirmatn-variable); }
h1 { font-family: var(--font-lalezar); }
با Tailwind v4 هم میتوانید در @theme بنویسید --font-display: var(--font-lalezar); و از کلاس font-display استفاده کنید. یا سادهتر: lalezar.className را مستقیم روی همان المان بگذارید.
نسخههای FD چه هستند؟
در نسخههای FD (مثل sahelFD) حتی اعداد انگلیسی (123) هم فارسی (۱۲۳) نمایش داده میشوند؛ برای قیمت و تاریخ مفید است. اگر متن شما خودش اعداد فارسی دارد، نسخهٔ معمولی هم کافی است. vazirMatn همیشه اعداد فارسی دارد.
optimizePackageImports لازم است؟
اگر از مسیر هر فونت ایمپورت کنید (next-persian-fonts/estedad)، نه. فقط اگر از ریشهٔ پکیج ایمپورت میکنید (import { sahel } from 'next-persian-fonts'، روش قدیمی نسخهٔ ۱.۰) و با webpack میسازید، این را در next.config اضافه کنید:
experimental: { optimizePackageImports: ['next-persian-fonts'] }
Pages Router یا Jest خطای ERR_UNSUPPORTED_DIR_IMPORT میدهد؟
در next.config بنویسید transpilePackages: ['next-persian-fonts']. Pages Router و next/jest پکیجهای node_modules را باندل نمیکنند، پس next/font/local اجرا نمیشود. این تنظیم در App Router هم بیضرر است.
چرا بعضی فونتها preload نمیشوند؟
خروجیهایی که بیش از ۳ فایل دارند (مثل vazirMatn با ۹ وزن، sahelFD، shabnam، ibmPlexSansArabic) preload نمیشوند تا Next.js همهٔ وزنها را در هر صفحه از قبل دانلود نکند؛ فقط وزنهایی که استفاده میکنید بارگذاری میشوند. برای کمترین حجم، نسخههای متغیر مثل vazirmatnVariable را انتخاب کنید (یک فایل برای همهٔ وزنها).
با pnpm نسخهٔ قدیمی (۱.۰) نصب شد؟
نسخههای جدید pnpm بستههایی را که تازه منتشر شدهاند تا مدتی نصب نمیکنند. نسخه را صریح بنویسید: pnpm add next-persian-fonts@^1.2.
بدون Next.js هم میشود استفاده کرد؟
بله، با فایلهای CSS پکیج، مثلاً import 'next-persian-fonts/css/estedad.css'، در Vite، Gatsby، Astro یا با <link> در HTML ساده. بخش استفاده در پروژههای غیر Next.js را ببینید.
با کدام نسخههای Next.js کار میکند؟
Next.js ۱۳.۲ تا ۱۶، App Router و Pages Router، Turbopack و webpack، React ۱۸ و ۱۹. همهٔ این ترکیبها در CI تست میشوند.
از نسخهٔ ۱.۰ ارتقا میدهم؛ چیزی خراب میشود؟
نه. همهٔ مسیرها و نامهای نسخهٔ ۱.۰ هنوز کار میکنند. فقط estedadFD منسوخ شده (روی استعداد ۷.۳ مانده)؛ برای پروژهٔ جدید از estedad استفاده کنید. جزئیات در CHANGELOG.
برای پروژهٔ تجاری رایگان است؟
بله. همهٔ فونتها مجوز آزاد دارند (بیشترشان SIL OFL 1.1). جزئیات در LICENSE.md.
مشارکت
⭐ اگر این پکیج به کارتان آمد، لطفاً در گیتهاب به آن ستاره بدهید؛ ستارهها کمک میکنند توسعهدهندههای بیشتری آن را پیدا کنند.
پیشنهاد فونت جدید، گزارش باگ یا Pull Request در GitHub خوشحالمان میکند. فقط فونتهایی با مجوز آزاد (مثل OFL) اضافه میشوند. راهنمای افزودن فونت در بخش Development آمده است.
اعتبار و مجوز
کد پکیج با مجوز ISC منتشر میشود. هر فونت متعلق به طراح خودش است و با مجوز خودش (بیشتر SIL OFL 1.1) بازتوزیع میشود؛ فایل مجوز داخل پوشهٔ هر فونت است. از همهٔ طراحان، بهویژه صابر راستیکردار و امین عابدی، سپاسگزاریم.
فهرست فونتها · Fonts
Usage · استفاده: import { <Export> } from 'next-persian-fonts/<import>'
Iranian fonts · فونتهای ایرانی
| Font · فونت | Designer · طراح | Import next-persian-fonts/… |
Export | Weights | License |
|---|---|---|---|---|---|
| Vazirmatn وزیرمتن |
Saber Rastikerdar | vazirmatnvazirmatn-variablevazirmatn-round-dots |
vazirMatn ¹vazirmatnVariablevazirmatnRoundDots |
100–900 (9) | OFL-1.1 |
| Sahel ساحل |
Saber Rastikerdar | sahelsahel-fd |
sahelsahelFD ¹ |
400–900 variable | OFL-1.1 |
| Estedad استعداد |
Amin Abedi | estedad |
estedad |
100–900 variable | OFL-1.1 |
| Samim صمیم |
Saber Rastikerdar | samimsamim-fd |
samimsamimFD ¹ |
400, 500, 700 | OFL-1.1 + Vera |
| Shabnam شبنم |
Saber Rastikerdar | shabnamshabnam-fd |
shabnamshabnamFD ¹ |
100–700 (5) | OFL-1.1 + Vera |
| Tanha تنها |
Saber Rastikerdar | tanhatanha-fd |
tanhatanhaFD ¹ |
400 | Vera + PD |
| Parastoo پرستو |
Saber Rastikerdar | parastooparastoo-fd |
parastooparastooFD ¹ |
400, 700 | OFL-1.1 |
| Gandom گندم |
Saber Rastikerdar | gandomgandom-fd |
gandomgandomFD ¹ |
400 | OFL-1.1 + Vera |
| Mikhak میخک |
Amin Abedi | mikhakmikhak-fd |
mikhakmikhakFD ¹ |
100–900 variable | OFL-1.1 |
| Arad آراد |
Mohamad Darvishi | aradarad-fd |
aradaradFD ¹ |
100–1000 variable | OFL-1.1 |
| Vazir Code وزیر کد |
Saber Rastikerdar | vazir-codevazir-code-fd |
vazirCodevazirCodeFD ¹ |
400 | Vera + PD |
| Behdad بهداد |
Mohammad Saleh Souzanchi (Font Store) | behdad |
behdad |
400 | OFL-1.1 |
| Nika نیکا |
Mohammad Saleh Souzanchi (Font Store) | nika |
nika |
400 | OFL-1.1 |
| Sepehr سپهر |
Saeed Rezaee, Saber Rastikerdar | sepehr |
sepehr |
100, 300, 400, 500, 700 | OFL-1.1 |
| Sorena سورنا |
Mohamad Darvishi | sorenasorena-fdsorena-pixelsorena-pixel-fd |
sorenasorenaFD ¹sorenaPixelsorenaPixelFD ¹ |
400 | OFL-1.1 |
| Ganjnameh گنجنامه |
Mohammad Saleh Souzanchi | ganjnameh |
ganjnameh |
400 | OFL-1.1 |
| Shahab شهاب |
Mohammad Saleh Souzanchi | shahab |
shahab |
400 | OFL-1.1 |
| Nahid ناهید |
Saber Rastikerdar | nahidnahid-fd |
nahidnahidFD ¹ |
400 | Vera + PD |
| Normal Sans نرمال سنس |
Azad Qalam | normal-sans |
normalSans |
100–900 variable | OFL-1.1 |
| Ario آریو |
Mohamad Darvishi | arioario-fd |
arioarioFD ¹ |
400 | OFL-1.1 |
| Rooyin رویین |
Mohamad Darvishi | rooyinrooyin-fd |
rooyinrooyinFD ¹ |
400, 700 | OFL-1.1 |
| Noqte نقطه |
Mehdi Sadeghi | noqte |
noqte |
500 | OFL-1.1 |
Google Fonts, bundled offline · فونتهای Google Fonts (آفلاین)
| Font · فونت | Designer · طراح | Import next-persian-fonts/… |
Export | Weights | License |
|---|---|---|---|---|---|
| Lalezar لالهزار |
Borna Izadpanah | lalezar |
lalezar |
400 | OFL-1.1 |
| Markazi Text مرکزی |
Borna Izadpanah | markazi-text |
markaziText |
400–700 variable | OFL-1.1 |
| Mirza میرزا |
KB-Studio (Kourosh Beigpour) | mirza |
mirza |
400–700 (4) | OFL-1.1 |
| Reem Kufi ریم کوفی |
Khaled Hosny (Alif Type) | reem-kufi |
reemKufi |
400–700 variable | OFL-1.1 |
| Noto Naskh Arabic نوتو نسخ |
Google (Noto project) | noto-naskh-arabic |
notoNaskhArabic |
400–700 variable | OFL-1.1 |
| Noto Sans Arabic نوتو سنس عربی |
Google (Noto project) | noto-sans-arabic |
notoSansArabic |
100–900 variable | OFL-1.1 |
| Noto Kufi Arabic نوتو کوفی |
Google (Noto project) | noto-kufi-arabic |
notoKufiArabic |
100–900 variable | OFL-1.1 |
| Noto Nastaliq Urdu نوتو نستعلیق |
Google (Noto project) | noto-nastaliq-urdu |
notoNastaliqUrdu |
400–700 variable | OFL-1.1 |
| IBM Plex Sans Arabic آیبیام پلکس عربی |
IBM (Mike Abbink, Bold Monday) | ibm-plex-sans-arabic |
ibmPlexSansArabic |
100–700 (7) | OFL-1.1 |
| Amiri امیری |
Khaled Hosny (Alif Type) | amiri |
amiri |
400, 700 + italic | OFL-1.1 |
| Harmattan هرمتان |
SIL Global | harmattan |
harmattan |
400–700 (4) | OFL-1.1 |
| Scheherazade New شهرزاد |
SIL Global | scheherazade-new |
scheherazadeNew |
400–700 (4) | OFL-1.1 |
| Lateef لطیف |
SIL Global | lateef |
lateef |
400–700 (4) | OFL-1.1 |
| Katibeh کتیبه |
KB-Studio (Kourosh Beigpour) | katibeh |
katibeh |
400 | OFL-1.1 |
| Aref Ruqaa عارف رقعه |
Abdullah Aref, Khaled Hosny | aref-ruqaa |
arefRuqaa |
400, 700 | OFL-1.1 |
| Rubik روبیک |
Hubert & Fischer, Meir Sadan, Cyreal, Daniel Grumer | rubik |
rubik |
300–900 variable + italic | OFL-1.1 |
| Jomhuria جمهوریا |
KB-Studio (Kourosh Beigpour) | jomhuria |
jomhuria |
400 | OFL-1.1 |
| El Messiri المسیری |
Mohamed Gaber, Jovanny Lemonad | el-messiri |
elMessiri |
400–700 variable | OFL-1.1 |
| Changa چنگا |
Eduardo Tunni | changa |
changa |
200–800 variable | OFL-1.1 |
| Baloo Bhaijaan 2 بالو بهایجان |
Ek Type | baloo-bhaijaan-2 |
balooBhaijaan2 |
400–800 variable | OFL-1.1 |
| Cairo قاهره |
Mohamed Gaber | cairo |
cairo |
200–1000 variable | OFL-1.1 |
| Badeen Display بدین |
Hani Adnan | badeen-display |
badeenDisplay |
400 | OFL-1.1 |
¹ Persian digits (FD): Latin digits are shown as Persian digits.
¹ نسخهٔ ارقام فارسی (FD): ارقام لاتین هم فارسی نمایش داده میشوند.
Vera = Bitstream Vera license (Latin glyphs), PD = public domain changes. Versions, sources and file changes: FONTS.md.
Request a font · درخواست فونت
فونتی که میخوای توی لیست نیست؟ از فرم درخواست فونت پیشنهادش بده. Missing a font? Suggest it with the font request form.
English
Features
- 44 Persian font families, 62 ready-to-use exports: Vazirmatn, Estedad, Sahel, Samim, Shabnam, Mikhak, Arad, Parastoo, Gandom, Tanha, Vazir Code, Behdad, Nika, Sepehr, Sorena, Ganjnameh, Shahab, Nahid, Normal Sans, Ario, Rooyin, Noqte, plus 22 Persian-capable Google Fonts (Lalezar, Noto Naskh/Sans/Kufi Arabic, Noto Nastaliq Urdu, Amiri, IBM Plex Sans Arabic, …).
- Fully offline: font files ship inside the package; your build and site never depend on Google or a CDN.
- No layout shift: loaded with
next/font/local, preloaded automatically,font-display: swap. - Only what you import ends up in your build (one subpath per font).
- Persian-digit (FD) variants for the Iranian fonts.
- TypeScript types; works with Next.js 13.2 → 16, App Router and Pages Router, Turbopack and webpack, React 18/19.
- Works without Next.js too: every font has a plain CSS file for Vite, Gatsby, Astro and plain HTML (how). It adds nothing for Next.js users.
- Free licenses (mostly SIL OFL 1.1), fine for commercial projects.
Installation & Usage (3 steps)
- Install:
npm install next-persian-fonts(with pnpm/yarn:pnpm add next-persian-fonts@^1.2; recent pnpm versions hold back freshly published releases for a while) - Import a font in
app/layout.tsx:import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable' - Put its class on
<body>:<body className={vazirmatnVariable.className}>
Fresh create-next-app project? Remove the Geist
next/font/googleimports fromapp/layout.tsx(they need the global internet) and delete thefont-family: Arial, Helvetica, sans-serif;line from thebodyrule inglobals.css, otherwise it overrides the Persian font.
App Router
// app/layout.tsx
import './globals.css'
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="fa" dir="rtl">
<body className={vazirmatnVariable.className}>{children}</body>
</html>
)
}
Pages Router
// pages/_app.tsx
import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import { vazirmatnVariable } from 'next-persian-fonts/vazirmatn-variable'
export default function App({ Component, pageProps }: AppProps) {
return (
<main className={vazirmatnVariable.className}>
<Component {...pageProps} />
</main>
)
}
The Pages Router also needs this in next.config (Next.js doesn't bundle node_modules packages for the Pages Router, so without it the build fails with ERR_UNSUPPORTED_DIR_IMPORT; Jest via next/jest needs it too, and it's harmless for the App Router):
// next.config.mjs
export default {
transpilePackages: ['next-persian-fonts'],
}
For right-to-left pages, use <Html lang="fa" dir="rtl"> in pages/_document.tsx.
Tailwind
Use .variable instead of .className: <html className={vazirmatnVariable.variable}>.
/* Tailwind v4: globals.css */
@import 'tailwindcss';
@theme inline {
--font-sans: var(--font-vazirmatn-variable), sans-serif;
}
// Tailwind v3: tailwind.config.js
theme: { extend: { fontFamily: { sans: ['var(--font-vazirmatn-variable)', 'sans-serif'] } } }
Each font's CSS variable is --font- + its import path, e.g. next-persian-fonts/estedad → --font-estedad.
Using without Next.js (Vite, Gatsby, Astro, plain HTML)
Since 1.2 every font also ships as a plain CSS file: next-persian-fonts/css/<name>.css, where <name> is the import path (e.g. vazirmatn-variable.css, sahel-fd.css; see the CSS column in FONTS.md). Each file:
- declares
@font-facerules for the same bundled font files (font-display: swap, real weight ranges for variable fonts), - sets the CSS variable on
:root, e.g.--font-vazirmatn-variable(the same name as the Next.js variable), - and adds a ready-made class, e.g.
.font-vazirmatn-variable.
Vite (React, Vue, Svelte, vanilla), Gatsby and Astro: import the CSS once; the bundler copies the font file for you.
// main.jsx (Vite) · gatsby-browser.js (Gatsby) · Layout.astro frontmatter (Astro)
import 'next-persian-fonts/css/vazirmatn-variable.css'
<body class="font-vazirmatn-variable">
Or in your own CSS: body { font-family: var(--font-vazirmatn-variable); }. Importing from CSS works too: @import 'next-persian-fonts/css/vazirmatn-variable.css';.
Tailwind v4:
@import 'tailwindcss';
@import 'next-persian-fonts/css/vazirmatn-variable.css';
@theme inline {
--font-sans: var(--font-vazirmatn-variable);
}
(Tailwind v3: fontFamily: { sans: ['var(--font-vazirmatn-variable)'] }.)
Plain HTML (no bundler): link the CSS file. Font URLs are relative, so the package folder (or node_modules) just has to be served next to the page:
<link rel="stylesheet" href="node_modules/next-persian-fonts/css/vazirmatn-variable.css">
<body class="font-vazirmatn-variable">
Nothing changes for Next.js users: the CSS files only end up in a build if you import them. With Next.js, keep using the
next/fontexports above (preloading, no layout shift).
Why offline?
If internet access is restricted, next/font/google may not download fonts at build time and CDN fonts may not load. Here the font files come with npm install and are self-hosted by Next.js, so they always work.
FAQ
- Several fonts? Put each font's
.variableon<html>and usefont-family: var(--font-lalezar)where needed, or putlalezar.classNameon a single element. - Without Next.js? Yes:
import 'next-persian-fonts/css/estedad.css'in Vite, Gatsby or Astro, or a<link>in plain HTML. See Using without Next.js. - What are the
FDexports? They render Latin digits (123) as Persian digits (۱۲۳).vazirMatnalways uses Persian digits. - Do I need
optimizePackageImports? Not with subpath imports. Only for the legacy root import (from 'next-persian-fonts') with webpack:experimental: { optimizePackageImports: ['next-persian-fonts'] }. - Pages Router or Jest fails with
ERR_UNSUPPORTED_DIR_IMPORT? AddtranspilePackages: ['next-persian-fonts']tonext.config. Harmless for the App Router. - Why are some fonts not preloaded? Exports with more than 3 files (e.g.
vazirMatnwith 9 weights,sahelFD,shabnam,ibmPlexSansArabic) aren't preloaded, so Next.js doesn't download every weight on every page; only the weights you use load. Variable exports such asvazirmatnVariableare the lightest (one file for all weights). - pnpm installed 1.0? Recent pnpm versions hold back freshly published releases for a while. Use
pnpm add next-persian-fonts@^1.2. - Upgrading from 1.0? Nothing breaks: every 1.0 import path and export still works.
estedadFDis deprecated (kept on Estedad 7.3); useestedad. See the CHANGELOG. - Commercial use? Yes. All fonts use free licenses (mostly SIL OFL 1.1).
Contributing
⭐ If this package saved you time, a star on GitHub helps other developers find it.
Font suggestions, bug reports and pull requests are welcome on GitHub. Only fonts with a redistributable license (e.g. OFL) can be added. See Development for how fonts are added and tested.
Credits & license
Package code: ISC. Every font belongs to its designer and is redistributed under its own license (mostly SIL OFL 1.1); each font folder contains its license file. Some Google Fonts files were converted to WOFF2 and subset to Arabic + Latin; FONTS.md lists every change. Thanks to all the type designers, especially Saber Rastikerdar and Amin Abedi.
Development
Repository layout
src/next-persian-fonts/ ← the npm package (published as-is, no build step)
fonts.json ← source of truth: fonts, versions, files, licenses
<subpath>/ ← one folder per import path: index.js, index.d.ts, *.woff2, OFL.txt/LICENSE.txt
css/<name>.css ← generated plain-CSS version of every export (for projects without Next.js)
FONTS.md ← generated table of fonts, versions and licenses
src/app, src/components ← demo/docs site (Next.js 16, Tailwind 4, static export to GitHub Pages)
scripts/ ← generate / update / verify / smoke-test / screenshot scripts
The root package.json is a private npm workspace that contains the package, so the demo imports
next-persian-fonts/... exactly like a real app would. The package itself keeps the same folder
and the same published layout as 1.0.x.
Commands
npm install # installs the demo and links the package workspace
npm run dev # demo at http://localhost:3000/next-persian-fonts/
npm run build # static export into ./out
npm start # serves ./out at http://localhost:4173/next-persian-fonts/ (same base path as Pages)
npm run verify # generated files in sync, fonts valid, pack contents, types (bundler/node16/node10)
npm run test:smoke # App Router + Pages Router test apps with the packed tarball on Next 13.5–16 (webpack + Turbopack), next/jest on 16
npm run test:smoke:css # Vite, Vite + Tailwind 4 and webpack apps that import next-persian-fonts/css/*.css
npm run lint
Adding or updating a font
- Edit
src/next-persian-fonts/fonts.json: bumpversionandref(a tag or commit SHA) or add a new family/variant (only redistributable licenses!). npm run fonts:updatedownloads the font files and license texts from upstream (--only <id>for one family).npm run fonts:generateregeneratesindex.js,index.d.ts,css/*.css, theexportsmap,FONTS.mdand the demo gallery (src/lib/gallery-fonts.generated.ts,src/lib/css-fonts.generated.ts).- Run
npm run verify && npm run test:smoke && npm run test:smoke:css.
Google Fonts families are pinned to a google/fonts commit. TTF-only families are converted to WOFF2
and subset to Arabic + Latin by the update script (needs Python with fonttools and brotli; set
NPF_PYTHON=/path/to/python). Never subset a font whose OFL declares a Reserved Font Name for its own
name: use the authors' official WOFF2 instead.
The README banner is rendered from .github/assets/banner.html at 1280×640 (it uses the bundled font files); .github/assets/ is not part of the npm package.
npm run fonts:check-upstream compares the pinned versions with the latest upstream GitHub releases.
Releasing
npm run verify && npm run test:smoke && npm run test:smoke:css
cd src/next-persian-fonts && npm publish # publishes the package folder only
git tag v1.2.0 && git push origin main --tags # pushing main also deploys the demo to Pages
Explore related projects
Loading…

