{ "id": "guide/docs-style-guide", "title": "Angular documentation style guide", "contents": "\n\n\n
\n mode_edit\n
\n\n\n
\n

Angular documentation style guidelink

\n

This style guide covers the standards for writing Angular documentation on angular.io.\nThese standards ensure consistency in writing style, Markdown conventions, and code snippets.

\n

Prerequisiteslink

\n

Before contributing to the Angular documentation, it is helpful if you are familiar with the following:

\n\n

Kinds of Angular documentationlink

\n

The categories of Angular documentation include:

\n\n

Markdown and HTMLlink

\n

While the Angular guides are Markdown files, there are some sections within the guides that use HTML.

\n
\n

To enable HTML in an Angular guide, always follow every opening and closing HTML tag with a blank line.

\n
\n

Notice the required blank line after the opening <div> in the following example:

\n\n<div class=\"alert is-helpful\">\n\n **Always** follow every opening and closing HTML tag with _a blank line_.\n\n</div>\n\n

It is customary but not required to precede the closing HTML tag with a blank line as well.

\n

Titlelink

\n

Every guide document must have a title, and it should appear at the top of the page.

\n

Begin the title with the Markdown # character, which renders as an <h1> in the browser.

\n\n # Angular documentation style guide\n\n

A document can have only one <h1>.

\n

Title text should be in Sentence case, which means the first word is capitalized and all other words are lower case.\nTechnical terms that are always capitalized, like \"Angular\", are the exception.

\n\n # Deprecation policy in Angular\n\n

Always follow the title with at least one blank line.

\n

The corresponding text in the left nav is in Title Case, which means that you use capital letters to start the first words and all principal words.\nUse lower case letters for secondary words such as \"in\", \"of\", and \"the\".\nYou can also shorten the nav title to fit in the column.

\n

Sectionslink

\n

A typical document has sections.

\n

All section headings are in Sentence case, which means the first word is capitalized and all other words are lower case.

\n

Always follow a section heading with at least one blank line.

\n

Main section headinglink

\n

There are usually one or more main sections that may be further divided into secondary sections.

\n

Begin a main section heading with the Markdown ## characters, which renders as an <h2> in the browser.

\n

Follow main section headings with a blank line and then the content for that heading as in the following example:

\n\n ## Main section heading\n\n Content after a blank line.\n\n

Secondary section headinglink

\n

A secondary section heading is related to a main heading and falls textually within the bounds of that main heading.

\n

Begin a secondary heading with the Markdown ### characters, which renders as an <h3> in the browser.

\n

Follow a secondary heading by a blank line and then the content for that heading as in the following example:

\n\n ### Secondary section heading\n\n Content after a blank line.\n\n

Additional section headingslink

\n

While you can use additional section headings, the Table-of-contents (TOC) generator only shows <h2> and <h3> headings in the TOC on the right of the page.

\n\n #### The TOC won't display this\n\n Content after a blank line.\n\n

Table of contentslink

\n

Most pages display a table of contents or TOC.\nThe TOC appears in the right panel when the viewport is wide.\nWhen narrow, the TOC appears in a collapsible region near the top of the page.

\n

You don't need to create your own TOC by hand because the TOC generator creates one automatically from the page's <h2> and <h3> headers.

\n

To exclude a heading from the TOC, create the heading as an <h2> or <h3> element with a class called 'no-toc'.

\n\n<h3 class=\"no-toc\">\n\nThis heading is not displayed in the TOC\n\n</h3>\n\n

You can turn off TOC generation for the entire page by writing the title with an <h1> tag and the no-toc class.

\n\n<h1 class=\"no-toc\">\n\nA guide without a TOC\n\n</h1>\n\n

Navigationlink

\n

To generate the navigation links at the top, left, and bottom of the screen, use the JSON configuration file, content/navigation.json.

\n
\n

If you have an idea that would result in navigation changes, file an issue first so that the Angular team and community can discuss the change.

\n
\n

For a new guide page, edit the SideNav node in navigation.json.\nThe SideNav node is an array of navigation nodes.\nEach node is either an item node for a single document or a header node with child nodes.

\n

Find the header for your page.\nFor example, a guide page that describes an Angular feature is probably a child of the Fundamentals header.

\n\n{\n \"title\": \"Fundamentals\",\n \"tooltip\": \"The fundamentals of Angular\",\n \"children\": [ ... ]\n}\n\n

A header node child can be an item node or another header node.\nIf your guide page belongs under a sub-header, find that sub-header in the JSON.

\n

Add an item node for your guide page as a child of the appropriate header node as in the following example:

\n\n {\n \"url\": \"guide/docs-style-guide\",\n \"title\": \"Doc authors style guide\",\n \"tooltip\": \"Style guide for documentation authors.\",\n },\n\n

A navigation node has the following properties:

\n\n
\n

Do not create a node that is both a header and an item node by specifying the url property of a header node.

\n
\n

Code snippetslink

\n

Angular.io has a custom framework that enables authors to include code snippets directly from working example apps that are automatically tested as part of documentation builds.

\n

In addition to working code snippets, example code can include terminal commands, a fragment of TypeScript or HTML, or an entire code file.

\n

Whatever the source, the doc viewer renders them as code snippets, either individually with the code-example component or as a tabbed collection with the code-tabs component.

\n\n

When to use code fontlink

\n

You can display a minimal, inline code snippet with the Markdown backtick syntax.\nUse a single backtick on either side of a term when referring to code or the\nname of a file in a sentence.\nThe following are some examples:

\n\n

The Markdown is as follows:

\n\n* In the `app.component.ts`, add a `logger()` method.\n* The <code class=\"no-auto-link\">item</code> property is `true`.\n* Add the component class name to the `declarations` array.\n\n

Auto-linking in code snippetslink

\n

In certain cases, when you apply backticks around a term, it may auto-link to the API documentation.\nIf you do not intend the term to be a link, use the following syntax:

\n\nThe <code class=\"no-auto-link\">item</code> property is `true`.\n\n

Hard-coded snippetslink

\n

Ideally, you should source code snippets from working sample code, though there are times when an inline snippet is necessary.

\n

For terminal input and output, place the content between <code-example> tags, set the CSS class to code-shell, and set the language attribute to sh as in this example:

\n\n\n npm start\n\n\n\n<code-example language=\"sh\" class=\"code-shell\">\n\n npm start\n\n</code-example>\n\n

Inline, hard-coded snippets like this one are not testable and, therefore, intrinsically unreliable.\nThis example belongs to the small set of pre-approved, inline snippets that includes user input in a command shell or the output of some process.

\n

In all other cases, code snippets should be generated automatically from tested code samples.

\n

For hypothetical examples such as illustrations of configuration options in a JSON file, use the <code-example> tag with the header attribute to identify the context.

\n\n

Compilable example appslink

\n

One of the Angular documentation design goals is that guide page code snippets be examples of working code.

\n

Authors meet this goal by displaying code snippets directly from working sample apps, written specifically for these guide pages.

\n

Find sample apps in sub-folders of the content/examples directory of the angular/angular repository.\nAn example folder name is often the same as the guide page it supports.

\n
\n

A guide page might not have its own sample code.\nIt might refer instead to a sample belonging to another page.

\n
\n

The Angular CI process runs all end-to-end tests for every Angular PR.\nAngular re-tests the samples after every new version of a sample and every new version of Angular.

\n

When possible, every snippet of code on a guide page should be derived from a code sample file. You tell the Angular documentation engine which code file—or fragment of a code file—to display by configuring <code-example> attributes.

\n\n

Displaying an entire code filelink

\n

This Angular documentation style guide that you are currently reading has its own example application, located in the content/examples/docs-style-guide folder.

\n

The following <code-example> displays the sample's app.module.ts:

\n\nimport { NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\nimport { FormsModule } from '@angular/forms';\n\nimport { AppComponent } from './app.component';\n\n@NgModule({\n imports: [ BrowserModule, FormsModule ],\n declarations: [ AppComponent ],\n bootstrap: [ AppComponent ]\n})\nexport class AppModule { }\n\n\n\n

The following markup produces that snippet:

\n\n<code-example path=\"docs-style-guide/src/app/app.module.ts\" header=\"src/app/app.module.ts\">\n</code-example>\n\n

The path attribute identifies the snippet's source file at the example app folder's location within content/examples.\nIn this example, that path is docs-style-guide/src/app/app.module.ts.

\n

The header tells the reader where to find the file.\nFollowing convention, set the header attribute to the file's location within the example app's root folder.

\n

Unless otherwise noted, all code snippets in this page are from sample source code located in the content/examples/docs-style-guide directory.

\n
\n

The documentation tooling reports an error if the file identified in the path does not exist or is in the .git-ignore file.\nMost .js files are in .git-ignore.

\n

To include an ignored code file in your project and display it in a guide, remove it from .git-ignore. Update the content/examples/.gitignore as follows:

\n\n # my-guide\n !my-guide/src/something.js\n !my-guide/more-javascript*.js\n\n
\n\n

Displaying part of a code filelink

\n

To include a snippet of code within a sample code file, rather than the entire file, use the <code-example> region attribute.\nThe following example focuses on the AppModule class and its @NgModule() metadata:

\n\n@NgModule({\n imports: [ BrowserModule, FormsModule ],\n declarations: [ AppComponent ],\n bootstrap: [ AppComponent ]\n})\nexport class AppModule { }\n\n\n

To render the above example, the HTML in the Markdown file is as follows:

\n\n<code-example\n path=\"docs-style-guide/src/app/app.module.ts\"\n region=\"class\">\n</code-example>\n\n

The path points to the file, just as in examples that render the entire file.\nThe region attribute specifies a portion of the source file delineated by an opening #docregion and a closing #enddocregion.

\n

You can see the class #docregion in the source file below.\nNotice the commented lines #docregion and #enddocregion in content/examples/docs-style-guide/src/app/app.module.ts with the name class.

\n\n\nimport { NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\nimport { FormsModule } from '@angular/forms';\n\nimport { AppComponent } from './app.component';\n\n// #docregion class\n@NgModule({\n imports: [ BrowserModule, FormsModule ],\n declarations: [ AppComponent ],\n bootstrap: [ AppComponent ]\n})\nexport class AppModule { }\n// #enddocregion class\n\n\n

The opening and ending #docregion lines designate any lines of code between them as being included in the code snippet.\nThis is why the import statements outside of the class #docregion are not in the code snippet.

\n

For more information on how to prepare example app files for use in guides, see\nSource code markup.

\n

Code snippet optionslink

\n

Specify the <code-example> output with the following attributes:

\n\n

Displaying bad codelink

\n

Occasionally, you want to display an example of less than ideal code or design, such as with avoid examples in the Angular Style Guide.\nBecause it is possible for readers to copy and paste examples of inferior code in their own applications, try to minimize use of such code.

\n

In cases where you need unacceptable examples, you can set the class to avoid or have the word avoid in the filename of the source file.\nBy putting the word avoid in the filename or path, the documentation generator automatically adds the avoid class to the <code-example>.\nEither of these options frames the code snippet in bright red to grab the reader's attention.

\n

Here's the markup for an \"avoid\" example in the\nAngular Style Guide that uses the word avoid in the path name:

\n\n<code-example\n path=\"styleguide/src/05-03/app/heroes/shared/hero-button/hero-button.component.avoid.ts\"\n region=\"example\"\n header=\"app/heroes/hero-button/hero-button.component.ts\">\n</code-example>\n\n

Having the word \"avoid\" in the file name causes the browser to render the code snippet with a red header and border:

\n\n/* avoid */\n\n@Component({\n selector: '[tohHeroButton]',\n templateUrl: './hero-button.component.html'\n})\nexport class HeroButtonComponent {}\n\n\n

Alternatively, the HTML could include the avoid class as in the following:

\n\n<code-example\n path=\"docs-style-guide/src/app/not-great.component.ts\"\n header=\"docs-style-guide/src/app/not-great.component.ts\"\n region=\"not-great\"\n class=\"avoid\">\n</code-example>\n\n

Explicitly applying the class avoid causes the same result of a red header and red border:

\n\nexport class NotGreatComponent {\n\n buggyFunction() {\n // things could be better here...\n }\n}\n\n\n\n

Code Tabslink

\n

Code tabs display code much like code-examples with the added advantage of displaying multiple code samples within a tabbed interface.\nEach tab displays code using a code-pane.

\n

code-tabs attributeslink

\n\n

code-pane attributeslink

\n\n

The following example displays multiple code tabs, each with its own header.\nIt demonstrates showing line numbers in <code-tabs> and <code-pane>.

\n\n\n \n<h1>{{title}}</h1>\n<h2>My Heroes</h2>\n<ul class=\"heroes\">\n <li *ngFor=\"let hero of heroes\"\n [class.selected]=\"hero === selectedHero\"\n (click)=\"onSelect(hero)\">\n <span class=\"badge\">{{hero.id}}</span> {{hero.name}}\n </li>\n</ul>\n<div *ngIf=\"selectedHero\">\n <h2>{{selectedHero.name}} details!</h2>\n <div><label>id: </label>{{selectedHero.id}}</div>\n <div>\n <label>name: </label>\n <input [(ngModel)]=\"selectedHero.name\" placeholder=\"name\"/>\n </div>\n</div>\n\n\n\n \nimport { Component } from '@angular/core';\nimport { Hero, HEROES } from './hero';\n\n@Component({\n selector: 'app-root',\n templateUrl: './app.component.html',\n styleUrls: ['./app.component.css']\n})\nexport class AppComponent {\n title = 'Authors Style Guide Sample';\n heroes = HEROES;\n selectedHero: Hero;\n\n onSelect(hero: Hero): void {\n this.selectedHero = hero;\n }\n}\n\n\n\n \n.heroes {\n margin: 0 0 2em 0;\n list-style-type: none;\n padding: 0;\n width: 15em;\n}\n\n\n \n{\n \"scripts\": {\n \"start\": \"concurrently \\\"npm run build:watch\\\" \\\"npm run serve\\\"\",\n \"test\": \"concurrently \\\"npm run build:watch\\\" \\\"karma start karma.conf.js\\\"\",\n \"lint\": \"tslint ./src/**/*.ts -t verbose\"\n }\n}\n\n\n\n\n\n

The linenums attribute set to true on <code-tabs> explicitly enables numbering for all panes.\nHowever, the linenums attribute set to false in the second <code-pane> disables line numbering only for itself.

\n\n<code-tabs linenums=\"true\">\n <code-pane\n header=\"app.component.html\"\n path=\"docs-style-guide/src/app/app.component.html\">\n </code-pane>\n <code-pane\n header=\"app.component.ts\"\n path=\"docs-style-guide/src/app/app.component.ts\"\n linenums=\"false\">\n </code-pane>\n <code-pane\n header=\"app.component.css (heroes)\"\n path=\"docs-style-guide/src/app/app.component.css\"\n region=\"heroes\">\n </code-pane>\n <code-pane\n header=\"package.json (scripts)\"\n path=\"docs-style-guide/package.1.json\">\n </code-pane>\n</code-tabs>\n\n\n

Preparing source code for code snippetslink

\n

To display <code-example> and <code-tabs> snippets, add code snippet markup to sample source code files.

\n
\n

The sample source code for this page, located in content/examples/docs-style-guide, contains examples of every code snippet markup described in this section.

\n
\n

Code snippet markup is always in the form of a comment.\nThe default #docregion markup for a TypeScript or JavaScript file is as follows:

\n\n// #docregion\n... some TypeScript or JavaScript code ...\n// #enddocregion\n\n\n<!-- #docregion -->\n... some HTML ...\n<!-- #enddocregion -->\n\n\n/* #docregion */\n... some CSS ...\n/* #enddocregion */\n\n

The documentation generation process erases these comments before displaying them in the documentation viewer, StackBlitz, and sample code downloads.

\n
\n

Because JSON does not allow comments, code snippet markup doesn't work in JSON files.\nSee the section on JSON files for more information.

\n
\n

#docregionlink

\n

Use #docregion in source files to mark code for use in <code-example> or <code-tabs> components.

\n

The #docregion comment begins a code snippet region.\nEvery line of code after that comment belongs in the region until the code fragment processor encounters the end of the file or a closing #enddocregion.

\n

The following src/main.ts is a an example of a file with a single #docregion at the top of the file.

\n\nimport { enableProdMode } from '@angular/core';\nimport { platformBrowserDynamic } from '@angular/platform-browser-dynamic';\n\nimport { AppModule } from './app/app.module';\nimport { environment } from './environments/environment';\n\nif (environment.production) {\n enableProdMode();\n}\n\nplatformBrowserDynamic().bootstrapModule(AppModule);\n\n\n\n

As a result, the entire file is in the <code-example>.

\n

Naming a #docregionlink

\n

To display multiple snippets from different fragments within the same file, give each fragment its own #docregion name as follows, where your-region-name is a hyphenated lowercase string:

\n\n// #docregion your-region-name\n... some code ...\n// #enddocregion your-region-name\n\n

Reference this region by name in the region attribute of the <code-example> or <code-pane> as follows:

\n\n<code-example\n path=\"your-example-app/src/app/your-file.ts\"\n region=\"your-region-name\"></code-example>\n\n

Because the #docregion with no name is the default region, you do not need to set the region attribute when referring to the default #docregion.

\n

Nesting a #docregionlink

\n

Place a #docregion within another #docregion as in the following example with a nested inner-region:

\n\n// #docregion\n... some code ...\n// #docregion inner-region\n... more code ...\n// #enddocregion inner-region\n... yet more code ...\n/// #enddocregion\n\n

Combining code fragmentslink

\n

Combine several fragments from the same file into a single code snippet by defining multiple #docregion sections with the same region name.\nThe following example defines two nested #docregion sections.

\n

The inner region, class-skeleton, appears twice—once to capture the code that opens the class definition and a second time to capture the code that closes the class definition.

\n\n\n// #docplaster\n...\n// #docregion class, class-skeleton\nexport class AppComponent {\n// #enddocregion class-skeleton\n title = 'Authors Style Guide Sample';\n heroes = HEROES;\n selectedHero: Hero;\n\n onSelect(hero: Hero): void {\n this.selectedHero = hero;\n }\n// #docregion class-skeleton\n}\n// #enddocregion class, class-skeleton\n\n\n

The #docplaster marker tells the processor what text string to use—that is, the \"plaster\"—to join each of the fragments into a single snippet.\nPlace the \"plaster\" text on the same line.\nFor example, #docplaster --- would use --- as the \"plaster\" text.\nIn the case of the previous file, the \"plaster\" text is empty so there will be nothing in between each fragment.

\n

Without #docplaster, the processor inserts the default plaster—an ellipsis comment—between the fragments.

\n

Here are the two corresponding code snippets for side-by-side comparison.

\n\n\n \nexport class AppComponent {\n title = 'Authors Style Guide Sample';\n heroes = HEROES;\n selectedHero: Hero;\n\n onSelect(hero: Hero): void {\n this.selectedHero = hero;\n }\n}\n\n\n \nexport class AppComponent {\n}\n\n\n\n\n

The above example also demonstrates that one #docregion or #enddocregion comment can specify two region names, which is a convenient way to start or stop multiple regions on the same code line.\nAlternatively, you could put these comments on separate lines as in the following example:

\n\n\n// #docplaster\n...\n// #docregion class\n// #docregion class-skeleton\nexport class AppComponent {\n// #enddocregion class-skeleton\n title = 'Authors Style Guide Sample';\n heroes = HEROES;\n selectedHero: Hero;\n\n onSelect(hero: Hero): void {\n this.selectedHero = hero;\n }\n// #docregion class-skeleton\n}\n// #enddocregion class\n// #enddocregion class-skeleton\n\n\n

JSON fileslink

\n

The <code-example> component cannot display portions of a JSON file because JSON forbids comments.\nHowever, you can display an entire JSON file by referencing it in the <code-example> src attribute.

\n

For large JSON files, you could copy the nodes-of-interest into Markdown backticks, but as it's easy to mistakenly create invalid JSON that way, consider creating a JSON partial file with the fragment you want to display.

\n

You can't test a partial file nor use it in the application, but at least your editor can confirm that it is syntactically correct.\nYou can also store the partial file next to the original, so it is more likely that the author will remember to keep the two in sync.

\n

Here's an example that excerpts certain scripts from package.json into a partial file named package.1.json.

\n\n{\n \"scripts\": {\n \"start\": \"concurrently \\\"npm run build:watch\\\" \\\"npm run serve\\\"\",\n \"test\": \"concurrently \\\"npm run build:watch\\\" \\\"karma start karma.conf.js\\\"\",\n \"lint\": \"tslint ./src/**/*.ts -t verbose\"\n }\n}\n\n\n\n\n<code-example path=\"docs-style-guide/package.1.json\" header=\"package.json (selected scripts)\"></code-example>\n\n

In some cases, it is preferable to use the name of the full file rather than the partial.\nIn this case, the full file is package.json and the partial file is package.1.json.\nSince the focus is generally on the full file rather than the partial, using the name of the file the reader edits, in this example package.json, clarifies which file to work in.

\n

Partial file naminglink

\n

The step-by-step nature of the guides necessitate refactoring, which means there are code snippets that evolve through a guide.

\n

Use partial files to demonstrate intermediate versions of the final source code with fragments of code that don't appear in the final app.\nThe sample naming convention adds a number before the file extension, as follows:

\n\npackage.1.json\napp.component.1.ts\napp.component.2.ts\n\n

Remember to exclude these files from StackBlitz by listing them in the stackblitz.json as illustrated here:

\n\n{\n \"description\": \"Authors style guide\",\n \"files\": [\n \"!**/*.d.ts\",\n \"!**/*.js\",\n \"!**/*.[1,2,3].*\"\n ],\n \"tags\": [\"author\", \"style guide\"]\n}\n\n\n\n\n

Live exampleslink

\n

Adding <live-example></live-example> to a page generates two default links: .

\n

The first is a link to the StackBlitz example, which the default stackblitz.json file defines.\nYou can find the stackblitz.json file in the content/examples/example-app directory, where example-app is the sample application folder you're using for the guide.

\n

By default, the documentation generator uses the name of the guide as the name of the example.\nSo, if you're working on router.md, and use <live-example></live-example> in the document, the documentation generator looks for content/examples/router.\nClicking this link opens the code sample on StackBlitz in a new browser tab.

\n

The second link downloads the sample app.

\n

Define live examples by one or more stackblitz.json files in the root of a code sample folder.\nEach sample folder usually has a single unnamed definition file, the default stackblitz.json.

\n

Live Example for named StackBlitzlink

\n

You can create additional, named definition files in the form name.stackblitz.json.\nThe Testing guide (aio/content/guide/testing.md) references a named StackBlitz file as follows:

\n\n<live-example stackblitz=\"specs\">Tests</live-example>\n\n

The stackblitz attribute value of specs refers to the examples/testing/specs.stackblitz.json file.\nIf you were to leave out the stackblitz attribute, the default would be examples/testing/stackblitz.json.

\n

Custom label and tooltiplink

\n

Change the appearance and behavior of the live example with attributes and classes.\nThe following example gives the live example anchor a custom label and tooltip by setting the title attribute:

\n\n<live-example title=\"Live Example with title\"></live-example>\n\n

The browser renders the following:

\n

\n

You can achieve the same effect by putting the label between the <live-example> tags:

\n\n<live-example>Live example with content label</live-example>\n\n

The browser renders the following:

\n

Live example with content label

\n

Live example from another guidelink

\n

To link to an example in a folder where the name is not the same as the current guide page, set the name attribute to the name of that folder.

\n

For example, to include the Router guide example in this style guide, set the name attribute to router, that is, the name of the folder where that example resides.

\n\n<live-example name=\"router\">Live example from the Router guide</live-example>\n\n

Live example from the Router guide

\n

Live Example without downloadlink

\n

To omit the download link, add the noDownload attribute.

\n\n<live-example noDownload>Just the StackBlitz</live-example>\n\n

The browser renders the following:

\n

Just the StackBlitz

\n

Live Example with download-onlylink

\n

To omit the live StackBlitz link and only link to the download, add the downloadOnly attribute.

\n\n<live-example downloadOnly>Download only</live-example>\n\n

The browser renders the following:

\n

Download only

\n

Embedded live examplelink

\n

By default, a live example link opens a StackBlitz example in a separate browser tab.\nYou can embed the StackBlitz example within the guide page by adding the embedded attribute.

\n

For performance reasons, StackBlitz does not start right away.\nInstead, the <live-example> component renders an image.\nClicking the image starts the process of launching the embedded StackBlitz within an <iframe>.

\n

The following is an embedded <live-example> for this guide:

\n\n<live-example embedded></live-example>\n\n

The browser renders the following <iframe> and a <p> with a link to download the example:

\n

\n\n

Anchorslink

\n

Every section header is also an anchor point.\nAnother guide page could add a link to this \"Anchors\" section with the following:

\n\n<div class=\"alert is-helpful\">\n\nSee the [\"Anchors\"](guide/docs-style-guide#anchors \"Style Guide&mdash;Anchors\") section for details.\n\n</div>\n\n

The browser renders the following:

\n
\n

See the \"Anchors\" section for details.

\n
\n

Notice that the above example includes a title of \"Style Guide—Anchors\".\nUse titles on anchors to create tooltips and improve UX.

\n

When navigating within a page, you can omit the page URL when specifying the link that scrolls up to the beginning of this section, as in the following:

\n\n... the link that [scrolls up](#anchors \"Anchors\") to ...\n\n\n

Section header anchorslink

\n

While the documentation generator automatically creates anchors for headers based on the header wording, titles can change, which can potentially break any links to that section.

\n

To mitigate link breakage, add a custom anchor explicitly, just above the heading or text to which it applies, using the special syntax as follows:

\n\n {@a section-anchors}\n\n #### Section header anchors\n\n

Then reference that anchor like this:

\n\nThis is a [link to that custom anchor name](#section-anchors).\n\n

The browser renders the following:

\n

This is a link to that custom anchor name.

\n

When editing a file, don't remove any anchors.\nIf you change the document structure, you can move an existing anchor within that same doc without breaking a link.\nYou can also add more anchors with more appropriate text.

\n
\n

As an alternative, you can use the HTML <a> tag.\nWhen using the <a> tag, set the id attribute—rather than the name attribute because the documentation generator does not convert the name to the proper link URL.\nFor example:

\n\n<a id=\"anchors\"></a>\n\n## Anchors\n\n
\n

Alerts and calloutslink

\n

Alerts and callouts present warnings, extra detail, or references to related topics.

\n

An alert or callout should not contain anything essential to understanding the main content.\nInstructions or tutorial steps should be in the main body of a guide rather than in a subsection.

\n

Alertslink

\n

Alerts draw attention to short, important points.\nFor multi-line content, see callouts.

\n
\n

See the live examples section for more information.

\n
\n

Note that at least one blank line must follow both the opening and closing <div> tags.\nA blank line before the closing </div> is conventional but not required.

\n\n<div class=\"alert is-helpful\">\n\n See the [live examples](guide/docs-style-guide#live-examples \"Live examples\") section for more information.\n\n</div>\n\n

There are three different levels for styling the alerts according to the importance of the content.

\n

Use the following the alert class along with the appropriate is-helpful, is-important, or is-critical CSS class, as follows:

\n\n<div class=\"alert is-helpful\">\n\nA helpful, informational alert.\n\n</div>\n\n\n<div class=\"alert is-important\">\n\nAn important alert.\n\n</div>\n\n\n<div class=\"alert is-critical\">\n\nA critical alert.\n\n</div>\n\n

The browser renders the following:

\n
\n

A helpful, informational alert.

\n
\n
\n

An important alert.

\n
\n
\n

A critical alert.

\n
\n

Calloutslink

\n

Callouts, like alerts, highlight important points.\nUse a callout when you need a header and multi-line content.

\n

If you have more than two paragraphs, consider creating a new page or making it part of the main content.

\n

Callouts use the same styling levels as alerts.

\n

Use the CSS class callout in conjunction with the appropriate is-helpful, is-important, or is-critical class.\nThe following example uses the is-helpful class:

\n\n<div class=\"callout is-helpful\">\n\n<header>A helpful or informational point</header>\n\n **A helpful note**. Use a helpful callout for information requiring explanation.\n Callouts are typically multi-line notes.\n They can also contain code snippets.\n\n</div>\n\n

The browser renders the three styles as follows:

\n
\n
A helpful or informational point
\n

A helpful note. Use a helpful callout for information requiring explanation.\nCallouts are typically multi-line notes.\nThey can also contain code snippets.

\n
\n
\n
An important point
\n

An important note. Use an important callout for significant information requiring explanation.\nCallouts are typically multi-line notes.\nThey can also contain code snippets.

\n
\n
\n
A critical point
\n

A critical note. Use a critical callout for compelling information requiring explanation.\nCallouts are typically multi-line notes.\nThey can also contain code snippets.

\n
\n

When using callouts, consider the following points:

\n\n

Use callouts sparingly to grab the user's attention.

\n

Treeslink

\n

Use trees to represent hierarchical data such as directory structure.

\n
\n
\n sample-dir\n
\n
\n
\n src\n
\n
\n
\n app\n
\n
\n
\n app.component.ts\n
\n
\n app.module.ts\n
\n
\n
\n styles.css\n
\n
\n tsconfig.json\n
\n
\n
\n node_modules ...\n
\n
\n package.json\n
\n
\n
\n

Here is the markup for this file tree.

\n\n<div class='filetree'>\n <div class='file'>\n sample-dir\n </div>\n <div class='children'>\n <div class='file'>\n src\n </div>\n <div class='children'>\n <div class='file'>\n app\n </div>\n <div class='children'>\n <div class='file'>\n app.component.ts\n </div>\n <div class='file'>\n app.module.ts\n </div>\n </div>\n <div class='file'>\n styles.css\n </div>\n <div class='file'>\n tsconfig.json\n </div>\n </div>\n <div class='file'>\n node_modules ...\n </div>\n <div class='file'>\n package.json\n </div>\n </div>\n</div>\n\n

Tableslink

\n

Use HTML tables to present tabular data.

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Header TypeMarkdownUse
<h1>#Title of page
<h2>##\n

Second level headers

\n
<h3>###\n

Third level headers

\n
\n

The following is the markup for this table:

\n\n<table>\n <tr>\n <th>Header Type</th>\n <th>Markdown</th>\n <th>Use</th>\n </tr>\n <tr>\n <td><code>&lt;h1&gt;</code></td>\n <td>#</td>\n <td>Title of page</td>\n </tr>\n <tr>\n <td><code>&lt;h2&gt;</code></td>\n <td>##</td>\n <!-- can use Markdown too; remember blank lines -->\n <td>\n\n **Second level headers**\n\n </td>\n </tr>\n <tr>\n <td><code>&lt;h3&gt;</code></td>\n <td>###</td>\n <td>\n\n **Third level headers**\n\n </td>\n </tr>\n</table>\n\n

Imageslink

\n

Store images in the content/images/guide directory in a folder with the same name as the guide page.\nBecause Angular documentation generation copies these images to generated/images/guide/your-guide-directory, set the image src attribute to the runtime location of generated/images/guide/your-guide-directory.

\n

For example, images for this \"Angular documentation style guide\" are in the content/images/guide/docs-style-guide folder, but the src attribute specifies the generated location.

\n

The following is the src attribute for the \"flying hero\" image belonging to this guide:

\n\nsrc=\"generated/images/guide/docs-style-guide/flying-hero.png\"\n\n
\n
Use the HTML <img> tag
\n

Specify images using the <img> tag.\nDo not use the Markdown image syntax, ![...](...).

\n

For accessibility, always set the alt attribute with a meaningful description of the image.

\n

Nest the <img> tag within a <div class=\"lightbox\"> tag, which styles the image according to the documentation standard.

\n\n<div class=\"lightbox\">\n <img src=\"generated/images/guide/docs-style-guide/flying-hero.png\" alt=\"flying hero\">\n</div>\n\n

Note that the HTML <img> element does not have a closing tag.

\n

The browser renders the following:

\n
\n \"flying\n
\n
\n

Image captions and figure captionslink

\n

A caption appears underneath the image as a concise and comprehensive summary of the image.\nCaptions are optional unless you are using numbered figures, such as Figure 1, Figure 2, and so on.\nIf you are using numbered figures in a page, follow the guidelines in Figure captions in the Google Developer Documentation Style Guide.

\n

Image dimensionslink

\n

The doc generator reads the image dimensions from an image file and adds width and height attributes to the <img> tag automatically.

\n

To control the size of the image, supply your own width and height attributes.

\n

Here's the \"flying hero\" markup with a 200px width:

\n\n<div class=\"lightbox\">\n <img src=\"generated/images/guide/docs-style-guide/flying-hero.png\"\n alt=\"flying Angular hero\"\n width=\"200\">\n</div>\n\n

The browser renders the following:

\n
\n

\"flying

\n
\n

Wide imageslink

\n

To prevent images overflowing their viewports, use image widths under 700px.\nTo display a larger image, provide a link to the actual image that the user can click to see the full size image separately, as in this example of source-map-explorer output from the \"Ahead-of-time Compilation\" guide:

\n\n
\n \"toh-pt6-bundle\"\n
\n
\n

The following is the HTML for creating a link to the image:

\n\n<a href=\"generated/images/guide/docs-style-guide/toh-pt6-bundle.png\" title=\"Click to view larger image\">\n <div class=\"lightbox\">\n <img src=\"generated/images/guide/docs-style-guide/toh-pt6-bundle-700w.png\" alt=\"toh-pt6-bundle\" width=\"300px\">\n </div>\n</a>\n\n

Image compressionlink

\n

For faster load times, always compress images.\nConsider using an image compression web site such as tinypng.

\n

Floated imageslink

\n

You can float the image to the left or right of text by applying the class=\"left\" or class=\"right\" attributes respectively.\nFor example:

\n\n<img src=\"generated/images/guide/docs-style-guide/flying-hero.png\"\n alt=\"flying Angular hero\"\n width=\"200\"\n class=\"left\">\n\nThis text wraps around to the right of the floating \"flying hero\" image.\n\nHeadings and code-examples automatically clear a floated image. If you need to force a piece of text to clear a floating image, add `<br class=\"clear\">` where the text should break.\n\n<br class=\"clear\">\n\n

The browser renders the following:

\n

\"flying

\n

This text wraps around to the right of the floating \"flying hero\" image.

\n

Headings and <code-example> components automatically clear a floated image.\nTo explicitly clear a floated image, add <br class=\"clear\"> where the text should break.

\n
\n

Generally, you don't wrap a floated image in a <figure> element.

\n

Floats within a subsectionlink

\n

If you have a floated image inside an alert, callout, or a subsection, apply the clear-fix class to the <div> to ensure that the image doesn't overflow its container.\nFor example:

\n\n<div class=\"alert is-helpful clear-fix\">\n\n <img src=\"generated/images/guide/docs-style-guide/flying-hero.png\"\n alt=\"flying Angular hero\"\n width=\"100\"\n class=\"right\">\n\n A subsection with **Markdown** formatted text.\n\n</div>\n\n

The browser renders the following:

\n
\n

\"flying

\n

A subsection with Markdown formatted text.

\n
\n

Help with documentation stylelink

\n

For specific language and grammar usage, a word list, style, tone, and formatting recommendations, see the Google Developer Documentation Style Guide.

\n

If you have any questions that this style guide doesn't answer or you would like to discuss documentation styles visit the Angular repo and file a documentation issue.

\n\n \n
\n\n\n" }