---
schema_version: "1"
id: 61d9815d1e4b40f0709391b1862489bd3140de4efc2229a4f2853262acfec2fa
title: Component IDs
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/components/components-ids.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/components-ids.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a9db70ec42f87f54743b4a9cfe58dd533d0ecdcf195c551e4d827ef21fc65102
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Component IDs

A component has two types of IDs: a local ID and a global ID. You can retrieve a component using its local ID in your JavaScript code. A global ID can be useful to differentiate between multiple instances of a component or for debugging purposes.

## Local IDs

A local ID is an ID that is only scoped to the component. A local ID is often unique but it’s not required to be unique.

Create a local ID by using the `aura:id` attribute. For example:

<!-- otherprops: set_clipboard -->
```nolang
<lightning:button aura:id="button1" label="button1"/>

```

**note:** `aura:id` doesn't support expressions. You can only assign literal string values to `aura:id`.

Find the button component by calling `cmp.find("button1")` in your client-side controller, where `cmp` is a reference to the component containing the button.

`find()` returns different types depending on the result.

-   If the local ID is unique, `find()` returns the component.
-   If there are multiple components with the same local ID, `find()` returns an array of the components.
-   If there is no matching local ID, `find()` returns `undefined`.

To find the local ID for a component in JavaScript, use `cmp.getLocalId()`.

## Global IDs

Every component has a unique `globalId`, which is the generated runtime-unique ID of the component instance. A global ID (1) is not guaranteed to be the same beyond the lifetime of a component, so it should never be relied on. A global ID can be useful to differentiate between multiple instances of a component or for debugging purposes.

![Every component has a unique global ID.](https://developer.salesforce.com/media/aura-platform/globalID.png)

To create a unique ID for an HTML element, you can use the `globalId` as a prefix or suffix for your element. For example:

<!-- otherprops: set_clipboard -->
```nolang
<div id="{!globalId + '_footer'}"></div>
```

In your browser’s developer console, retrieve the element using `document.getElementById("<globalId>_footer")`, where `<globalId>` is the generated runtime-unique ID.

To retrieve a component’s global ID in JavaScript, use the `getGlobalId()` function.

<!-- otherprops: set_clipboard -->
```javascript
var globalId = cmp.getGlobalId();
```

**See Also**  


-   [Finding Components by ID](https://developer.salesforce.com/docs/platform/aura-platform/js-cb/js-cb-find-by-id.md)
-   [Which Button Was Pressed?](https://developer.salesforce.com/docs/platform/aura-platform/js-cb/js-cb-which-button-pressed.md)

