|
| 1 | +--- |
| 2 | +title: Tab variants |
| 3 | +description: Create multiple content variations within a single tab using variants in Fern Docs navigation. |
| 4 | +--- |
| 5 | + |
| 6 | +Tab variants allow you to display different content variations within a single tab. This is useful when you want to show different perspectives, user types, or implementation approaches for the same topic without creating separate tabs. |
| 7 | + |
| 8 | +## Basic usage |
| 9 | + |
| 10 | +To use tab variants, define a tab with a `variants` property instead of a `layout` property. Each variant has its own title, layout, and optional configuration. |
| 11 | + |
| 12 | +```yaml title="docs.yml" |
| 13 | +tabs: |
| 14 | + guides: |
| 15 | + display-name: Guides |
| 16 | + icon: book |
| 17 | + |
| 18 | +navigation: |
| 19 | + - tab: guides |
| 20 | + variants: |
| 21 | + - title: For developers |
| 22 | + layout: |
| 23 | + - section: Getting started |
| 24 | + contents: |
| 25 | + - page: Quick start |
| 26 | + path: ./pages/dev-quickstart.mdx |
| 27 | + - page: API integration |
| 28 | + path: ./pages/dev-api.mdx |
| 29 | + - title: For product managers |
| 30 | + layout: |
| 31 | + - section: Getting started |
| 32 | + contents: |
| 33 | + - page: Overview |
| 34 | + path: ./pages/pm-overview.mdx |
| 35 | + - page: Use cases |
| 36 | + path: ./pages/pm-use-cases.mdx |
| 37 | +``` |
| 38 | +
|
| 39 | +## Setting a default variant |
| 40 | +
|
| 41 | +By default, the first variant in the list is displayed. You can explicitly set which variant should be the default by adding `default: true` to a variant. |
| 42 | + |
| 43 | +```yaml title="docs.yml" {11} |
| 44 | +navigation: |
| 45 | + - tab: guides |
| 46 | + variants: |
| 47 | + - title: Advanced |
| 48 | + layout: |
| 49 | + - section: Advanced topics |
| 50 | + contents: |
| 51 | + - page: Custom integrations |
| 52 | + path: ./pages/advanced.mdx |
| 53 | + - title: Beginner |
| 54 | + default: true |
| 55 | + layout: |
| 56 | + - section: Getting started |
| 57 | + contents: |
| 58 | + - page: Introduction |
| 59 | + path: ./pages/intro.mdx |
| 60 | +``` |
| 61 | + |
| 62 | +In this example, the "Beginner" variant displays by default even though it's listed second. |
| 63 | + |
| 64 | +## Variant properties |
| 65 | + |
| 66 | +Each variant supports the following properties: |
| 67 | + |
| 68 | +### Required properties |
| 69 | + |
| 70 | +- `title` (string): The display name for the variant |
| 71 | +- `layout` (list): The navigation structure for this variant, using the same format as regular tab layouts |
| 72 | + |
| 73 | +### Optional properties |
| 74 | + |
| 75 | +- `subtitle` (string): A subtitle displayed below the variant title |
| 76 | +- `icon` (string): A [Font Awesome icon](https://fontawesome.com/icons) name |
| 77 | +- `slug` (string): Custom URL slug for the variant |
| 78 | +- `skip-slug` (boolean): If true, the variant slug won't be added to URLs |
| 79 | +- `hidden` (boolean): If true, the variant is hidden from the navigation |
| 80 | +- `default` (boolean): If true, this variant displays by default |
| 81 | +- `viewers` (string or list): Role-based access control for the variant |
| 82 | +- `feature-flag` (string or object): Feature flag configuration for conditional display |
| 83 | + |
| 84 | +## Complete example |
| 85 | + |
| 86 | +Here's a comprehensive example showing multiple variants with various properties: |
| 87 | + |
| 88 | +```yaml title="docs.yml" |
| 89 | +tabs: |
| 90 | + documentation: |
| 91 | + display-name: Documentation |
| 92 | + icon: book |
| 93 | +
|
| 94 | +navigation: |
| 95 | + - tab: documentation |
| 96 | + variants: |
| 97 | + - title: REST API |
| 98 | + subtitle: HTTP-based integration |
| 99 | + icon: fa-solid fa-code |
| 100 | + slug: rest |
| 101 | + default: true |
| 102 | + layout: |
| 103 | + - section: Authentication |
| 104 | + contents: |
| 105 | + - page: API keys |
| 106 | + path: ./pages/rest/auth.mdx |
| 107 | + - api: REST API Reference |
| 108 | + |
| 109 | + - title: GraphQL API |
| 110 | + subtitle: Query-based integration |
| 111 | + icon: fa-solid fa-diagram-project |
| 112 | + slug: graphql |
| 113 | + layout: |
| 114 | + - section: Authentication |
| 115 | + contents: |
| 116 | + - page: OAuth setup |
| 117 | + path: ./pages/graphql/auth.mdx |
| 118 | + - api: GraphQL API Reference |
| 119 | + |
| 120 | + - title: SDKs |
| 121 | + subtitle: Client libraries |
| 122 | + icon: fa-solid fa-cube |
| 123 | + slug: sdks |
| 124 | + layout: |
| 125 | + - section: Client libraries |
| 126 | + contents: |
| 127 | + - page: TypeScript |
| 128 | + path: ./pages/sdks/typescript.mdx |
| 129 | + - page: Python |
| 130 | + path: ./pages/sdks/python.mdx |
| 131 | +``` |
| 132 | + |
| 133 | +## Use cases |
| 134 | + |
| 135 | +Tab variants are particularly useful for: |
| 136 | + |
| 137 | +- **Multiple API types**: Show REST, GraphQL, and gRPC documentation in the same tab |
| 138 | +- **User personas**: Provide different content for developers, product managers, and administrators |
| 139 | +- **Implementation approaches**: Display different integration methods (SDK, REST API, CLI) |
| 140 | +- **Experience levels**: Separate beginner and advanced content |
| 141 | +- **Platform-specific guides**: Show iOS, Android, and web documentation variants |
| 142 | + |
| 143 | +## Variants vs. tabs |
| 144 | + |
| 145 | +Use **variants** when you want to show different perspectives or approaches to the same content area. Use **tabs** when you want to organize completely different sections of your documentation (like separating guides from API reference). |
| 146 | + |
| 147 | +```yaml title="When to use variants" |
| 148 | +# Good: Different approaches to the same topic |
| 149 | +navigation: |
| 150 | + - tab: integration |
| 151 | + variants: |
| 152 | + - title: REST API |
| 153 | + layout: [...] |
| 154 | + - title: GraphQL |
| 155 | + layout: [...] |
| 156 | +``` |
| 157 | + |
| 158 | +```yaml title="When to use separate tabs" |
| 159 | +# Good: Completely different documentation sections |
| 160 | +navigation: |
| 161 | + - tab: guides |
| 162 | + layout: [...] |
| 163 | + - tab: api-reference |
| 164 | + layout: [...] |
| 165 | +``` |
| 166 | + |
| 167 | +## Permissions and feature flags |
| 168 | + |
| 169 | +Variants support role-based access control and feature flags, allowing you to show different content to different users: |
| 170 | + |
| 171 | +```yaml title="docs.yml" |
| 172 | +navigation: |
| 173 | + - tab: documentation |
| 174 | + variants: |
| 175 | + - title: Public documentation |
| 176 | + viewers: public |
| 177 | + layout: |
| 178 | + - section: Getting started |
| 179 | + contents: |
| 180 | + - page: Introduction |
| 181 | + path: ./pages/intro.mdx |
| 182 | + |
| 183 | + - title: Internal documentation |
| 184 | + viewers: internal |
| 185 | + layout: |
| 186 | + - section: Internal guides |
| 187 | + contents: |
| 188 | + - page: Architecture |
| 189 | + path: ./pages/internal/architecture.mdx |
| 190 | +``` |
| 191 | + |
| 192 | +For more information on permissions, see [Role based access control](/learn/docs/authentication/rbac). |
0 commit comments