Next.js ships optimized helpers for fonts and images—common performance and layout-shift pain points on content sites.
next/font
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ['latin'], display: 'swap' });
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={inter.className}>
<body>{children}</body>
</html>
);
}
Fonts self-host at build time—no extra layout shift from late-loading Google CSS.
next/image
import Image from 'next/image';
<Image
src="/hero.jpg"
alt="Team photo"
width={800}
height={450}
priority
/>
- Automatic responsive sizes and modern formats (WebP/AVIF where supported)
- Lazy loading by default;
priorityfor LCP heroes - Remote domains must be allowlisted in
next.config.js
Playground note
Use standard <img> in the sandbox; apply the same sizing and alt discipline you would with next/image locally.
Self-check
- Why specify
widthandheighton images? - What does
display: 'swap'on fonts improve?