# Blazor Card, Card Group and Carousel

URL: https://flexcoreui.com/demo/cards  
Section: Components  
Controls: CardControl, CardGroupControl, CarouselControl  
Keywords: card, card group, carousel, slideshow

Show products, places or people as Blazor cards: header, image, body and footer, in a wrapping grid or a carousel that shows one at a time.

## Documentation

### Card

| Name | Type | Default | Description |
|---|---|---|---|
| Title (base) | string? | null | Header heading. The base class documents it as a descriptive title; this control renders it as an <h5>. |
| Subtitle | string? | null | Second line under the title. |
| ImageUrl | string? | null | Image rendered full width between header and body. |
| ImageAlt | string? | null | Alt text; falls back to Title, then "Card image". |
| Elevation | int | 1 | Shadow depth 1 to 3; 0 or less draws only the border, and above 3 has no shadow rule. |
| HeaderContent | RenderFragment? | null | Replaces the title and subtitle inside the header. |
| ChildContent | RenderFragment? | null | Body. |
| FooterContent | RenderFragment? | null | Footer, a right-aligned flex row with a 0.5rem gap. |
| CssClass / Style (base) | string? | null | On the fx-card root. The base Visible is not applied. |
| Enabled / Id / Tag / Data / Parent (base) |  | null | Accepted but have no effect. A written id binds to Id, so it does not reach the root. |
| (unmatched attributes) | Dictionary<string,object> |  | Forwarded to the root <div>. |

### Group

| Name | Type | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | The cards. |
| CssClass / Style (base) | string? | null | On the fx-card-group root <div>. The base Visible is not applied. |
| Enabled / Id / Title / Tag / Data / Parent (base) |  | null | Accepted but have no effect. A written id binds to Id, so it does not reach the root <div>. |
| (unmatched attributes) | Dictionary<string,object> |  | Forwarded to the root <div>. |

### Css

| Name | Description |
|---|---|
| fx-card · fx-card-elevation-1 / -2 / -3 | White rounded box with a hairline border, overflow: hidden; the elevation classes add the shadows. |
| fx-card-header · fx-card-title · fx-card-subtitle | Header block with a bottom hairline; bold 1rem title, 0.8rem gray subtitle. |
| fx-card-image | Full-width image block; the image is display: block. |
| fx-card-body | Padded body that grows to fill the card. |
| fx-card-footer | Light gray footer, flex row aligned to the end. |
| fx-card-group | The group's root. The library's grid rule for this class sits in CardControl's scoped stylesheet and does not reach the group's element, so the group renders as a plain block. Give it a grid in your own CSS, as the card group example does. |

### Carousel

| Name | Type | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | The CarouselItemControls. Each registers when it is first rendered; the order of registration is its index. |
| ActiveIndex | int | 0 | Zero-based index of the item shown. The carousel sets it itself when its buttons or methods move; bind it with @bind-ActiveIndex, because a fixed value is put back the next time the parent renders. An index with no item shows nothing. |
| ShowNavButtons | bool | true | Draws the previous and next arrow buttons when there are at least two items. |
| ShowIndicators | bool | true | Draws one dot button per item when there are at least two items. |
| CssClass / Style (base) | string? | null | On the fx-carousel root. The base Visible is not applied. |
| Enabled / Id / Title / Tag / Data / Parent (base) |  | null | Accepted but have no effect. A written id binds to Id, so it does not reach the root. |
| (unmatched attributes) | Dictionary<string,object> |  | Forwarded to the root <div>; the example passes its ARIA attributes this way. |

### Carousel events

| Name | Type | Description |
|---|---|---|
| ActiveIndexChanged | int | After an arrow, a dot, Next, Prev or SelectSlide, with the new index; a dot or SelectSlide for the current item raises it too. Not raised when an item is removed and the index is pulled back to the last item. |

### Carousel methods

| Name | Type | Description |
|---|---|---|
| Next() | Task | Shows the next item, from the last back to the first, and raises ActiveIndexChanged. Does nothing with no items. |
| Prev() | Task | Shows the previous item, from the first back to the last, and raises ActiveIndexChanged. Does nothing with no items. |
| SelectSlide(int index) | Task | Shows that item and raises ActiveIndexChanged. An index outside the items is ignored. |

