Stripe Elements Google Web Font Not Working
I can't get Stripe Elements to use Google Lato. I know there are other questions like this, but I don't see anything that applies. I tried to fix this for a while with no luck
var windowHash = getWindowHash();
var stripe = Stripe(stripePubKey);
var elements = stripe.elements({
fonts: [
{
family: "'Lato'",
src: 'local("Lato"), local("lato"), url(https://fonts.gstatic.com/s/lato/v13/dPJ5r9gl3kK6ijoeP1IRsvY6323mHUZFJMgTvxaG2iE.woff2) format("woff2")',
weight: 300,
style: "normal",
unicodeRange: "U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF"
}
]
});
var card = elements.create('card', {
iconStyle: 'solid',
hidePostalCode: true,
style: {
base: {
iconColor: '#3cacce',
color: '#424B54',
lineHeight: '36px',
fontWeight: 300,
fontFamily: '"Lato", sans-serif',
fontSize: '13pt',
fontStyle: "normal",
'::placeholder': {
color: '#969696'
},
},
invalid: {
iconColor: '#b32903',
color: '#b32903',
}
},
classes: {
focus: 'is-focused',
empty: 'is-empty',
},
});
And somewhere else:
card.mount('.cardElement');
Any advice on how I can display this image correctly?
Update:
Found the problem! I tried to load in Lato Light but since the normal Lato was added using 300 wight didn't work. Adding the Lato Light font made it work.
source to share
Reason: You must use a
latin
Unicode reference and range. Notlatin-ext
font face for latin font (latin and latin-ext)
Use the following font options
fonts: [
{
family: '"Lato"',
src: 'local("Lato Regular"), local("Lato-Regular"), url(https://fonts.gstatic.com/s/lato/v13/MDadn8DQ_3oT6kvnUq_2r_esZW2xOQ-xsNqO47m55DA.woff2) format("woff2")',
weight: 300,
style: 'normal',
unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215'
}
]
source to share
Now you can use the cssSrc option:
let stripe = Stripe('pk_test_JYjfAwsv9ODbL7mm1qObrIXZ')
let elements = stripe.elements({
fonts: [
{
cssSrc: 'https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600'
}
]
})
Then you can refer to it in the style parameters when creating the map:
let card = elements.create('card', {
style: {
base: {
fontFamily: 'Montserrat'
}
}
})
card.mount('#card-element')
source to share