Newer Version Available

This content describes an older version of this product. View Latest

Working with Lightning Design System Variants

Base component variants correspond to blueprint variations in Lightning Design System. Variants change the appearance of a component and are controlled by the variant attribute.

Applying Variants to Base Components

Variants on a component refer to design variations for that component, which enable you to change the appearance of the component easily. We try to create variants for each component to apply the design of variations and examples from the SLDS component blueprint. However, not all variants are implemented yet. Most base components provide a variant attribute that accepts two or more variants. For example, lightning:button supports many variants to apply different text and background colors on the buttons.

This example creates a button with the brand variant.

1<lightning:button variant="brand" label="Brand" onclick="{! c.handleClick }" />

If you don’t specify a variant or you pass in a variant that’s not supported, the default variant is used instead. For button, the neutral variant is used by default.

Some components don’t support a variant attribute, but you can use Lightning Design System classes to achieve the styling you want.

This example uses a Lightning Design System class to apply a padding to a paragraph in the lightning:card component.

1<lightning:card footer="Card Footer" title="Hello">
2    <aura:set attribute="actions">
3        <lightning:button label="New"/>
4    </aura:set>
5    <p class="slds-p-horizontal_small">
6        Card Body with a Lightning Design System class
7    </p>
8</lightning:card>

If you don’t find a variant you need, see if you can pass in a Lightning Design System class to the base component before creating your own custom CSS class. Don’t be afraid to experiment with Lightning Design System classes and variants in base components. For more information, see Lightning Design System.

Interactive examples for base components are available in the Component Library.

Note