---
title: "Angular Calendar Custom Header Example | Mobiscroll"
component: "Calendar"
framework: "Angular"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/angular/calendar/customizing-header"
---

# Custom Header - Angular Calendar demo

Customize the Angular date picker header — rearrange nav controls, add a today button, or add a week/month view switcher.

- [Live demo](https://demo.mobiscroll.com/angular/calendar/customizing-header)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-angular/tree/main/src/demos/datepicker/calendar/customizing-header)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/calendar/customizing-header.md), [jQuery](https://demo.mobiscroll.com/jquery/calendar/customizing-header.md), [React](https://demo.mobiscroll.com/react/calendar/customizing-header.md), [Vue](https://demo.mobiscroll.com/vue/calendar/customizing-header.md)

## Description

You can customize how the header of calendar looks and how the components are arranged. Besides that you can also add custom functionality, like a segmented control that lets people switch between week and month view.

Use the [`headerTemplate`](https://mobiscroll.com/docs/angular/datepicker/api#template-headerTemplate) option for passing a custom template. There are predefined components - shorthands if you will - that can be used to assemble the header:

- **Navigation component** - `<mbsc-calendar-nav></mbsc-calendar-nav>`
- **Today button** - `<mbsc-calendar-today></mbsc-calendar-today>`
- **Previous month button** - `<mbsc-calendar-prev></mbsc-calendar-prev>`
- **Next month button** - `<mbsc-calendar-next></mbsc-calendar-next>`

## What this demo shows

- The Datepicker calendar header can use the default layout, a custom arrangement, or be hidden completely.
- **Default header**: Displays the current month and year with previous and next navigation controls.
- **Month and year navigation**: Clicking the month and year label opens a picker for navigating directly to a specific month or year.
- **Previous and next controls**: Pages the calendar by one month in month view and one week in week view.
- **Custom header arrangement**: Centers `CalendarNav` and places `CalendarPrev` and `CalendarNext` on opposite sides using predefined calendar components.
- **Today button**: Adds a `CalendarToday` control between the navigation buttons in their default positions.
- **Week and month views**: Adds a segmented control with week and month icons for switching the calendar dynamically between the two views.
- **Selected date preview**: Displays the currently selected date in the header.

## Best for

- **Compact date pickers**: Hide the header when month and year navigation is unnecessary or space is limited.
- **Long-range date selection**: Open the month and year picker to reach dates that would require many previous or next navigation steps.
- **Current-date workflows**: Add a Today button when users frequently need to return to the current date.
- **Flexible date browsing**: Let users switch between week and month views when they need both a focused and a broader calendar view.
- **Selection confirmation**: Show the selected date in the header when users need a clear preview of their current choice.
- **Custom header layouts**: Rearrange the built-in navigation controls to fit the date picker's available space and surrounding interface.

## Tutorial

### Default header

The default header contains the two arrows on the far-right for previous and next months, while the current month indicator with the `mbsc-calendar-nav` component is placed to the far-left.

```html
<mbsc-datepicker
    [controls]="['calendar']"
    calendarType="week"
    [calendarSize]="2">
</mbsc-datepicker>
```

### Custom header arrangement

You can reorder the controls and place the `mbsc-calendar-nav` in the middle with the two arrows - `mbsc-calendar-prev` and `mbsc-calendar-next` - to the sides.

```html
<mbsc-datepicker
    [controls]="['calendar']"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-prev class="custom-prev"></mbsc-calendar-prev>
        <mbsc-calendar-nav class="custom-nav"></mbsc-calendar-nav>
        <mbsc-calendar-next class="custom-next"></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
```

### Add a today button

You can also add a custom component, like a `mbsc-calendar-today` button.

```html
<mbsc-datepicker
    [controls]="['calendar']"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-nav></mbsc-calendar-nav>
        <div class="custom-buttons">
            <mbsc-calendar-prev></mbsc-calendar-prev>
            <mbsc-calendar-today></mbsc-calendar-today>
            <mbsc-calendar-next></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
```

### Switch between week and month view

Use a segmented component for creating a view switcher.

```html
<mbsc-datepicker
    [controls]="['calendar']"
    [calendarType]="calendarType"
    [calendarSize]="2"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-nav class="custom-view-nav"></mbsc-calendar-nav>
        <div class="custom-view">
            <mbsc-segmented-group [(ngModel)]="view" (change)="changeView()">
                <mbsc-segmented value="week" icon="material-date-range"></mbsc-segmented>
                <mbsc-segmented value="month" icon="material-event-note"></mbsc-segmented>
            </mbsc-segmented-group>
        </div>
        <mbsc-calendar-prev></mbsc-calendar-prev>
        <mbsc-calendar-next></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
```

```ts
view = 'week';
changeView() {
    setTimeout(() => {
        switch (this.view) {
            case 'week':
                this.calendarType = 'week';
                break;
            case 'month':
                this.calendarType = 'month';
                break;
        }
    });
}
```

### Preview the selection

Above all that you can give instructions or show the selected `{value}` in the header

```html
<mbsc-datepicker
    [controls]="['calendar']"
    calendarType="week"
    [calendarSize]="2"
    headerText="You selected {value}">
</mbsc-datepicker>
```

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/angular/datepicker/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/angular/datepicker/api#opt-themeVariant) - option
- [`calendarType`](https://mobiscroll.com/docs/angular/datepicker/api#opt-calendarType) - option
- [`controls`](https://mobiscroll.com/docs/angular/datepicker/api#opt-controls) - option
- [`display`](https://mobiscroll.com/docs/angular/datepicker/api#opt-display) - option
- [`calendarSize`](https://mobiscroll.com/docs/angular/datepicker/api#opt-calendarSize) - option
- [`calendarHeaderTemplate`](https://mobiscroll.com/docs/angular/datepicker/api#template-calendarHeaderTemplate) - template
- [`headerText`](https://mobiscroll.com/docs/angular/datepicker/api#opt-headerText) - option

## Code

### Component

```ts
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MbscModule, setOptions } from '@mobiscroll/angular';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

@Component({
  selector: 'app-root', 
  templateUrl: './app.component.html',
  standalone: true,
  imports: [CommonModule, FormsModule, MbscModule],
})
export class AppComponent {
  view = 'week';
  calendarType: any = 'week';
  changeView(): void {
    setTimeout(() => {
      switch (this.view) {
        case 'week':
          this.calendarType = 'week';
          break;
        case 'month':
          this.calendarType = 'month';
          break;
      }
    });
  }
}
```

### Template

```html
<mbsc-datepicker [controls]="['calendar']" display="inline" calendarType="week" [calendarSize]="2"></mbsc-datepicker>

<mbsc-datepicker [controls]="['calendar']" display="inline" [calendarHeaderTemplate]="customHeaderTemplate">
  <ng-template #customHeaderTemplate>
    <mbsc-calendar-prev class="custom-prev"></mbsc-calendar-prev>
    <mbsc-calendar-nav class="custom-nav"></mbsc-calendar-nav>
    <mbsc-calendar-next class="custom-next"></mbsc-calendar-next>
  </ng-template>
</mbsc-datepicker>

<mbsc-datepicker [controls]="['calendar']" display="inline" [calendarHeaderTemplate]="todayHeaderTemplate">
  <ng-template #todayHeaderTemplate>
    <mbsc-calendar-nav></mbsc-calendar-nav>
    <div class="custom-buttons">
      <mbsc-calendar-prev></mbsc-calendar-prev>
      <mbsc-calendar-today></mbsc-calendar-today>
      <mbsc-calendar-next></mbsc-calendar-next>
    </div>
  </ng-template>
</mbsc-datepicker>

<mbsc-datepicker
  [controls]="['calendar']"
  display="inline"
  [calendarType]="calendarType"
  [calendarSize]="2"
  [calendarHeaderTemplate]="switchHeaderTemplate"
>
  <ng-template #switchHeaderTemplate>
    <mbsc-calendar-nav class="custom-view-nav"></mbsc-calendar-nav>
    <div class="custom-view">
      <mbsc-segmented-group [(ngModel)]="view" (change)="changeView()">
        <mbsc-segmented value="week" icon="material-date-range"></mbsc-segmented>
        <mbsc-segmented value="month" icon="material-event-note"></mbsc-segmented>
      </mbsc-segmented-group>
    </div>
    <mbsc-calendar-prev></mbsc-calendar-prev>
    <mbsc-calendar-next></mbsc-calendar-next>
  </ng-template>
</mbsc-datepicker>

<mbsc-datepicker
  [controls]="['calendar']"
  display="inline"
  calendarType="week"
  [calendarSize]="2"
  headerText="You selected {value}"
></mbsc-datepicker>
```

### CSS

```css
.custom-buttons,
.custom-view,
.custom-nav {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex: 1 0 auto;
  -moz-box-flex: 1;
  -ms-flex: 1 0 auto;
  flex: 1 0 auto;
}

.custom-buttons {
  -webkit-justify-content: flex-end;
  -moz-box-pack: end;
  -ms-flex-pack: end;
  justify-content: flex-end;
}

.custom-view,
.custom-nav {
  -webkit-justify-content: center;
  -moz-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.custom-view-nav .mbsc-calendar-title.mbsc-material {
  font-size: 16px;
}

.custom-view .mbsc-segmented {
  margin: 0;
}

.custom-view .mbsc-segmented.mbsc-material,
.custom-view .mbsc-segmented.mbsc-windows {
  padding: 0 2px;
}

.custom-view .mbsc-segmented .mbsc-segmented-button {
  padding: 0 1px;
}

.custom-view .mbsc-segmented .mbsc-icon {
  font-size: 20px;
}

.custom-view .mbsc-segmented-button.mbsc-windows {
  border: 0;
}
```

## Implementation notes

- Use `controls: ['calendar']` and `display: 'inline'`; the compact multi-row examples add `calendarType: 'week'` and `calendarSize: 2`.
- **Default header**: no extra option needed - it renders the nav label on the left and the prev/next arrows on the right.
- **Custom arrangement**: pass `renderCalendarHeader` (Angular: `calendarHeaderTemplate`, Vue: `#header` slot) returning custom markup that composes the predefined header sub-components - `mbsc-calendar-nav` (Vue: `MbscCalendarNav`, React: `CalendarNav`), `mbsc-calendar-prev`/`mbsc-calendar-next` (Vue: `MbscCalendarPrev`/`MbscCalendarNext`, React: `CalendarPrev`/`CalendarNext`) - in any order/position.
- **Today button**: include `mbsc-calendar-today` (Vue: `MbscCalendarToday`, React: `CalendarToday`) alongside the prev/next controls inside the same custom header markup.
- `calendarType` can be switched at runtime between `'week'` and `'month'`. React/Vue/Angular update it as a controlled value (`useState`, `v-model`, `[(ngModel)]`) bound to the datepicker's `calendarType` prop; JS/jQuery call `.setOptions({ calendarType: 'week' | 'month' })` on the instance.
- **Selected-date preview**: set `headerText` to a template string containing `{value}` (e.g. `'You selected {value}'`) - it's substituted with the current selection and rendered in the header automatically, no custom renderer needed.
- To hide the header entirely, return empty/no markup from `renderCalendarHeader` - pair with a compact layout when month/year navigation isn't needed.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-angular.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config angular
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   ng serve
   ```

On a trial, add `--trial` to the config command: `mobiscroll config angular --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/angular/getting-started/installation

## Related demos

- Previous: [Themes — iOS, Material & Windows](https://demo.mobiscroll.com/angular/calendar/themes-ios-material-windows.md) - Style the Angular calendar date picker with iOS, Material, or Windows themes — switch light/dark mode, use the theme builder, or apply custom CSS.
- Next: [Mark Days with Custom Shapes](https://demo.mobiscroll.com/angular/calendar/customize-marked-day-shapes.md) - Add custom-shaped day markers to an Angular calendar date picker — use the marked option for colored dots, then override styles.
