Skip to content

yp.js: Appearance

The form is a <yp-root> custom element. It renders in a shadow DOM, so your page styles do not leak into it. You theme it in three ways: the appearance option, CSS custom properties, and shadow parts. The default theme is light with a blue accent.

Appearance Option

Pass appearance to elements(). It has two fields.

FieldTypeDescription
variablesobject, optionalDesign tokens. Each key maps to a --yp- custom property. { primary: '#335cff' } sets --yp-primary.
rulesstring, optionalRaw CSS applied inside the form. Use it for fine styling that the tokens do not cover.
js
yp('pub_xxx').elements({
  token: 'token_xxx',
  container: '#payment',
  appearance: {
    variables: {
      'primary': '#335cff',
      'radius': '12px',
      'font': 'Poppins, sans-serif',
    },
    rules: `[part="button"] { text-transform: uppercase; }`,
  },
});

Custom Properties

Set any --yp-* property on the yp-root element to override a token.

PropertyDescription
--yp-primaryAccent color for buttons and focus.
--yp-primary-hoverAccent color on hover.
--yp-primary-foregroundText color on the accent.
--yp-backgroundForm background.
--yp-cardCard surface.
--yp-foregroundMain text color.
--yp-muted-foregroundSecondary text color.
--yp-borderBorder color.
--yp-destructiveError color.
--yp-successSuccess color.
--yp-ringFocus ring color.
--yp-radiusCorner radius. --yp-radius-sm and --yp-radius-lg follow it.
--yp-fontFont family.
css
yp-root {
  --yp-primary: #335cff;
  --yp-radius: 12px;
}

Shadow Parts

Target inner elements from your page with ::part().

css
yp-root::part(input) {
  border-width: 2px;
}

yp-root::part(button) {
  letter-spacing: 0.02em;
}

Available parts: widget, selector, form, field, label, input, hint, error, button, dialog, overlay, loader, help, guide, sandbox, code.

Dark Theme

Set data-theme="dark" on the yp-root element. The form reads it and switches. The element is created during mount(), so set the attribute after the ready event.

js
const payment = yp('pub_xxx').elements({ token: 'token_xxx', container: '#payment' });

payment.on('ready', () => {
  document.querySelector('#payment yp-root').setAttribute('data-theme', 'dark');
});

payment.mount();