Recommended approach to add custom fonts with the new theming system and frontend structure #34397
-
Hi everyone, I'm customizing the Superset UI and I’d like to add custom fonts so that they can be used globally via the I’ve found older threads suggesting the use of Since Superset is moving away from LESS and global CSS toward Ant Design v5 tokens and more JS-based theming, I’d like to ask:
I'd be very thankful if both cases could be explained, i.e.:
I’d really appreciate clarification or confirmation on the best practice, especially regarding how Superset expects custom fonts to be loaded in this new setup. Apologies if tagging is inappropriate, but I've seen the following folks be especially active in theming and frontend customization PRs, so I hope it’s okay to mention you for insights: @gabotorresruiz @msyavuz @eschutho @geido @mistercrunch @rusackas @EnxDev Thanks in advance for your time and help. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
Hi @VasilijeBursac! I'm Dosu and I’m helping the superset team. The most future-proof way to load custom fonts in Superset’s new theming system is to import your font files (via @fontsource, a CSS file, or @font-face) at the top of Theme.tsx in the frontend. This ensures the fonts are available globally and can be referenced in the Ant Design fontFamily token in your theme JSON or config. The theme token only sets the CSS font-family property; it does not load the font itself—so you must ensure the font is loaded before referencing it in the theme config. For local fonts, place your font files in /static/assets/fonts/, create a CSS file with @font-face rules pointing to those files, and import that CSS file at the top of Theme.tsx. For external fonts (like Google Fonts or @fontsource), import the relevant CSS or JS package at the top of Theme.tsx as well. If you use Google Fonts or another CDN, make sure to update the Content Security Policy (CSP) in TALISMAN_CONFIG in config.py to allow those font sources, or the browser will block them example. You do not need to maintain a custom fork if you can inject your font imports early in the frontend entry hierarchy or via a plugin, but to guarantee global font availability for all users, a minimal code change—importing your font CSS or @fontsource package in Theme.tsx—is the standard approach example. Theme.tsx is the canonical place for these imports in the new setup. Once the font is loaded, set the fontFamily token in your theme JSON/config to the font’s CSS name (e.g., 'My Custom Font', Arial, sans-serif). This will apply it globally via the theming system example. There’s no built-in mechanism to load fonts via theme JSON alone; font files must be loaded separately and referenced by name in the theme config. This approach is reusable across projects: just import your font(s) in Theme.tsx and reference them in your theme tokens. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Right now i think the best place to load custom fonts in is the |
Beta Was this translation helpful? Give feedback.
-
Yeah would be great to have support to something AFTER webpack builds. Ideally you'd reference a CDN and we'd get the fonts in the background. The best place I can point to is https://github.com/apache/superset/blob/master/superset/templates/superset/spa.html , like you'd have to dust off the jinja2 docs and figure out how to add a section like |
Beta Was this translation helpful? Give feedback.
-
I asked Claude Code to analyze this, here's what it came up with (after going nuts on SUPER complex solutions...) Simple Runtime Font Loading for SupersetYou're exactly right! The solution is quite straightforward: Implementation
CUSTOM_FONT_URLS = [
"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
"https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap"
]
# Update CSP to allow these domains
TALISMAN_CONFIG = {
"content_security_policy": {
"font-src": ["'self'", "https://fonts.googleapis.com", "https://fonts.gstatic.com"],
"style-src": ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
}
}
{% if config.CUSTOM_FONT_URLS %}
{% for font_url in config.CUSTOM_FONT_URLS %}
<link rel="stylesheet" href="{{ font_url }}">
{% endfor %}
{% endif %}
{
"token": {
"fontFamily": "Inter, -apple-system, BlinkMacSystemFont, sans-serif"
}
} How It Works
This gives Docker users custom fonts through simple configuration, while build users can still bundle fonts the traditional way. |
Beta Was this translation helpful? Give feedback.
-
Let me try to have AI generate a PR see how far it gets |
Beta Was this translation helpful? Give feedback.
-
Here #34416 |
Beta Was this translation helpful? Give feedback.
-
The documentation states:
Could you please provide a minimal working example of this setup? Specifically:
|
Beta Was this translation helpful? Give feedback.
Here #34416