Lightning Components · June 28, 2023
What is aura:attribute and What Are the Types?
aura:attribute is how you define typed variables inside a Salesforce Lightning (Aura) component. They let you pass data into components, hold state, and bind values to the UI — similar to props and state in React.
What is aura:attribute?
An aura:attribute is a typed variable declared on a Lightning component. It defines what data a component can accept and store. Attributes act as the component's data model — any change to an attribute automatically re-renders the bound UI.
<aura:attribute name="title" type="String" default="Hello World" />
Attribute Parameters
nameThe attribute identifier. Used to reference it in expressions like {! v.name }.
typeThe data type. Can be a primitive, collection, or Apex/sObject type.
defaultOptional default value assigned when the component loads.
requiredSet to true to make the attribute mandatory. Throws an error if missing.
accessVisibility scope: global (external use) or private (component-only).
descriptionDocumentation string — appears in component reference docs.
Basic Types
These are primitive types mapped to their JavaScript equivalents. Use them for simple scalar values.
StringBooleanIntegerDecimalDoubleLongDateDateTime<aura:attribute name="isActive" type="Boolean" default="false" /> <aura:attribute name="score" type="Integer" default="0" /> <aura:attribute name="label" type="String" default="Click me" />
Collection Types
Use these when you need to store multiple values. The most common are List and Map.
ArrayAn ordered list of values. Use for simple indexed collections.
ListAn ordered collection — functionally identical to Array in most use cases.
MapA key-value store. Keys must be strings; values can be any type.
SetAn unordered collection of unique values. No duplicates allowed.
<aura:attribute name="items" type="List" default="[]" />
<aura:attribute name="settings" type="Map" default="{}" />
<aura:attribute name="tags" type="Set" />Object Types
You can type an attribute as any Salesforce sObject or custom Apex class. This enables strong typing and direct field binding to sObject records.
<!-- Bind to a standard sObject --> <aura:attribute name="account" type="Account" /> <!-- Bind to a custom object --> <aura:attribute name="project" type="My_Project__c" /> <!-- Generic object --> <aura:attribute name="data" type="Object" />
Accessing Attribute Values
Attributes are accessed differently in markup vs. JavaScript controllers.
In component markup
<!-- Read the value -->
<p>{! v.title }</p>
<!-- Two-way bind to an input -->
<lightning:input value="{! v.title }" />In JavaScript controller / helper
// Get
var title = component.get("v.title");
// Set
component.set("v.title", "New Title");Need help?
Get expert Salesforce development support
Our Lightning component developers build custom Salesforce UIs for enterprise clients. Book a free call to discuss your project.
Book a Free Call