Skip to content

Customization

Appearance config

Pass an appearance object when initializing the widget to customize its look:

const widget = new ElasticPayCardWidget("card-widget", {
apiUrl: "https://staging-api.elasticpay.co",
publishableKey: "pk_sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
clientSecret: "pi_0abc123_secret_xyz987",
appearance: {
variables: {
colorPrimary: "#2563eb",
colorBackground: "#ffffff",
colorText: "#111827",
colorDanger: "#dc2626",
fontFamily: "Inter, sans-serif",
fontSize: "16px",
labelFontSize: "14px",
inputFontSize: "16px",
borderRadius: "6px",
},
},
});

CSS variables reference

VariableDefaultDescription
colorPrimary#418FC1Button and focus ring color
colorBackground#ffffffInput background color
colorText#363434Input and label text color
colorDanger#cc4b37Error and invalid state color
fontFamilysystem-uiFont family for all widget text
fontSize16pxBase font size
labelFontSize14pxLabel font size
inputFontSize16pxInput field font size
borderRadius8pxBorder radius for inputs and buttons

CSS class overrides

For deeper customization, target these stable class names:

ClassElement
.elasticpay-card-widgetRoot container
.elasticpay-card-widget__inputCard input fields
.elasticpay-card-widget__input--validInput in valid state
.elasticpay-card-widget__input--invalidInput in invalid state
.elasticpay-card-widget__submitSubmit button
.elasticpay-card-widget__status--successSuccess message
.elasticpay-card-widget__status--errorError message

Example:

.elasticpay-card-widget__input {
border: 1px solid #d1d5db;
padding: 10px 12px;
}
.elasticpay-card-widget__input--invalid {
border-color: #dc2626;
}
.elasticpay-card-widget__submit {
background-color: #2563eb;
font-weight: 600;
}

Hide the submit button

Set showSubmitButton: false to hide the built-in submit button and trigger tokenization manually:

const widget = new ElasticPayCardWidget("card-widget", {
apiUrl: "https://staging-api.elasticpay.co",
publishableKey: "pk_sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
clientSecret: "pi_0abc123_secret_xyz987",
showSubmitButton: false,
});
document.getElementById("pay-button")?.addEventListener("click", async () => {
await widget.tokenize();
});

Use this when the submit button is outside the widget container, or when you need to validate other form fields before triggering payment.