Skip to Content
Checkout · Altruon.js

Style the component

Set the colors, corner radius, font and shadow of the Altruon.js component with styleCustomization when you create the session.

You style the Altruon.js component from your server. Add a styleCustomization object to the Create Session request and the component renders with those styles. There is nothing to configure in the browser.

How styling works
  1. Your server
    Create the session
    Add styleCustomization to the request body.
  2. Altruon
    Keeps the styles
    The styles are stored with the session.
  3. Browser
    Render the component
    renderComponent() applies them automatically.
Styles belong to the session, so every payment method in the component uses them.

Altruon.js only

styleCustomization styles the embedded component. Hosted pages and dynamic hosted checkout take their appearance from Settings > Checkout in the backoffice.

Style a session

Add styleCustomization to the session

Every property is optional. This example sets two of them. The rest keep their defaults.

server.js
body: JSON.stringify({
  paymentData: { currency: 'USD' },
  redirectUrl: 'https://yourdomain.com/success',
  billingData: {
    lineItems: [{ type: 'plan', id: process.env.PLAN_ID, quantity: 1 }],
    billingPlatformId: process.env.BILLING_PLATFORM_ID,
  },
  styleCustomization: { accentColor: '#6366F1', borderRadius: '10px' }, 
}),

Render the component as usual

The browser code does not change. The session already has the styles.

altruon.setSession(sessionId);
altruon.renderComponent('#altruon-payment-container');

Check the result

Open your checkout page. The annotated example below shows which part of the component each property changes.

The Altruon.js component showing a UPI form, with arrows naming the style property behind each part: backgroundColor around the component, primaryColor on the header bar and input borders, secondaryColor on the form panel, accentColor on the selected method marker, headerTextColor and fontFamily on the method title, textColor on labels and placeholders, borderRadius on the corners and dropShadow under the panel
Which property styles which part of the component

Style options lists all nine properties with their types and defaults.

Theme recipes

The merchant demo maps its storefront branding onto the component, so the component looks like part of the host page.

server/src/routes.js
function buildStyleCustomization(branding = {}) {
  return {
    backgroundColor: '#FFFFFF',
    primaryColor: '#E2E8F0', // input borders and dividers inside the component
    secondaryColor: '#FFFFFF',
    accentColor: branding.primaryColor || '#6366F1', // buttons and focus states
    borderRadius: '10px',
    headerTextColor: '#0F172A',
    textColor: '#0F172A',
    fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
    dropShadow: false,
  };
}

More complete themes are in Style options.

Different styles per plan

Styles are set per session, so your server can choose them at runtime: by plan, by shopper type or by the page the shopper came from.

server.js
const themes = {
  basic: { accentColor: '#9CA3AF', borderRadius: '4px', dropShadow: false },
  premium: { accentColor: '#60A5FA', borderRadius: '8px', dropShadow: true },
  enterprise: { backgroundColor: '#1F2937', textColor: '#F3F4F6', accentColor: '#FBBF24', borderRadius: '12px' },
};

app.post('/create-checkout-session', async (req, res) => {
  const styleCustomization = themes[req.body.planType] || themes.basic;
  // Send styleCustomization in the Create Session request body.
});

Language

The language of the component is also set on the session, with the locale field. See Create a session.

Accessibility and fonts

  • Contrast. Keep at least the WCAG AA ratio of 4.5:1 between textColor and backgroundColor. Dark text such as #1F2937 on #FFFFFF passes. Light gray text such as #D1D1D1 on #EFEFEF does not.
  • Focus states. accentColor marks the focused field. Choose a value that stays visible against backgroundColor.
  • Font fallbacks. Give fontFamily a list, not a single font: '"YourBrandFont", Arial, sans-serif'. If the custom font is unavailable, the next one is used.
  • Custom fonts. Load the font on your page before you render the component.
  • System fonts. A system stack such as system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif needs no download and performs best.

Test it

Create one session per theme you want to compare, then check each one:

  • Colors match what you set and text is readable.
  • The font loads.
  • The corner radius applies to all elements, and the shadow shows if you enabled it.
  • The component looks right in Chrome, Firefox, Safari and Edge, on iOS and Android, at different screen sizes, and with light and dark system themes.

Troubleshooting

Next steps