---
title: "Collapse Sidebar Sections by Default | Explore SwiftUI"
description: "Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples."
canonical_url: "https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default"
meta:
  author: "Explore SwiftUI"
  "og:description": "Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples."
  "og:image": "https://exploreswiftui.com/_og/d/c_Component%2Ctitle_Collapse%2BSidebar%2BSections%2Bby%2BDefault%2Cdescription_Explore%2Bvisually%2Bwith%2Bcode%2Bexamples%2Ccategory_TabView%2Cprops_eyJwbGF0Zm9ybXMiOlsiaU9TIiwiaVBhZE9TIiwibWFjT1MiLCJ3YXRjaE9TIiwidHZPUyIsInZpc2lvbk9TIl19%2Cp_Ii9saWJyYXJ5L3RhYnZpZXcvY29sbGFwc2Utc2lkZWJhci1zZWN0aW9ucy1ieS1kZWZhdWx0Ig%2Cs_164BSB-Ho3X3EMuq.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Collapse Sidebar Sections by Default | Explore SwiftUI"
  "twitter:description": "Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples."
  "twitter:image": "https://exploreswiftui.com/_og/d/c_Component%2Ctitle_Collapse%2BSidebar%2BSections%2Bby%2BDefault%2Cdescription_Explore%2Bvisually%2Bwith%2Bcode%2Bexamples%2Ccategory_TabView%2Cprops_eyJwbGF0Zm9ybXMiOlsiaU9TIiwiaVBhZE9TIiwibWFjT1MiLCJ3YXRjaE9TIiwidHZPUyIsInZpc2lvbk9TIl19%2Cp_Ii9saWJyYXJ5L3RhYnZpZXcvY29sbGFwc2Utc2lkZWJhci1zZWN0aW9ucy1ieS1kZWZhdWx0Ig%2Cs_164BSB-Ho3X3EMuq.png"
  "twitter:title": "Collapse Sidebar Sections by Default | Explore SwiftUI"
---

