Skip to content
✈️ TokenFlight SDK

Theming & Custom Colors

TokenFlight widgets ship with light and dark themes, plus an auto mode that follows the user’s system preference. You can further override any color via setCustomColors() or CSS variables.

<tokenflight-swap theme="dark"></tokenflight-swap>
<tokenflight-swap theme="light"></tokenflight-swap>
<tokenflight-swap theme="auto"></tokenflight-swap>
import { TokenFlightSwap } from '@tokenflight/swap';
const swap = new TokenFlightSwap({
container: '#swap',
config: { theme: 'auto' },
});
swap.initialize();

auto detects prefers-color-scheme: dark and picks accordingly.

swap.setTheme('light');
swap.setTheme('dark');
swap.setTheme('auto');

No re-initialization needed — the widget updates instantly.


Use setCustomColors() or the customColors config option to override any theme color.

const swap = new TokenFlightSwap({
container: '#swap',
config: {
theme: 'dark',
customColors: {
primary: '#FF6B00',
background: '#1A1A2E',
},
},
});
swap.initialize();
swap.setCustomColors({
primary: '#FF6B00',
background: '#1A1A2E',
textPrimary: '#FFFFFF',
border: '#2A2A4A',
});

These friendly names map to internal CSS variables:

KeyCSS VariableDescription
primary--tf-accentButtons, links, active states
background--tf-bgMain background
textPrimary--tf-textPrimary text
textSecondary--tf-text-secondaryLabels, hints
border--tf-borderBorders, dividers
success--tf-successSuccess states
error--tf-errorError states
warning--tf-warningWarning states

Any key not in the table above is converted to --tf-{key} automatically:

swap.setCustomColors({ 'bg-secondary': '#111' });
// sets --tf-bg-secondary

For full control, here are all variables the widgets reference. Override any of them via setCustomColors().

VariableLightDark
--tf-bg#ffffff#0d0f14
--tf-bg-secondary#f8f9fb#141720
--tf-surface#ffffff#181b25
--tf-surface-hover#f3f4f8#1e2230
--tf-input-bg#f5f6f8#141720
VariableLightDark
--tf-text#0f1419#eef0f6
--tf-text-secondary#5e6673#8a90a0
--tf-text-tertiary#9ba3af#555b6b
VariableLightDark
--tf-accent#6C5CE7#8B7CF6
--tf-accent-lightrgba(108,92,231,0.08)rgba(139,124,246,0.10)
--tf-success#00C48C#00D9A0
--tf-error#FF4757#FF5B6A
--tf-warning#FFAA00#FFB820
VariableLightDark
--tf-border#e8eaef#252836
--tf-border-light#f0f1f5#1e2230
--tf-shadow0 2px 16px rgba(0,0,0,0.06)…0 2px 16px rgba(0,0,0,0.3)…

const swap = new TokenFlightSwap({
container: '#swap',
config: {
theme: 'dark',
customColors: {
primary: '#E8396B', // brand pink
background: '#12121A', // deep bg
'bg-secondary': '#1A1A28',
'surface': '#1E1E2E',
border: '#2D2D44',
},
},
});
swap.initialize();
swap.setCustomColors({
primary: '#2563EB', // blue
background: '#FAFAFA',
border: '#E5E7EB',
'surface-hover': '#F3F4F6',
});