Skip to main content
Sometimes changing the programming language or framework changes more than the code. The headings, explanations, and procedure may all follow a different path. The <View> component lets readers make that choice once and see the version of the page that applies to them. Use views for page-level variation. If only one section or code sample changes, a smaller component will be easier to follow.

How views work

Each <View> block has a title that appears in a dropdown above the table of contents. When a reader chooses a title, the page shows its matching blocks and updates the table of contents.
Example of views
Try the selector above this page’s table of contents. Switching between JavaScript and Python changes the example below.

JavaScript example

Choose the smallest component that fits

Views, tabs, and code groups all show variations, but at different scales:
  • Use <CodeGroup> when the explanation stays the same and only the code changes.
  • Use <Tabs> when one section changes based on the reader’s platform, role, or another known context.
  • Use <View> when the selection changes headings, explanations, or several examples across the page.
For example, an SDK guide may use views when its JavaScript version explains promises while its Python version explains synchronous and asynchronous clients. Those differences affect the page’s structure, not just a code block.

Keep shared information visible

Put introductions, prerequisites, and warnings that apply to every reader outside the view blocks. Duplicating them creates extra maintenance, while placing them in only one view hides them from everyone else. Views are also a poor fit when readers need to compare the options before choosing. The selector shows one version at a time, so use a table or visible sections for a comparison. Don’t use views simply to shorten a page. The hidden content should be an alternative version, not required information that every reader needs.
Next up: Tables for structured comparisons — When grid layouts communicate relationships better than prose or cards.