# 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()`.
