Skip to main content

Primer Checkout Styling API

Primer Checkout uses styling variables (implemented as CSS Variables) to maintain a consistent design language across components. These variables provide a standardized way to customize the appearance of your checkout UI.

Styling Methods

You can apply styling in two ways:

CSS Variables Method
JSON Properties Method
/* Apply styling directly in your CSS */
primer-checkout {
--primer-color-brand: #2f98ff;
--primer-radius-medium: 8px;
--primer-typography-brand: 'Inter', sans-serif;

}

<!-- Apply styling through component attributes -->
<primer-checkout
customStyles='{"primerColorBrand":"#2f98ff","primerRadiusMedium":"8px"}'
></primer-checkout>

CSS to JSON Conversion

When using the JSON method, convert kebab-case CSS variables to camelCase properties:

  1. Remove the leading dashes (--)
  2. Convert hyphens to camelCase by removing the hyphen and capitalizing the next letter

Examples:

  • --primer-color-brandprimerColorBrand
  • --primer-space-mediumprimerSpaceMedium
  • --primer-typography-body-large-fontprimerTypographyBodyLargeFont

Core Styling Variables

These variables control the fundamental aspects of your checkout UI, from colors to spacing.

CSS VariableTypeDescriptionDefault ValueAffects
--primer-color-brandcolorControls the brand color across the checkout.#2F98FFBackground color in primary primer-button, Focus outline in all components
--primer-typography-brandfont familyControls the brand font family across the checkout.InterAll typography styles
--primer-color-backgroundcolorControls the background color across the checkout.#FFFFFFDefault background color in all components except the primary primer-button
--primer-color-focuscolorControls the interactive focus color across the checkout.var(--primer-color-brand)Focus outline in all components

Text Colors

CSS VariableTypeDescriptionDefault ValueAffects
--primer-color-text-primarycolorControls the primary text color across the checkout.#212121Secondary/Tertiary primer-button label text, primer-input input text, primer-input-label text
--primer-color-text-placeholdercolorControls the placeholder text color across the checkout.#9E9E9Eprimer-input placeholder text
--primer-color-text-disabledcolorControls the disabled text color across the checkout.#BDBDBD(In disabled state) Secondary/Tertiary primer-button label text, primer-input input text, primer-input-label text
--primer-color-text-negativecolorControls the negative text color across the checkout.#B4324Bprimer-input-error text in primer-input

Border Radius

CSS VariableTypeDescriptionDefault ValueAffects
--primer-radius-smallradiusControls the small border radius across the checkout.4pxprimer-input-wrapper
--primer-radius-mediumradiusControls the medium border radius across the checkout.8pxPrimary/Secondary primer-button

Spacing

CSS VariableTypeDescriptionDefault ValueAffects
--primer-space-xsmallspacingControls the x-small spacing across the checkout.4pxprimer-input-wrapper (Spacing between primer-input-label & primer-input)
--primer-space-smallspacingControls the small spacing across the checkout.8pxprimer-card-form, primer-input-card-number
--primer-space-mediumspacingControls the medium spacing across the checkout.12pxPaddings in primer-button, primer-input-wrapper, Spacings inside primer-card-form

Typography

The following variables control text appearance across components, ensuring consistent text styling and readability.

Title Large

CSS VariableTypeDescriptionDefault ValueAffects
--primer-typography-title-large-fontfont familyControls the font family of the title-large typography style.var(--primer-typography-brand)Primary/Secondary/Tertiary primer-button label text
--primer-typography-title-large-weightfont weightControls the font weight of the title-large typography style.550Primary/Secondary/Tertiary primer-button label text
--primer-typography-title-large-sizefont sizeControls the font size of the title-large typography style.16pxPrimary/Secondary/Tertiary primer-button label text
--primer-typography-title-large-line-heightline heightControls the line height of the title-large typography style.20pxPrimary/Secondary/Tertiary primer-button label text
--primer-typography-title-large-letter-spacingletter spacingControls the letter spacing of the title-large typography style.-0.2pxPrimary/Secondary/Tertiary primer-button label text

Body Large

CSS VariableTypeDescriptionDefault ValueAffects
--primer-typography-body-large-fontfont familyControls the font family of the body-large typography style.var(--primer-typography-brand)Input/Placeholder text in primer-input
--primer-typography-body-large-weightfont weightControls the font weight of the body-large typography style.400Input/Placeholder text in primer-input
--primer-typography-body-large-sizefont sizeControls the font size of the body-large typography style.16pxInput/Placeholder text in primer-input
--primer-typography-body-large-line-heightline heightControls the line height of the body-large typography style.20pxInput/Placeholder text in primer-input
--primer-typography-body-large-letter-spacingletter spacingControls the letter spacing of the body-large typography style.-0.2pxInput/Placeholder text in primer-input

