Full answer
Every page needs a title and a description. Browsers show the title in the tab and history, assistive technology announces it, and search engines use both in results.
Ways to set them:
- Route title:
{ path: 'courses', component: CoursesComponent, title: 'Courses' }. The router setsdocument.titleon navigation. A function or resolver gives a dynamic title, such as the course name. A customTitleStrategycan add a suffix for every page. Titleservice:inject(Title).setTitle('Angular basics').Metaservice:meta.updateTag({ name: 'description', content: '...' }). Social sharing uses Open Graph tags such asog:title,og:description, andog:image, set with{ property: 'og:title', content: '...' }.
The important point is when the tags exist. A purely client-rendered app sends an almost empty HTML file, and tags are set only after JavaScript runs. Search engines that run JavaScript will see them, but many link-preview bots (chat apps, social networks) read only the first HTML. So for public pages use server-side rendering or prerendering. Title and Meta work on the server too, because they use the platform's document.
Good practice:
- A unique title and description for each page. Keep titles under about 60 characters and descriptions under about 160.
- Use
updateTag(replace) instead ofaddTag(can create duplicates) when navigating. - Set a canonical link for pages that appear at more than one URL.
- Put structured data (JSON-LD) in the page for rich results if relevant.
- Do not rely on the meta keywords tag. Search engines ignore it.
typescript
import { Component, Injectable, inject } from '@angular/core';
import { Meta, Title } from '@angular/platform-browser';
import { RouterStateSnapshot, TitleStrategy, Routes } from '@angular/router';
@Injectable({ providedIn: 'root' })
export class SiteTitleStrategy extends TitleStrategy {
private readonly title = inject(Title);
override updateTitle(snapshot: RouterStateSnapshot): void {
const pageTitle = this.buildTitle(snapshot);
this.title.setTitle(pageTitle ? `${pageTitle} | Schoolabe` : 'Schoolabe');
}
}
@Component({
selector: 'app-course-page',
template: `<h1>Angular basics</h1>`,
})
export class CoursePageComponent {
private readonly meta = inject(Meta);
constructor() {
this.meta.updateTag({ name: 'description', content: 'Learn Angular step by step with short lessons.' });
this.meta.updateTag({ property: 'og:title', content: 'Angular basics' });
this.meta.updateTag({ property: 'og:description', content: 'Short lessons with practice questions.' });
}
}
export const routes: Routes = [{ path: 'courses/angular', component: CoursePageComponent, title: 'Angular basics' }];
export const titleProvider = { provide: TitleStrategy, useClass: SiteTitleStrategy };Angular 20.3, type-checked. The suffix strategy is registered with `{ provide: TitleStrategy, useClass: SiteTitleStrategy }`.
Key points
- Route `title` is the simplest way. `Title` and `Meta` cover dynamic pages.
- `meta.updateTag` avoids duplicates when navigating.
- Link preview bots read the first HTML. Use SSR or prerendering for public pages.
- Unique titles and descriptions per page.
Common mistakes
- Using `addTag` on every navigation and filling the head with duplicates.
- Relying on client-only rendering for pages that need link previews.
- Leaving the default title for all routes.
Follow-ups
- How would you add a suffix like "| Schoolabe" to every title?
- How do you set a canonical URL?
- How can you test that the tags appear in the server response?
Tips
- Talk about when the tags exist (client versus server HTML). It is the senior part of this simple question.
- Mention `TitleStrategy` for consistent titles.
- Name length guidance for titles and descriptions, and say it is guidance, not a rule.
Evaluation rubric
- Knows route titles and the Title and Meta services.
- Explains the SSR relationship.
- Avoids duplicate tag mistakes.