Customize the width of the Square payment form by changing the default CSS styles.
Square Payment Form

Customize Payment Form Appearance Deprecated
This component is deprecated. See below for guidance about what to use instead.


The Square payment form is deprecated and replaced by the Web Payments SDK.

You should use the Web Payments SDK to take payments on a web client. The Web Payments SDK uses modern web styling 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.

The SqPaymentForm library offers two ways to configure a payment form in your website:

  • Multi-element payment form. You build the payment form with multiple DOM elements and map each element to a SqPaymentForm configuration field (cardNumber, cvv, expirationDate, and postalCode).

  • Single-element payment form. You build the payment form with one DOM element and map it to the card configuration field provided by the SqPaymentForm library.

Overview Permalink Get a link to this section

The following example shows the two ways you can configure a payment form:

A graphic showing the two optional payment entry form layouts available with the SqpaymentForm library.

For an example, see Walkthrough: Integrate Square Payments in a Website. The topics explain what the library does for the look and feel of the payment form and how you might customize it to conform to your page styles.

Customize the appearance of the multi-element payment form Permalink Get a link to this section

The SqPaymentForm library renders HTML input elements inside iframes. When you want to customize the appearance of these inputs, note the following caveat:

  • An iframe is an element in your HTML page and therefore you can customize the iframe styles (for example, customize the height of the iframe and the border drawn around the iframe).

  • However, the area where buyers enter information (such as a card number or expiration date) is Square's HTML within the iframe that your CSS cannot customize. Instead, you direct the SqPaymentForm library to customize this portion.

For example, if you inspect any of the payment form elements in your browser, you see the HTML page containing <iframe> elements in the <body>. Each <iframe> element has an <html> child (Square's HTML) that contains the <input> element. The following is an example HTML fragment:

Therefore, to customize the appearance of the multi-element payment form, the SqPaymentForm library provides the following two configuration fields:

  • inputClass. Identifies the CSS class name. You declare the class somewhere in your project and reference the containing .css file in the HTML head section. The library uses the specified CSS class to customize styles of the iframe element.

  • inputStyles. An array of InputStyle objects that provide styles that the library uses to customize the <input> rendered inside the iframe. The library supports a set of styles to choose for this customization.

You specify these configuration fields when you initialize the SqPaymentForm object.

Multi-element payment form example Permalink Get a link to this section

To explore customization of the multi-element payment form appearance, do the following:

  1. Complete the SqPaymentForm walkthrough to create a multi-element payment form. For more information, see Walkthrough: Integrate Square Payments in a Website. Do not follow the additional steps provided at the end of the walkthrough to build a single-element payment.

  2. Review the following code components:

    • Layout of the iframe elements. You see the following layout of the SqPaymentForm iframe elements:

      A graphic showing a typical credit card input layout for SqPaymentForm integrations, without a payment button.

      This layout is defined by the following <div> block in index.html. Three of the iframe elements (sq-expiration-date, CVV, and sq-postal-code) specify a class (third). The styles defined in the class cause the elements to appear on the same line.

      If you inspect these payment form elements in your browser, you see the corresponding iframe elements with the class attribute showing the third class.

    • Customize iframe styles. In index.html, the SqPaymentForm initialization specifies the inputClass configuration field that sets the CSS class to use for the iframe styles.

      The sq-input class is defined in the mysqpaymentform.css file as follows:

      You can explore customization by changing these CSS styles and review the resulting payment form.

    • Customize the input styles within the iframe. The SqPaymentForm initialization specifies the inputStyles configuration field to define custom styles for the <input> element in the iframe.

      The style applies to all four SqPaymentForm input fields in the iframes. The inputStyles defines the internal styles applied to the rendered iframes. For a list of input style properties that SqPaymentForm supports, see InputStyle.

Customize the appearance of the single-element payment form Permalink Get a link to this section

To build the single-element payment form, you use the card configuration field of SqPaymentForm. The look and feel you get is defined by the default CSS configuration the library provides with the card element. You can optionally customize the appearance using card.inputStyle (of the InputStyle type) as described in this section.

The following example shows a single-element payment form with custom styles and highlights the components you can customize:

A graphic showing the UI elements for a customizable payment card entry form.

As the example shows, you can customize:

  • The payment form background color, shape, and other attributes.

  • The font and color of the placeholder text.

  • The font and color of text as users enter information.

  • The font and color of user data input errors for the following:

    • Incorrect user data text

    • Helper text message

Single-element payment form example Permalink Get a link to this section

If you want to test the custom styling of the single-element payment form using the card.inputStyle, do the following:

  1. Complete the SqPaymentForm example walkthrough. For more information, see Walkthrough: Integrate Square Payments in a Website. The resulting payment form you see uses the default CSS styling that the card configuration element provides. You can now apply custom styles.

  2. Set the background color of the page.

    1. Open mysqpaymentform.css.

    2. Set the background color of the page.

  3. Add custom styles so the payment form appears as shown in the preceding example. Open index.html and add the card.inputStyle configuration field as shown:

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
      elementId: 'sq-card',
        //Set font attributes on card entry fields
        fontSize: '16px',
        fontWeight: 500,
        fontFamily: 'futura',
        placeholderFontWeight: 300,
        autoFillColor: '#FFFFFF',    //Sets color of card nbr & exp. date
        color: '#FFFFFF',            //Sets color of CVV & Zip
        placeholderColor: '#A5A5A5', //Sets placeholder text color
        //Set form appearance
        backgroundColor: '#000',  //Card entry background color
        cardIconColor: '#A5A5A5', //Card Icon color
        borderRadius: '50px',
        boxShadow: "0px 2px 6px rgba(0,0,0,.02)," +
          "0px 4px 8px rgba(0,0,0, 0.04), 0px 8px 30px " +
          "rgba(0,0,0, 0.04), 0px 1px 2px rgba(0,0,0, 0.08)",
        //Set form appearance in error state
          cardIconColor: '#FF1ADA', //Sets color of card icon
          color: '#FF4DB8',         //Sets color of card entry text
          backgroundColor: '#000',  //Card entry background color
          fontWeight: 500,
          fontFamily: 'futura'      //Font of the input field in error
        //Set appearance of hint text below form
          hidden: false,    //Shows or hides hint text
          color: '#A5A5A5', //Sets hint text color
          fontSize: '12px', //Not inherited from parent, Sets size of
          //text, defaults to 12px
          fontWeight: 500,  //Not inherited from parent
          fontFamily: 'futura', //Not inherited from parent, required to render form
          { //Sets attributes of hint text in when form
            color: '#FF4DB8', //is in error state
            fontSize: '12px'

Test the application and you see the payment form with the custom styles you specified.

If you need more assistance, contact Developer Support or ask for help in the Developer Forums.