# Collect tax IDs with the Tax ID Element

Use the Tax ID Element with the Checkout Sessions API to collect business tax IDs.

Use the Tax ID Element in your Elements integration with the Checkout Sessions API to collect your customer’s business tax ID. To learn how the Tax ID Element works, including supported regions and visibility behavior, see the [Tax ID Element overview](https://docs.stripe.com/elements/tax-id-element.md).

## Create a Tax ID Element

Here’s how you can use the [Tax ID Element](https://docs.stripe.com/js/custom_checkout/create_tax_id_element) with the Checkout Sessions API to collect tax IDs:

```html
<div class="tax-id-form">
  <div id="tax-id-element"></div>
</div>
```

```javascript
const stripe = window.Stripe('<<YOUR_PUBLISHABLE_KEY>>');
const appearance = { /* appearance */ };
const elementsOptions = { appearance };

const clientSecret = fetch('/create-checkout-session', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  })
    .then((res) => res.json())
    .then((res) => {
      return res.clientSecret;
    });

const checkout = stripe.initCheckoutElementsSdk({
  clientSecret,
  elementsOptions
});

const taxIdElementOptions = {
  visibility: 'always',
};
const taxIdElement = checkout.createTaxIdElement(taxIdElementOptions);
taxIdElement.mount('#tax-id-element');
```

For more information about using the Tax ID Element with Checkout Sessions, see the [Checkout Sessions integration guide](https://docs.stripe.com/tax/checkout/tax-ids.md#enable-tax-id-collection).

## Control visibility with name_collection

When `name_collection.business.enabled` is `true` on the Checkout Session and the Tax ID Element is mounted, the Tax ID Element visibility changes based on how you configure the `fields.businessName` option.

If you don’t explicitly set `visibility`: `never` or `fields.businessName`: `never`, the SDK automatically overrides the following options:

- `visibility`: `always`: The element always displays regardless of the customer’s country and overrides `auto`.
- `fields.businessName`: `always`: The business name row always renders within the element.
- `validation.businessName.required`: `always`: This applies only when `name_collection.business.optional`: `false`. Stripe preserves your `validation.businessName.required` setting when `optional`: `true`.

In this case, the Tax ID Element collects the business name. If you also call `updateBusinessName()`, calling `confirm()` throws an error. To avoid this, unmount the Tax ID Element before calling `updateBusinessName()`. For customers in countries with no supported tax ID type, the tax ID type and value fields are hidden, and only the business name field is shown.

If you explicitly set `fields.businessName` to `never` or `visibility` to `never`, the SDK respects your choice and doesn’t apply overrides. In this case, collect the business name through your own input with `updateBusinessName()`.

## Real-time tax ID validation

> #### Eligibility
> 
> To use this feature, you need a [Tax Complete subscription or Tax Custom pricing](https://stripe.com/tax/pricing).

In addition to the asynchronous validation described above, you can enable synchronous, real-time tax ID verification directly in the Tax ID Element. When you enable it, Stripe verifies tax IDs against government databases as your customer types and displays the result inline before they submit the payment. Stripe currently supports real-time verification for [Australian Business Numbers (ABNs)](https://docs.stripe.com/tax/invoicing/tax-ids.md#australian-business-numbers-abn), [European Value Added Tax (EU VAT)](https://docs.stripe.com/tax/invoicing/tax-ids.md#european-value-added-tax-eu-vat-numbers), and [United Kingdom Value Added Tax (GB VAT)](https://docs.stripe.com/tax/invoicing/tax-ids.md#united-kingdom-value-added-tax-gb-vat-numbers) numbers. If a government database is unavailable, Stripe falls back to synchronous format validation and performs full verification asynchronously.

```javascript
const taxIdElement = checkout.createTaxIdElement({
  ...
  verification: {
    taxId: {
      mode: 'if_supported',
    },
  },
});
```

When you enable verification, the `change` event includes the `verification.taxId.status` field. Its value can be `pending`, `verified`, `unverified`, or `unavailable`. The element’s `complete` status reflects the verification result. See [Create a Tax ID Element](https://docs.stripe.com/js/custom_checkout/create_tax_id_element#custom_checkout_create_tax_id_element-options-verification) and [Tax ID Element on Change](https://docs.stripe.com/js/custom_checkout/element_events/on_change?type=taxIdElement#custom_checkout_element_on_change-handler-verification) for details.
