Styling
Each element is actually mounted in an iframe under the hood. Because of this, Elements are unlikely to work with any existing styling and component frameworks that you may have. Despite this, you should still be able to fully configure an Element to seamlessly blend in with the rest of your site. Fully customizing Elements consists of configuring the Element with options, applying styles to the Element container, and responding to events.

Why iFrames?

We recognize that the use of iframes makes styling an Element more difficult, but they shift the burden of securely handling payment data to Stripe and provide an easy way to keep your site compliant with industry regulation.
1
import { Component, OnInit, ViewChild } from '@angular/core';
2
3
import { StripeCardComponent } from 'ngx-stripe';
4
import {
5
StripeCardElementOptions,
6
StripeElementsOptions
7
} from '@stripe/stripe-js';
8
9
@Component({
10
selector: 'app-styling-example',
11
template: `
12
<ngx-stripe-card [options]="cardOptions"></ngx-stripe-card>
13
`,
14
})
15
export class StylingExampleComponent {
16
@ViewChild(StripeCardComponent) card: StripeCardComponent;
17
18
cardOptions: StripeCardElementOptions = {
19
iconStyle: 'solid',
20
style: {
21
base: {
22
iconColor: '#c4f0ff',
23
color: '#fff',
24
fontWeight: 500,
25
fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif',
26
fontSize: '16px',
27
fontSmoothing: 'antialiased',
28
':-webkit-autofill': {color: '#fce883'},
29
'::placeholder': {color: '#87bbfd'}
30
},
31
invalid: {
32
iconColor: '#ffc7ee',
33
color: '#ffc7ee'
34
}
35
}
36
};
37
}
Copied!

Element Container

Style the container you mount an Element to as if it were an <input> on your page. For example, to control padding and border on an Element, set these properties on the container. This is usually done by re-using the classes that you have applied to your DOM <input> elements.
The Element Container API allows to specify a class name for container of the input in the iframe. You can set this using the option classes in the element options, or just use the containerClass in the element:
1
import { Component, OnInit, ViewChild } from '@angular/core';
2
3
import { StripeCardComponent } from 'ngx-stripe';
4
import {
5
StripeCardElementOptions,
6
StripeElementsOptions
7
} from '@stripe/stripe-js';
8
9
@Component({
10
selector: 'app-styling-example',
11
template: `
12
<ngx-stripe-card containerClass="example"></ngx-stripe-card>
13
`,
14
})
15
export class StylingExampleComponent {
16
@ViewChild(StripeCardComponent) card: StripeCardComponent;
17
}
Copied!
The default value is StripeElement, and there are also some subclasses:
  • .StripeElement--complete
  • .StripeElement--empty
  • .StripeElement--focus
  • .StripeElement--invalid
  • .StripeElement--webkit-autofill (Chrome and Safari only)
Last modified 1yr ago
Copy link