### Item

| Name | Type | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | What the item shows. Rendered only while the item is the current one; the others render nothing at all. |
| (no base class) |  |  | It does not inherit FlexControlBase, so it takes no CssClass, Style or other attributes. Wrap the content in your own element to style it, as the example does. |

### Item props

| Name | Type | Description |
|---|---|---|
| CarouselItemControl.Active | bool | True while this item is the carousel's current one; false outside a CarouselControl, where it never renders. |

### Carousel css

| Name | Description |
|---|---|
| fx-carousel | Root: full width, overflow: hidden, 8px radius, dark slate background #1e293b. |
| fx-carousel-inner | Holds the items; at least 200px tall. |
| fx-carousel-item · active | The current item's wrapper; it fades in from 40% opacity over 0.3s. |
| fx-carousel-btn · fx-carousel-prev / -next | 36px round arrow buttons, translucent black, centered vertically 12px in from the left and right edges. |
| fx-carousel-indicators | Row of dots centered 12px above the bottom edge. |
| fx-carousel-indicator · active | 10px dot with a white ring; the current one is solid white and 22px wide. |

## Examples

### Card

```razor
@using Fx.ControlKit

<div class="demo-row">
    <span class="field-label">Elevation</span>
    <ButtonGroupControl Items="_elevationItems" Values="@(new[] { _elevation.ToString() })" ValuesChanged="PickElevation" AriaLabel="Elevation" />
</div>
<div class="card-stage">
    <CardControl Title="Quote LIS-0001 Lisbon city break" Subtitle="@($"{(_sent ? "Sent to Albus Door" : "Quoted")} · 3 lines · $1,720")"
                 ImageUrl="images/card-lisbon.svg" ImageAlt="Route sketch: airport, old-town hotel and food tour" Elevation="@_elevation">
        <ChildContent><p class="m0">Return flights, four nights in an old-town hotel and a guided food tour.</p></ChildContent>
        <FooterContent>
            <BadgeControl Text="@(_sent ? "Quote sent" : "Quoted")" Variant="@(_sent ? BadgeVariant.Success : BadgeVariant.Info)" />
            <ButtonControl CssClass="btn-sm" OnClick="@(() => _sent = !_sent)">@(_sent ? "Recall quote" : "Send quote")</ButtonControl>
        </FooterContent>
    </CardControl>
</div>
```

```csharp
// Card
private int _elevation = 2;
private bool _sent;
private readonly SelectionItem[] _elevationItems = { new("0", "None"), new("1", "1"), new("2", "2"), new("3", "3") };
private void PickElevation(IReadOnlyList<string> values)
{
    if (values.Count > 0) _elevation = int.Parse(values[0]);
}
```

### Group

```razor
@using Fx.ControlKit

<div class="demo-row">
    <span class="field-label">Status</span>
    <ButtonGroupControl Items="_statusItems" Values="@(new[] { _status })" ValuesChanged="PickStatus" AriaLabel="Status" />
    <span class="result inline" role="status">@Shown.Length of @_quotes.Length quotes</span>
</div>
<div class="quotes">
    <CardGroupControl>
        @foreach (var q in Shown)
        {
            <CardControl @key="q.Name" Elevation="1">
                <HeaderContent><span class="head"><span class="@q.Icon"></span> @q.Name</span></HeaderContent>
                <ChildContent><p class="m0">@q.Summary</p></ChildContent>
                <FooterContent><BadgeControl Text="@q.Status" Variant="@q.Variant" /></FooterContent>
            </CardControl>
        }
    </CardGroupControl>
</div>
```

