Skip to main content

Custom Fonts

Load custom web fonts into the editor so users can apply your brand typography to any text element.

import { useRef } from 'react';
import { PexelizeEditor, PexelizeEditorRef } from '@pexelize/react-editor';

function BrandFontEditor() {
const editorRef = useRef<PexelizeEditorRef>(null);

return (
<PexelizeEditor
ref={editorRef}
editorKey="pk_your_key"
editorMode="email"
options={{
customFonts: {
excludeDefaults: false,
fonts: [
{
label: 'Inter',
value: "'Inter', sans-serif",
url: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap',
weights: [400, 500, 600, 700],
},
{
label: 'Playfair Display',
value: "'Playfair Display', serif",
url: 'https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&display=swap',
weights: [400, 700],
},
{
label: 'Brand Sans',
value: "'Brand Sans', sans-serif",
url: 'https://cdn.example.com/fonts/brand-sans.css',
weights: [400, 600],
},
],
},
}}
/>
);
}
Font URL format

The url should point to a CSS file that contains @font-face declarations. Google Fonts URLs work directly. For self-hosted fonts, serve a CSS file with the correct @font-face rules.

Exclude default fonts

Set excludeDefaults: true to remove all built-in system fonts (Arial, Times New Roman, etc.) and only show your custom fonts:

customFonts: {
excludeDefaults: true,
fonts: [
{ label: 'Brand Sans', value: "'Brand Sans', sans-serif", url: '...', weights: [400, 600] },
{ label: 'Brand Serif', value: "'Brand Serif', serif", url: '...', weights: [400, 700] },
],
}

Update fonts at runtime

// React
editorRef.current?.editor?.setFonts({
excludeDefaults: false,
fonts: [
{ label: 'New Font', value: "'New Font', sans-serif", url: '...', weights: [400, 700] },
],
});

// Vanilla JS
pexelize.setFonts({ excludeDefaults: false, fonts: [/* ... */] });
Email client support

Not all email clients support web fonts. The editor includes the fallback font stack from the value property (e.g., sans-serif). Always specify a web-safe fallback.

Method reference

MethodReturnsDescription
setFonts(config)voidReplace the custom fonts configuration at runtime

Next steps