<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/hoverEffectGroup(id:in:behavior:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE16hoverEffectGroup2id2in8behaviorQrSSSg_AA9NamespaceV2IDVAA05HovereF0V8BehaviorVtF"
  },
  "title" : "hoverEffectGroup(id:in:behavior:)"
}
-->

# hoverEffectGroup(id:in:behavior:)

Adds a [`HoverEffectGroup`](/documentation/SwiftUI/HoverEffectGroup) to all effects defined on descendant views,
and activates the group whenever this view or any descendant views are
hovered.

```
nonisolated func hoverEffectGroup(id: String? = nil, in namespace: Namespace.ID, behavior: HoverEffectGroup.Behavior = .activatesGroup) -> some View
```

## Parameters

`id`

An optional id to give the group. If provided, the group will be
uniquely identified by combining the id and the namespace.

`namespace`

The namespace that identifies the group. If
`nil`, this modifier has no effect.

`behavior`

How the effect will behave relative to other
effects in the group.

## Return Value

A new effect that is matched to other effects in the same
group.

## Discussion

You use this modifier when all effects defined on a view and its
subviews should activate together. In the following example hovering
anywhere over the view will activate the `hoverEffect`s added to
the `Text` and the background view, as well as any effects added to the
group by other views:

```
struct EffectView: View {
    @Namespace var namespace

    var body: some View {
        HStack {
            Image(systemName: "exclamationmark.triangle.fill")
            Text("12 Issues")
                .hoverEffect { effect, isActive, _ in
                    effect.opacity(isActive ? 1 : 0.5)
                }
        }
        .padding()
        .background {
            Capsule()
                .fill(.yellow)
                .hoverEffect { effect, isActive, _ in
                    effect.opacity(isActive ? 0.25 : 0.1)
                }
        }
        .hoverEffectGroup(in: namespace)
    }
}
```

The effect group is uniquely identified by combining the `id` and
`namespace` parameters. If an `id` is not provided, the effect will be
identified by the `namespace` alone. Providing a `name` is useful when
creating effects that use multiple, related groups.

The default behavior of a matched effect is to activate the effect group
when hovered. The `behavior` parameter can be used to choose alternative
behaviors. See [`HoverEffectGroup.Behavior`](/documentation/SwiftUI/HoverEffectGroup/Behavior) for all possible behaviors.

---

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)