---
title: "element(withRole:frame:label:parent:)"
framework: appkit
role: symbol
role_heading: Type Method
path: "appkit/nsaccessibilityelement-swift.class/element(withrole:frame:label:parent:)"
---

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

Instantiates and configures a new accessibility element.

## Declaration

```swift
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 doc://com.apple.appkit/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

Return Value A newly instantiated and initialized accessibility element.

## Discussion

Discussion Alternatively, instead of calling this convenience method, you can create an accessibility element and set its accessibilityRole, accessibilityLabel, and accessibilityParent properties. Regardless of how you create the accessibility element, you need to set its accessibilityFrameInParentSpace property to ensure that the element’s frame is updated as its parent moves.

## See Also

### Supporting the Accessibility Hierarchy

- [accessibilityAddChildElement(_:)](appkit/nsaccessibilityelement-swift.class/accessibilityaddchildelement(_:).md)
- [accessibilityFrameInParentSpace()](appkit/nsaccessibilityelement-swift.class/accessibilityframeinparentspace().md)
- [setAccessibilityFrameInParentSpace(_:)](appkit/nsaccessibilityelement-swift.class/setaccessibilityframeinparentspace(_:).md)
