🇨🇦 Canada-based Salesforce partner — serving SMBs across North America·✦ Free 30-min CRM audit — no pitch, just insight·✦ 50+ SMBs transformed — 100% Salesforce certified team·✦ Offices in Toronto, ON & Mohali, India·🇨🇦 Canada-based Salesforce partner — serving SMBs across North America·✦ Free 30-min CRM audit — no pitch, just insight·✦ 50+ SMBs transformed — 100% Salesforce certified team·✦ Offices in Toronto, ON & Mohali, India·
← Blog

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

name

The attribute identifier. Used to reference it in expressions like {! v.name }.

type

The data type. Can be a primitive, collection, or Apex/sObject type.

default

Optional default value assigned when the component loads.

required

Set to true to make the attribute mandatory. Throws an error if missing.

access

Visibility scope: global (external use) or private (component-only).

description

Documentation string — appears in component reference docs.

Basic Types

These are primitive types mapped to their JavaScript equivalents. Use them for simple scalar values.

String
Boolean
Integer
Decimal
Double
Long
Date
DateTime
<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.

Array

An ordered list of values. Use for simple indexed collections.

List

An ordered collection — functionally identical to Array in most use cases.

Map

A key-value store. Keys must be strings; values can be any type.

Set

An 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