> Index of every page on this site: [llms.txt](https://exploreswiftui.com/llms.txt)

# **Collapse Sidebar Sections by Default**

Collapses the section in the sidebar by default.

![Collapse Sidebar Sections by Default - Preview Not Available](https://exploreswiftui.com/api/images/259/variants/2039?v=1792566366133&r=2&w=800&q=80&f=webp)

### **Platform Compatibility**

iOS 27.0+ iPadOS 27.0+ macOS 27.0+ watchOS 27.0+ tvOS 27.0+ visionOS 27.0+

### **Tags**

### **SwiftUI Code**

[ Docs](https://developer.apple.com/documentation/swiftui/tabsectionexpansion/collapsed)

```
TabView {
    TabSection("Foo") {
        Tab("1", systemImage: "1.circle") {
            Text("0")
        }
    }
    .defaultSectionExpansion(.collapsed)

    TabSection("Bar") {
        Tab("3", systemImage: "3.circle") {
            Text("2")
        }
    }

    TabSection("FooBar") {
        Tab("5", systemImage: "5.circle") {
            Text("4")
        }
    }
}
.tabViewStyle(.sidebarAdaptable)
```

### **Found an issue or have a suggestion?**

Created: October 21, 2026Updated: October 21, 2026

![Connect Wizard](https://exploreswiftui.com/_ipx/f_webp&q_80&s_48x48/images/connect-wizard-icon.png)

**Connect Wizard**

**Unlock insights App Store Connect doesn’t show you.**

[** Get Started **](https://apps.apple.com/app/apple-store/id6747314580?pt=121213751&ct=Explore%20SwiftUI%20Banner&mt=8)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://exploreswiftui.com/#website","@type":"WebSite","description":"A visual library for SwiftUI APIs, components, and modifiers","inLanguage":"en-US","name":"Explore SwiftUI","url":"https://exploreswiftui.com/","publisher":{"@id":"https://exploreswiftui.com/#identity"}},{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#webpage","@type":"WebPage","dateModified":"2026-10-21T07:06:06.143Z","datePublished":"2026-10-21T07:02:19.500Z","description":"Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples.","name":"Collapse Sidebar Sections by Default","url":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default","breadcrumb":{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#breadcrumb"},"isPartOf":{"@id":"https://exploreswiftui.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default"]}],"primaryImageOfPage":{"@id":"https://exploreswiftui.com/#logo"}},{"@id":"https://exploreswiftui.com/#identity","@type":"Organization","description":"A visual library for SwiftUI APIs, components, and modifiers","name":"Explore SwiftUI","url":"https://exploreswiftui.com","logo":{"@id":"https://exploreswiftui.com/#logo"},"sameAs":["https://x.com/Typ0genius","https://mastodon.social/@Typ0genius"]},{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#article","dateModified":"2026-10-21T07:06:06.143Z","datePublished":"2026-10-21T07:02:19.500Z","description":"Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples.","headline":"Collapse Sidebar Sections by Default","inLanguage":"en-US","name":"Collapse Sidebar Sections by Default","thumbnailUrl":"https://exploreswiftui.com/api/images/259/variants/2039?v=1792566366133&r=2","url":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default","@type":["Article","TechArticle"],"about":{"@type":"Thing","name":"SwiftUI"},"author":{"@id":"https://exploreswiftui.com/#identity"},"image":{"@id":"https://exploreswiftui.com/#/schema/image/1"},"isPartOf":{"@type":"WebSite","name":"Explore SwiftUI","url":"https://exploreswiftui.com"},"mainEntityOfPage":{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#webpage"},"publisher":{"@id":"https://exploreswiftui.com/#identity"}},{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#/schema/software-source-code/1","@type":"SoftwareSourceCode","codeRepository":"https://developer.apple.com/documentation/swiftui/tabsectionexpansion/collapsed","codeSampleType":"full example","description":"Collapses the section in the sidebar by default. Learn how to use Collapse Sidebar Sections by Default in SwiftUI with visual code examples.","name":"Collapse Sidebar Sections by Default SwiftUI Example","programmingLanguage":"Swift","runtimePlatform":"SwiftUI","text":"TabView {\n    TabSection(\"Foo\") {\n        Tab(\"1\", systemImage: \"1.circle\") {\n            Text(\"0\")\n        }\n    }\n    .defaultSectionExpansion(.collapsed)\n\n    TabSection(\"Bar\") {\n        Tab(\"3\", systemImage: \"3.circle\") {\n            Text(\"2\")\n        }\n    }\n\n    TabSection(\"FooBar\") {\n        Tab(\"5\", systemImage: \"5.circle\") {\n            Text(\"4\")\n        }\n    }\n}\n.tabViewStyle(.sidebarAdaptable)","about":[{"@type":"Thing","name":"SwiftUI"},{"@type":"Thing","name":"TabView"},{"@type":"Thing","name":"Collapse Sidebar Sections by Default"}]},{"@id":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Home","item":"https://exploreswiftui.com","position":1},{"@type":"ListItem","name":"TabView","item":"https://exploreswiftui.com/library/tabview","position":2},{"@type":"ListItem","name":"Collapse Sidebar Sections by Default","item":"https://exploreswiftui.com/library/tabview/collapse-sidebar-sections-by-default","position":3}]},{"@id":"https://exploreswiftui.com/#logo","@type":"ImageObject","caption":"Explore SwiftUI","contentUrl":"https://exploreswiftui.com/apple-touch-icon.png","inLanguage":"en","url":"https://exploreswiftui.com/apple-touch-icon.png"},{"@id":"https://exploreswiftui.com/#/schema/image/1","@type":"ImageObject","contentUrl":"https://exploreswiftui.com/api/images/259/variants/2039?v=1792566366133&r=2","inLanguage":"en","url":"https://exploreswiftui.com/api/images/259/variants/2039?v=1792566366133&r=2"}]}
```