```csharp
// Card group
private sealed record Quote(string Name, string Icon, string Summary, string Status, BadgeVariant Variant);
private readonly Quote[] _quotes =
{
    new("AMF-0002 Puddleby", "bi bi-geo-alt", "Amalfi coast drive, 9 lines, $6,240.", "Booked", BadgeVariant.Success),
    new("CPT-0003 Wobblesworth", "bi bi-sun", "Cape winelands, 8 lines, $8,150.", "Awaiting deposit", BadgeVariant.Warning),
    new("KYO-0001 Thistlewood", "bi bi-map", "Kyoto long weekend, 6 lines, $4,860.", "Draft", BadgeVariant.Secondary),
    new("LIS-0001 Door", "bi bi-building", "Lisbon city break, 3 lines, $1,720.", "Quoted", BadgeVariant.Info),
    new("LIS-0002 Marmalade", "bi bi-compass", "Lisbon Explorer, 5 lines, $3,480.", "Booked", BadgeVariant.Success),
    new("HOI-0004 Bumblethorpe", "bi bi-brightness-high", "Hoi An lantern trail, 7 lines, $5,310.", "Draft", BadgeVariant.Secondary),
};
private readonly SelectionItem[] _statusItems = { new("All", "All"), new("Booked", "Booked"), new("Awaiting deposit", "Awaiting deposit"), new("Quoted", "Quoted"), new("Draft", "Draft") };
private string _status = "All";
private void PickStatus(IReadOnlyList<string> values)
{
    if (values.Count > 0) _status = values[0];
}
private Quote[] Shown => _quotes.Where(q => _status == "All" || q.Status == _status).ToArray();
```

### Carousel

```razor
@using Fx.ControlKit

<SwitchControl @bind-Checked="_showNav" Label="Nav buttons" />
<SwitchControl @bind-Checked="_showDots" Label="Indicators" />

<CarouselControl @ref="_carousel" @bind-ActiveIndex="_slide" ShowNavButtons="_showNav" ShowIndicators="_showDots"
                 role="region" aria-roledescription="carousel" aria-label="Destinations">
    @foreach (var t in _trips)
    {
        <CarouselItemControl>
            <div class="trip-slide">
                <CardControl Title="@t.City" Subtitle="@t.Country" Elevation="2">
                    <ChildContent><p class="trip-blurb">@t.Blurb</p></ChildContent>
                    <FooterContent>
                        <span class="trip-package">@t.Package</span>
                        <BadgeControl Text="@($"{t.Nights} nights")" Variant="BadgeVariant.Info" />
                    </FooterContent>
                </CardControl>
            </div>
        </CarouselItemControl>
    }
</CarouselControl>
<div class="trip-pager">
    <ButtonControl CssClass="btn-sm" OnClick="@(() => _carousel!.Prev())">Previous</ButtonControl>
    <ButtonControl CssClass="btn-sm" OnClick="@(() => _carousel!.Next())">Next</ButtonControl>
    <ButtonControl CssClass="btn-sm" OnClick="@(() => _carousel!.SelectSlide(0))" Disabled="@(_slide == 0)">First</ButtonControl>
    <span class="trip-count" aria-live="polite">Card @(_slide + 1) of @_trips.Length: @_trips[_slide].Package, @_trips[_slide].Nights nights</span>
</div>
<div class="trip-pager">
    <span class="field-label">Go to</span>
    @foreach (var (t, i) in _trips.Select((t, i) => (t, i)))
    {
        <ButtonControl CssClass="@(i == _slide ? "btn-sm btn-primary" : "btn-sm")" OnClick="@(() => _slide = i)">@t.City</ButtonControl>
    }
</div>
```

```csharp
// Carousel
private CarouselControl? _carousel;
private int _slide;
private bool _showNav = true;
private bool _showDots = true;
private sealed record Trip(string City, string Country, string Package, int Nights, string Blurb);
private readonly Trip[] _trips =
{
    new("Lisbon", "Portugal", "Lisbon Explorer", 7, "Tram 28 up to the Alfama, custard tarts in Belém and an evening of fado."),
    new("Amalfi", "Italy", "Amalfi Coast Drive", 6, "The cliff road from Positano to Ravello, with a boat day out to Capri."),
    new("Kyoto", "Japan", "Kyoto Classic", 8, "Temple gardens at opening time, a tea ceremony and a day trip to Nara."),
    new("Hoi An", "Vietnam", "Hoi An Lantern Trail", 9, "Lantern evenings in the old town, a tailor's fitting and a riverside cooking class."),
    new("Cape Town", "South Africa", "Cape Winelands", 10, "Table Mountain by cable car, then three days among the Stellenbosch vineyards."),
    new("Marrakech", "Morocco", "Marrakech to the Dunes", 6, "The souks and Jemaa el-Fnaa, then over the Atlas to a camp in the dunes."),
};
```

