Customize the Card Entry Form

Applies to: Web Payments SDK

Learn how to apply custom styles to the Web Payments SDK card payment form.

Link to section

Overview

The Web Payments SDK lets you customize the style of the card entry and gift card entry forms. The following sections show the available style choices, how to set them, and what the resulting form looks like. You can see several customization ideas by viewing the Design Showcase sample on GitHub.

The following steps add code to the application you created from the quickstart project sample. If you haven't created an application using the quickstart, you need to do so before completing these steps. You can find a complete example of the customized card on GitHub.

You can view the supported stylesheet classes and properties in the CardClassSelectors object API Reference.

The five visual elements of the Card payment method are represented as selectors that you specify in a card option styling object. You can set colors, fonts, and border options as shown in the following image:

A graphic showing the five visual elements of the Card payment method, which are represented as selectors that you specify in a card option styling object.

Link to section

Configure a customized Card payment method

The following steps produce the dark mode card previously shown.

Link to section

Step 1: Add a dark mode style to the page

  1. Add a reference to the dark-mode css class to the body of the page.

    <body class="dark-mode"> <form id="payment-form"> <div id="card-container"></div> </form> </body>
  2. Add a * tag after the current <link href="app.css" rel="stylesheet" /> in the header to add dark-mode.css.

    <link href="dark-mode.css" rel="stylesheet" />
Link to section

Step 2: Define a custom style

Declare style customizing options in the CardOptions object. The style field value is of the CardClassSelectors type.

Link to section

Step 3: Initialize the Card payment method with a custom style

Add the style parameter to the payments.card function call.

async function initializeCard(payments) { const card = await payments.card({ style: darkModeCardStyle, }); await card.attach('#card-container'); return card; }
Link to section

Dynamic layout

Your application and the buyer's actions determine whether the form is shown as a single line or a two-line form. If your application has styled the <d​iv> that the form is attached to as a fixed width of less than 480 pixels, the form is rendered as two lines. If the <d​iv> is declared with minimum and maximum widths that let the buyer resize the page, the form reacts to a wider <d​iv> container by rendering as a single line.

Link to section

See also