Style card payments fields

DocsCurrentAdvancedLast updated: October 18th 2021, @ 3:21:59 pm


Change the layout, width, height, and outer styling (for example, border, box-shadow, background) of the card fields. You can modify the elements you supply as containers (for example; #card-number { border: 1px solid #333; }) with your current stylesheets.

Typically, input elements calculate their height from font size and line height (and a few other properties), but advanced credit and debit card payments require explicit configuration of height. Make sure you style the height of your containers in your stylesheets. The text of the field components is configured with JavaScript.

Supported CSS properties

  • appearance
  • color
  • direction
  • font-family
  • font-size-adjustfont-size
  • font-stretch
  • font-style font-variant-alternates
  • font-variant-capsfont-variant-east-asian
  • font-variant-ligatures font-variant-numeric
  • font-variantfont-weight
  • font
  • letter-spacing
  • line-height
  • opacity
  • outline
  • padding
  • text-shadowtransition
  • -moz-appearance
  • -moz-osx-font-smoothing
  • -moz-tap-highlight-color
  • -moz-transition
  • -webkit-appearance
  • -webkit-font-smoothing
  • -webkit-tap-highlight-color
  • -webkit-transition

You must specify any other CSS on your page and outside of the advanced credit and debit card payments configuration. Setting unsupported properties will fail and create a warning in the console.

Custom classes

While advanced credit and debit card payments manages the internal state and styles of the input fields, you can manage the visual state of your containers. Use the styles parameter in the render() method under HostedFields to manage your container style.

The following example shows the styles parameter:

// ...
paypal.HostedFields.render({
      createOrder: getOrderId,
      styles: {
        'input': {
          'color': '#3A3A3A',
          'transition': 'color 160ms linear',
          '-webkit-transition': 'color 160ms linear'
        },
        ':focus': {
          'color': '#333333'
        },
        '.invalid': {
          'color': '#FF0000'
        }
        // field configuration here
      }
    });