<!--
{
  "documentType" : "article",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Menus-and-commands",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Menus and commands"
}
-->

# Menus and commands

Provide space-efficient, context-dependent access to commands and controls.

## Overview

Use a menu to provide people with easy access to common commands. You can add
items to a macOS or iPadOS app’s menu bar using the [`commands(content:)`](/documentation/SwiftUI/Scene/commands(content:)) scene
modifier, or create context menus that people reveal near their current task
using the [`contextMenu(menuItems:)`](/documentation/SwiftUI/View/contextMenu(menuItems:)) view modifier.

![](images/com.apple.SwiftUI/menus-and-commands-hero@2x.png)

Create submenus by nesting [`Menu`](/documentation/SwiftUI/Menu) instances inside others. Use a [`Divider`](/documentation/SwiftUI/Divider)
view to create a separator between menu elements.

For design guidance, see
<doc://com.apple.documentation/design/Human-Interface-Guidelines/menus>
in the Human Interface Guidelines.

## Topics

### Building a menu bar

[Building and customizing the menu bar with SwiftUI](/documentation/SwiftUI/Building-and-customizing-the-menu-bar-with-SwiftUI)

Provide a seamless, cross-platform user experience by building a native menu bar for iPadOS and macOS.

### Creating a menu

[Populating SwiftUI menus with adaptive controls](/documentation/SwiftUI/Populating-SwiftUI-menus-with-adaptive-controls)

Improve your app by populating menus with controls and organizing your content intuitively.

[`struct Menu`](/documentation/SwiftUI/Menu)

A control for presenting a menu of actions.

[`func menuStyle<S>(S) -> some View`](/documentation/SwiftUI/View/menuStyle(_:))

Sets the style for menus within this view.

### Creating context menus

[`func contextMenu<MenuItems>(menuItems: () -> MenuItems) -> some View`](/documentation/SwiftUI/View/contextMenu(menuItems:))

Adds a context menu to a view.

[`func contextMenu<M, P>(menuItems: () -> M, preview: () -> P) -> some View`](/documentation/SwiftUI/View/contextMenu(menuItems:preview:))

Adds a context menu with a custom preview to a view.

[`func contextMenu<I, M>(forSelectionType: I.Type, menu: (Set<I>) -> M, primaryAction: ((Set<I>) -> Void)?) -> some View`](/documentation/SwiftUI/View/contextMenu(forSelectionType:menu:primaryAction:))

Adds an item-based context menu to a view.

### Defining commands

[`func commands<Content>(content: () -> Content) -> some Scene`](/documentation/SwiftUI/Scene/commands(content:))

Adds commands to the scene.

[`func commandsRemoved() -> some Scene`](/documentation/SwiftUI/Scene/commandsRemoved())

Removes all commands defined by the modified scene.

[`func commandsReplaced<Content>(content: () -> Content) -> some Scene`](/documentation/SwiftUI/Scene/commandsReplaced(content:))

Replaces all commands defined by the modified scene with the commands
from the builder.

[`protocol Commands`](/documentation/SwiftUI/Commands)

Conforming types represent a group of related commands that can be exposed
to the user via the main menu on macOS and key commands on iOS.

[`struct CommandMenu`](/documentation/SwiftUI/CommandMenu)

Command menus are stand-alone, top-level containers for controls that
perform related, app-specific commands.

[`struct CommandGroup`](/documentation/SwiftUI/CommandGroup)

Groups of controls that you can add to existing command menus.

[`struct CommandsBuilder`](/documentation/SwiftUI/CommandsBuilder)

Constructs command sets from multi-expression closures. Like `ContentBuilder`,
it supports up to ten expressions in the closure body.

[`struct CommandGroupPlacement`](/documentation/SwiftUI/CommandGroupPlacement)

The standard locations that you can place new command groups relative to.

### Getting built-in command groups

[`struct SidebarCommands`](/documentation/SwiftUI/SidebarCommands)

A built-in set of commands for manipulating window sidebars.

[`struct TextEditingCommands`](/documentation/SwiftUI/TextEditingCommands)

A built-in group of commands for searching, editing, and transforming
selections of text.

[`struct TextFormattingCommands`](/documentation/SwiftUI/TextFormattingCommands)

A built-in set of commands for transforming the styles applied to selections
of text.

[`struct ToolbarCommands`](/documentation/SwiftUI/ToolbarCommands)

A built-in set of commands for manipulating window toolbars.

[`struct ImportFromDevicesCommands`](/documentation/SwiftUI/ImportFromDevicesCommands)

A built-in set of commands that enables importing content from nearby
devices.

[`struct InspectorCommands`](/documentation/SwiftUI/InspectorCommands)

A built-in set of commands for manipulating inspectors.

[`struct EmptyCommands`](/documentation/SwiftUI/EmptyCommands)

An empty group of commands.

### Showing a menu indicator

[`func menuIndicator(Visibility) -> some View`](/documentation/SwiftUI/View/menuIndicator(_:))

Sets the menu indicator visibility for controls within this view.

[`var menuIndicatorVisibility: Visibility`](/documentation/SwiftUI/EnvironmentValues/menuIndicatorVisibility)

The menu indicator visibility to apply to controls within a view.

### Responding to menu item interaction

### Configuring menu dismissal

[`func menuActionDismissBehavior(MenuActionDismissBehavior) -> some View`](/documentation/SwiftUI/View/menuActionDismissBehavior(_:))

Tells a menu whether to dismiss after performing an action.

[`struct MenuActionDismissBehavior`](/documentation/SwiftUI/MenuActionDismissBehavior)

The set of menu dismissal behavior options.

### Setting a preferred order

[`func menuOrder(MenuOrder) -> some View`](/documentation/SwiftUI/View/menuOrder(_:))

Sets the preferred order of items for menus presented from this view.

[`var menuOrder: MenuOrder`](/documentation/SwiftUI/EnvironmentValues/menuOrder)

The preferred order of items for menus presented from this view.

[`struct MenuOrder`](/documentation/SwiftUI/MenuOrder)

The order in which a menu presents its content.

### Deprecated types

[`struct MenuButton`](/documentation/SwiftUI/MenuButton)

A button that displays a menu containing a list of choices when pressed.

[`typealias PullDownButton`](/documentation/SwiftUI/PullDownButton)

[`struct ContextMenu`](/documentation/SwiftUI/ContextMenu)

A container for views that you present as menu items in a context menu.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)