---
title: "hidden(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/tabcontent/hidden(_:)"
---

# hidden(_:)

Hides the tab from the user.

## Declaration

```swift
nonisolated func hidden(_ hidden: Bool = true) -> some TabContent<Self.TabValue>

```

## Parameters

- `hidden`: Whether the tab is hidden.

## Discussion

Discussion Unlike removing or adding tabs with if statements, this modifier preserves the associated state of the tab’s content view when the tab is hidden. When you hide a tab using this modifier, make sure to update the TabView’s selection appropriately, since that tab could be selected. The following example shows a TabView with 4 tabs in compact and 5 tabs in regular. In compact, one of the tabs is a ‘Browse’ tab that displays a custom list view. This list view allows navigating to the destinations that are contained within the ‘Library’ and ‘Playlists’ sections in regular. The navigation path and the selection state are updated when the number of tabs changes. struct BrowseTabExample: View {     @Environment(\.horizontalSizeClass) var sizeClass

@State var selection: MusicTab = .listenNow     @State var browseTabPath: [MusicTab] = []     @State var playlists = [Playlist("All Playlists"), Playlist("Running")]

var body: some View {             TabView(selection: $selection) {                 Tab("Listen Now", systemImage: "play.circle", value: .listenNow) {                     ListenNowView()                 }

Tab("Radio", systemImage: "dot.radiowaves.left.and.right", value: .radio) {                     RadioView()                 }

Tab("Search", systemImage: "magnifyingglass", value: .search) {                     SearchDetailView()                 }

Tab("Browse", systemImage: "list.bullet", value: .browse) {                     LibraryView(path: $browseTabPath)                 }                 .hidden(sizeClass != .compact)

TabSection("Library") {                     Tab("Recently Added", systemImage: "clock", value: MusicTab.library(.recentlyAdded)) {                         RecentlyAddedView()                     }

Tab("Artists", systemImage: "music.mic", value: MusicTab.library(.artists)) {                         ArtistsView()                     }                 }                 .hidden(sizeClass == .compact)

TabSection("Playlists") {                     ForEach(playlists) { playlist in                         Tab(playlist.name, image: playlist.image, value: MusicTab.playlists(playlist)) {                             playlist.detailView()                         }                     }                 }                 .hidden(sizeClass == .compact)             }             .tabViewStyle(.sidebarAdaptable)             .onChange(of: sizeClass, initial: true) { _, sizeClass in                 if sizeClass == .compact && selection.showInBrowseTab {                     browseTabPath = [selection]                     selection = .browse                 } else if sizeClass == .regular && selection == .browse {                     selection = browseTabPath.last ?? .library(.recentlyAdded)                 }             }         }     } }

struct LibraryView: View {     @Binding var path: [MusicTab]

var body: some View {         NavigationStack(path: $path) {             List {                 ForEach(MusicLibraryTab.allCases, id: \.self) { tab in                     NavigationLink(tab.rawValue, value: MusicTab.library(tab))                 }                 // Code to add playlists here             }             .navigationDestination(for: MusicTab.self) { tab in                 tab.detail()             }         }     } }

## See Also

### Configuring tab content

- [badge(_:)](swiftui/tabcontent/badge(_:).md)
- [contextMenu(menuItems:)](swiftui/tabcontent/contextmenu(menuitems:).md)
- [customizationBehavior(_:for:)](swiftui/tabcontent/customizationbehavior(_:for:).md)
- [customizationID(_:)](swiftui/tabcontent/customizationid(_:).md)
- [defaultSectionExpansion(_:)](swiftui/tabcontent/defaultsectionexpansion(_:).md)
- [TabSectionExpansion](swiftui/tabsectionexpansion.md)
- [defaultVisibility(_:for:)](swiftui/tabcontent/defaultvisibility(_:for:).md)
- [disabled(_:)](swiftui/tabcontent/disabled(_:).md)
- [draggable(_:)](swiftui/tabcontent/draggable(_:).md)
- [dropDestination(for:action:)](swiftui/tabcontent/dropdestination(for:action:).md)
- [help(_:)](swiftui/tabcontent/help(_:).md)
- [popover(isPresented:attachmentAnchor:arrowEdge:content:)](swiftui/tabcontent/popover(ispresented:attachmentanchor:arrowedge:content:).md)
- [popover(item:attachmentAnchor:arrowEdge:content:)](swiftui/tabcontent/popover(item:attachmentanchor:arrowedge:content:).md)
- [sectionActions(content:)](swiftui/tabcontent/sectionactions(content:).md)
- [springLoadingBehavior(_:)](swiftui/tabcontent/springloadingbehavior(_:).md)
