How it works
DefaultButtonStyle is the button style SwiftUI applies when you haven't specified one of your own — it produces the standard appearance and interaction behavior appropriate to the current context, platform, and enclosing container. Because it adapts to its surroundings, a button styled this way looks like a plain control inline but takes on the prominent, bordered treatment expected inside something like an alert or a form. Reach for DefaultButtonStyle when you want to opt back in to system-provided styling explicitly, or to reset a button to the default after an ancestor view has imposed a different style.
Conform through ButtonStyle and PrimitiveButtonStyle
DefaultButtonStyle is a concrete type that conforms to the button-style protocols, so it slots into the same styling machinery as every other built-in style. You never implement its body yourself; SwiftUI supplies the context-appropriate rendering, which is why a Button labeled "Save Changes" picks up standard system styling without any further description.
Construct it with DefaultButtonStyle()
The type has a simple no-argument initializer because it carries no configuration of its own — all of its behavior comes from the environment it resolves against. Writing
DefaultButtonStyle()gives you an instance whose appearance is determined at render time by the platform and the surrounding container.Apply it with the buttonStyle(_:) modifier
You attach the style by passing the instance to
.buttonStyle(DefaultButtonStyle())on aButton. The modifier sets the style for that button and any descendant buttons that don't override it, so it's also the tool you use to restore default styling beneath an ancestor that set a different one.Prefer the .automatic shorthand
SwiftUI exposes the same default behavior through the
.automaticstatic member, letting you write.buttonStyle(.automatic)instead of naming the type. TheCancelbutton uses this form; it resolves to the context-driven default styling exactly likeDefaultButtonStyle()does, and reads more naturally in a modifier chain.Let context and role shape the result
Because the default style defers to its environment, the same style declaration renders differently depending on where the button lives and what role it carries. The
Cancelbutton'srole: .cancelinforms that contextual treatment, demonstrating that DefaultButtonStyle adapts rather than imposing a fixed look.
.alert(...) presentation and observe how the same DefaultButtonStyle() and .automatic declarations switch to the bordered, prominent appearance the system uses for buttons in that context.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct DefaultButtonStyleDemo: View {
var body: some View {
VStack(spacing: 16) {
Button("Save Changes") {}
.buttonStyle(DefaultButtonStyle())
Button("Cancel", role: .cancel) {}
.buttonStyle(.automatic)
}
.padding()
}
}