> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-ui-builder/17.latest/cards/custom-cards.md).

# Custom Cards

Custom cards enable more complex metric calculations and are defined by a class that implements the `Card` base class.

When Umbraco UI Builder resolves a card, it tries to do so from the global DI container. This means you can inject any dependencies required for the card's value calculation. If no type is found in the DI container, Umbraco UI Builder will fall back to manually instantiating a new instance of the value mapper.

## Defining a Custom Card

To define a custom card, create a class that inherits from the base class `Card` and configure it in the constructor as shown below:

```csharp
// Example
public class AvgPersonAgeCard : Card
{
    public override string Alias => "avgPersonAge";
    public override string Name => "Average Age";
    public override string Icon => "icon-calendar";
    public override string Color => "green";
    public override string Suffix => "yrs";
        
    public override object GetValue(object parentId = null)
    {
        // Perform value calculation logic
    }
}
```

### Configuration Options

|              Option              |                 Description                | Required |
| :------------------------------: | :----------------------------------------: | -------- |
|               Name               |            The name of the card.           | Yes      |
|               Alias              |        A unique alias for the card.        | Yes      |
| GetValue(object parentId = null) |   A method to retrieve the card's value.   | Yes      |
|               Icon               |       An icon displayed in the card.       | No       |
|               Color              |           The color of the card.           | No       |
|              Suffix              | The suffix displayed after the card value. | No       |

## Adding a Custom Card to a Collection

### Using the `AddCard()` Method

Adds a custom card of the specified type to the collection.

#### Method Syntax

```cs
AddCard() : CollectionConfigBuilder<TEntityType>
```

#### Example

```csharp
collectionConfig.AddCard<AvgPersonAgeCard>();
```

### Using the `AddCard(Type cardType)` Method

Adds a custom card of the specified type to the collection, using the `Type` parameter to pass the card type dynamically.

#### Method Syntax

```cs
AddCard(Type cardType) : CollectionConfigBuilder<TEntityType>
```

#### Example

```csharp
collectionConfig.AddCard(typeof(AvgPersonAgeCard));
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.umbraco.com/umbraco-ui-builder/17.latest/cards/custom-cards.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
