How to add font ttf file in nextjs #16257
Unanswered
Shankhadeep1234
asked this question in
Help
Replies: 2 comments 1 reply
|
You can reference files in the @font-face {
font-family: "Avenir";
src: url("/fonts/AvenirNextRoundedStd-Demi.ttf");
src: url("/fonts/AvenirNextRoundedStd-MedIt.ttf");
src: url("/fonts/AvenirNextRoundedStd-Reg.ttf");
}Also you should consider removing |
1 reply
|
You can also use // fonts/index.ts
// fonts/myFont.ttf
import localFont from "next/font/local";
export const myFont = localFont({
src: "myFont.ttf",
display: "swap",
variable: "--font-my-font",
});// app/layout.tsx
import "./globals.css";
import { myFont } from "@/fonts";
export default function RootLayout({
/* ... */
}) {
return (
<html lang="en">
<body className={`${venite.variable}`}>
{/* ... */}
</body>
</html>
);
}/* app/globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
.my-font {
font-family: var(--font-my-font);
@apply tracking-wide;
}
}
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am new to Nextjs. I wanna add my custom fonts to my project. I am totally confused about how to do that(my fonts are in "public/fonts/"). my global.css file is this-
//global.css
`html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
box-sizing: border-box;
}
@font-face {
font-family: "Avenir";
src: url("../public/fonts/AvenirNextRoundedStd-Demi.ttf");
src: url("../public/fonts/AvenirNextRoundedStd-MedIt.ttf");
src: url("../public/fonts/AvenirNextRoundedStd-Reg.ttf");
}`
//next.config.js
const withCSS = require("@zeit/next-css"); module.exports = withCSS({ /* config options here */ });All reactions