## Collecting Customer Addresses for Tax Calculation

Stripe Tax requires your customer's location to automatically calculate tax. This requirement applies even if you don’t have an active registration. This guide helps you understand how to collect addresses from your customers.

### Which Customer Address We Use

Stripe Tax uses a single address as your customer’s location when calculating tax. How we choose an address doesn’t depend on the type of product you sell.

You can see which location an automatic tax calculated payment used in the Tax calculation section of the Transactions details page in your Dashboard.

You can also review the `tax.location.source` field on the Customer API object.

*   **Checkout and Payment Links:** Checkout and Payment Links use the address collected during the session.
*   **Invoicing, Subscriptions, and custom payment integrations:** We use the first viable item in the list below to determine your customer’s location:
    *   We use your customer’s shipping address, if present. If a shipping address is present but invalid, we raise a `customer_tax_location_invalid` error instead of trying the next address in this list.
    *   We use your customer’s billing address, if present. If a billing address is present but invalid, we raise a `customer_tax_location_invalid` error instead of trying the next address in the

### Collecting Addresses

#### Address Element

The Address Element is a prebuilt UI component that collects an address from your customer. It includes features like:

*   **Autocomplete:** Helps customers enter their address faster and more accurately.
*   **Localization:** Adapts to the customer’s language and region.
*   **Validation:** Ensures the address is in a valid format.

To use the Address Element, you need to:

1.  **Create an Address Element:**
    ```javascript
    const addressElement = elements.create('address', {
      mode: 'billing', // or 'shipping', if you are shipping goods
    });
    ```
2.  **Mount the Address Element to your page:**
    ```javascript
    addressElement.mount('#address-element');
    ```
3.  **Listen for changes to the address:** When the address changes, you can re-estimate taxes and update the total.
    ```javascript
    addressElement.on('change', function(event) {
      // Throttle your requests to avoid overloading your server or hitting
      // Stripe's rate limits.
      const { tax, total } = event;
      // Update your UI with the new tax and total
    });
    ```

#### Custom Form

If you prefer to build your own address form, you can collect the address details using your own HTML elements and then pass them to the Stripe Tax API to calculate tax.

You'll need to collect the following fields:

*   `country`
*   `state`
*   `city`
*   `postal_code`
*   `line1` (street address)

#### IP Address

In some cases, you can estimate a customer’s location using their IP address. This is particularly useful for initial tax estimations before a customer provides their full address. However, IP address-based location is less precise and should not be relied upon for final tax calculations.

To use IP address for tax estimation, you can pass the `customer_details.tax.ip_address` parameter when creating a preview invoice or calculating tax.

### Validating Addresses

Before calculating tax, it’s important to ensure that the address provided by your customer is precise enough for accurate tax calculation. Some addresses, like a US postal code, might span multiple tax jurisdictions.

You can use the [Address Resolution API](https://stripe.com/docs/api/tax/address_resolution) to check the precision level of an address and identify any missing information needed for accurate tax calculation.

### Next Steps

*   [Specify product tax codes and tax behavior](https://stripe.com/docs/tax/products-prices-tax-codes-tax-behavior)
*   [Validate addresses](https://stripe.com/docs/tax/address-resolution)
*   [Define customizations](https://stripe.com/docs/tax/tax-customizations)