Body Small

CSS VariableTypeDescriptionDefault ValueAffects
--primer-typography-body-small-fontfont familyControls the font family of the body-small typography style.var(--primer-typography-brand)primer-input-error, primer-input-label
--primer-typography-body-small-weightfont weightControls the font weight of the body-small typography style.400primer-input-error, primer-input-label
--primer-typography-body-small-sizefont sizeControls the font size of the body-small typography style.12pxprimer-input-error, primer-input-label
--primer-typography-body-small-line-heightline heightControls the line height of the body-small typography style.16pxprimer-input-error, primer-input-label
--primer-typography-body-small-letter-spacingletter spacingControls the letter spacing of the body-small typography style.0primer-input-error, primer-input-label

Outlined Container

These styling variables control the appearance of outlined containers like input wrappers and buttons.

Background Properties

CSS VariableTypeDescriptionDefault ValueAffects
--primer-color-background-outlined-defaultcolorControls the background color of the outlined container in default state.var(--primer-color-background)(In default state) Background color in primer-input-wrapper, secondary primer-button
--primer-color-background-outlined-hovercolorControls the background color of the outlined container in hover state.var(--primer-color-background-outlined-default)(In hover state) Background color in primer-input-wrapper, secondary primer-button
--primer-color-background-outlined-activecolorControls the background color of the outlined container in active state.var(--primer-color-background-outlined-default)(In active state) Background color in primer-input-wrapper, secondary primer-button
--primer-color-background-outlined-errorcolorControls the background color of the outlined container in error state.var(--primer-color-background-outlined-default)(In error state) Background color in primer-input-wrapper
--primer-color-background-outlined-disabledcolorControls the background color of the outlined container in disabled state.#F5F5F5(In disabled state) Background color in primer-input-wrapper, secondary primer-button

Border Properties

CSS VariableTypeDescriptionDefault ValueAffects
--primer-color-border-outlined-defaultcolorControls the border color of the outlined container in default state.#E0E0E0(In default state) Border color in primer-input-wrapper, secondary primer-button
--primer-color-border-outlined-hovercolorControls the border color of the outlined container in hover state.#BDBDBD(In hover state) Border color in primer-input-wrapper, secondary primer-button
--primer-color-border-outlined-activecolorControls the border color of the outlined container in active state.#9E9E9E(In active state) Border color in primer-input-wrapper, secondary primer-button
--primer-color-border-outlined-focuscolorControls the border color of the outlined container in focus state.var(--primer-color-focus)(In focus state) Border color in primer-input-wrapper, secondary primer-button
--primer-color-border-outlined-errorcolorControls the border color of the outlined container in error state.#FF7279(In error state) Border color in primer-input-wrapper, secondary primer-button
--primer-color-border-outlined-disabledcolorControls the border color of the outlined container in disabled state.#EEEEEE(In disabled state) Border color in primer-input-wrapper, secondary primer-button

Using Styling Variables in Practice

CSS Variables Method

Implementation Options

You can target specific components or apply global styling to all components in your checkout experience.

/* Customizing all components */
:root {
/* Colors */
--primer-color-brand: #663399;
--primer-color-text-primary: #333333;

/* Typography */
--primer-typography-body-large-font: 'Helvetica Neue', sans-serif;

/* Spacing */
--primer-space-medium: 16px;

/* Border Radius */
--primer-radius-medium: 8px;
}

JSON Properties Method

This approach is particularly useful when working with JavaScript frameworks or when you need to apply styling variables programmatically.

// Create a styling object
const myCustomStyles = {
primerColorBrand: '#663399',
primerColorTextPrimary: '#333333',
primerTypographyBodyLargeFont: 'Helvetica Neue, sans-serif',
primerSpaceMedium: '16px',
primerRadiusMedium: '8px',
};

// Apply to component
const checkoutElement = document.querySelector('primer-checkout');
checkoutElement.setAttribute('customStyles', JSON.stringify(myCustomStyles));

The component will parse the JSON and automatically apply the styles as CSS Variables internally.

Theme Support

Primer Checkout supports both light (default) and dark themes using CSS classes:

<!-- Add the theme class to your checkout container -->
<primer-checkout client-token="your-client-token" class="primer-dark-theme">
<!-- Your checkout content -->
</primer-checkout>

You can toggle between themes using JavaScript:

// Function to toggle between themes
function toggleTheme(isDark) {
const container = document.querySelector('primer-checkout');
container.className = isDark ? 'primer-dark-theme' : 'primer-light-theme';
}

// Examples
toggleTheme(true); // Switch to dark theme
toggleTheme(false); // Switch to light theme

This approach allows you to support both light and dark themes, toggling between them as needed.