Angular Material Card

Angular Material Card Component is a container component that holds title text, image, and action buttons to represent a single or specific subject.

Angular Material provides a wide range of web components which are very easy to implement and use in Angular applications for creating card, badge, forms, steps, menu etc. In this example we will learn how to create step by step form in angular app using material card.

Angular Material Basic card sections

Syntax :

<mat-card>     </mat-card>

The most basic card needs only an <mat-card> element with some content. However, Angular Material provides a number of preset sections that you can use inside of an <mat-card>:

<mat-card-title>Card title
<mat-card-subtitle>Card subtitle
<mat-card-content>Primary card content. Intended for blocks of text
<img mat-card-image>Card image. Stretches the image to the container width
<mat-card-actions>Container for buttons at the bottom of the card
<mat-card-footer>Section anchored to the bottom of the card

These elements primary serve as pre-styled content containers without any additional APIs. However, the align property on <mat-card-actions> can be used to position the actions at the 'start' or 'end' of the container.

Angular Material Card headers

In addition to the aforementioned sections, <mat-card-header> gives the ability to add a rich header to a card. This header can contain:

<mat-card-title>A title within the header
<mat-card-subtitle>A subtitle within the header
<img mat-card-avatar>An image used as an avatar within the header

Angular Material Card With Title and Subtitle

Apart from the basic card component without any specific sections, We can provide a Title and Subtitle as well, we can make use of the in-built selector with the card header, below you can find the syntax for the same.

Syntax :

<mat-card-title>               <mat-card-title>
<mat-card-subtitle>            </mat-card-subtitle>

Example 1 : Angular Material Simple-Card Example with Title and SubTitle


Add the below import statement into your module file.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import {MatCardModule} from '@angular/material/card';
import {MatButtonModule} from '@angular/material/button';

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }


<mat-card [style.background]="'skyblue'">
<mat-card-title> Card Title </mat-card-title>
<mat-card-subtitle> @ Subtitle</mat-card-subtitle>

Output :

And you will get output something like this.

Angular Material Card with subtitle

Example 2 : Angular Material Simple-Card Example


  <mat-card-title> Card Title</mat-card-title>
  <mat-card-subtitle> Card Subtitle</mat-card-subtitle>
  <mat-card-actions align="end">
   <button mat-button=""> LIKE ❤️ </button>
   <button mat-button=""> SHARE</button>

Output :

And you will get output something like this.

Angular Material Card Example

Example 3 : Angular Material Card with Image Example


  <img mat-card-image="" src="" alt="Photo of a Shiba Inu">
    <strong>  A dog is a domestic mammal of the family Canidae and the order Carnivora.</strong>
    Its scientific name is Canis lupus familiaris. Dogs are a subspecies of the gray wolf, and they are also related to foxes and jackals. Dogs are one of the two most ubiquitous and most popular domestic animals in the world.
  <mat-card-actions align="end">
    <button mat-button="">Like ❤️</button>
    <button mat-button="">share 👍</button>


Output :

And you will get output something like this.

Angular Material Card with Image

Title group :

<mat-card-title-group> can be used to combine a title, subtitle, and image into a single section. This element can contain:

  • <mat-card-title>
  • <mat-card-subtitle>
  • One of :
    • <img mat-card-sm-image>
    • <img mat-card-md-image>
    • <img mat-card-lg-image>

I hope you like this amazing article.

Also Read: