<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSAccessibilityElement-swift.class/element(withRole:frame:label:parent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAccessibilityElement(cm)accessibilityElementWithRole:frame:label:parent:"
  },
  "title" : "element(withRole:frame:label:parent:)"
}
-->

# element(withRole:frame:label:parent:)

Instantiates and configures a new accessibility element.

```
class func element(withRole role: NSAccessibility.Role, frame: NSRect, label: String?, parent: Any?) -> Any
```

## Parameters

`role`

The new element’s intended role. For a complete list of roles, see Roles.
  
  > Note:
  > Your subclass also needs to adopt the role-based protocol that corresponds with this role.

`frame`

The element’s frame in screen coordinates. Additionally, you need to set the element’s [`accessibilityFrameInParentSpace`](/documentation/AppKit/NSAccessibilityElement-swift.class/accessibilityFrameInParentSpace) property.
  
  > Note:
  > The ``doc://com.apple.appkit/documentation/AppKit/NSAccessibilityElement-swift.class/accessibilityFrameInParentSpace`` property ensures that the element’s frame is updated as its parent moves.

`label`

A short description of the new element. Do not include the element’s type in the label (for example, use `Play`, not `Play button`). If possible, use a single word. To help ensure that accessibility clients such as VoiceOver read the label with the correct intonation, start the label with a capital letter. Do not put a period at the end. Always localize the label.

`parent`

The new element’s parent in the accessibility hierarchy.

## Return Value

A newly instantiated and initialized accessibility element.

## Discussion

Alternatively, instead of calling this convenience method, you can create an accessibility element and set its [`accessibilityRole`](/documentation/AppKit/NSAccessibility-c.protocol/accessibilityRole), [`accessibilityLabel`](/documentation/AppKit/NSAccessibility-c.protocol/accessibilityLabel), and [`accessibilityParent`](/documentation/AppKit/NSAccessibility-c.protocol/accessibilityParent) properties. Regardless of how you create the accessibility element, you need to set its [`accessibilityFrameInParentSpace`](/documentation/AppKit/NSAccessibilityElement-swift.class/accessibilityFrameInParentSpace) property to ensure that the element’s frame is updated as its parent moves.

---

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)