Skip to main content
Version: 1.0.0

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 { DragbleEditor, DragbleEditorRef } from "dragble-react-editor";

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

return (
<DragbleEditor
ref={editorRef}
editorKey="db_your_key"
editorMode="email"
options={{
fonts: {
excludeDefaults: false,
customFonts: [
{
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],
},
],
},
}}
/>
);
}

:::tip 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:

fonts: {
excludeDefaults: true,
customFonts: [
{ 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,
customFonts: [
{
label: "New Font",
value: "'New Font', sans-serif",
url: "...",
weights: [400, 700],
},
],
});

// Vanilla JS
dragble.setFonts({
excludeDefaults: false,
customFonts: [
/* ... */
],
});

:::warning 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. :::

Configuration reference

PropertyTypeDefaultDescription
excludeDefaultsbooleanfalseHide built-in default system fonts
customFontsFontDefinition[][]Custom fonts to add

FontDefinition

PropertyTypeRequiredDescription
labelstringYesDisplay name in the font dropdown
valuestringYesCSS font-family value (include fallbacks)
urlstringNoURL to CSS file with @font-face declarations
weightsnumber[]NoAvailable font weights (e.g., [400, 700])
defaultFontbooleanNoWhether this is a default system font

Method reference

MethodReturnsDescription
setFonts(config)voidReplace the custom fonts configuration at runtime
getFonts()Promise<FontsConfig>Get the current fonts configuration

Next steps