Suggest an editImprove this articleRefine the answer for “Can you create a custom directive in Angular?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**Yes**, you can create a custom directive in Angular: you create a class with the `@Directive` decorator and specify a selector through which the directive is applied to an element. **Key point:** a custom directive lets you extend the functionality of elements and create reusable behavior.Shown above the full answer for quick recall.Answer (EN)ImageYes, you can create a custom directive in Angular. Principle: 1. A class is created with the `@Directive` decorator. 2. A **selector** is specified, through which the directive will be applied to an element. 3. Inside the class you can control the element via `ElementRef`, add styles via `Renderer2`, listen for events and so on. Example of a simple attribute directive: ```typescript import { Directive, ElementRef, Renderer2 } from '@angular/core'; @Directive({ selector: '[appHighlight]' }) export class HighlightDirective { constructor(el: ElementRef, renderer: Renderer2) { renderer.setStyle(el.nativeElement, 'background-color', 'yellow'); } } ``` Usage in a template: ```html <p appHighlight>Text with a yellow background</p> ``` > Conclusion: a custom directive lets you **extend the functionality of elements** and create reusable behavior.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.