files/en-us/web/api/xrhittestresult/createanchor/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}{{SecureContext_Header}}
The createAnchor() method of the {{domxref("XRHitTestResult")}} interface creates an {{domxref("XRAnchor")}} from a hit test result that is attached to a real-world object.
createAnchor()
None.
A {{jsxref("Promise")}} resolving with an {{domxref("XRAnchor")}} object.
The following example starts with an {{domxref("XRHitTestResult")}} retrieved by calling {{domxref("XRFrame.getHitTestResults()")}}. After calling createAnchor(), the Promise resolves with an {{domxref("XRAnchor")}} to attach a virtual object to that location.
hitTestResult.createAnchor().then(
(anchor) => {
// add anchored objects to the scene
},
(error) => {
console.error(`Could not create anchor: ${error}`);
},
);
{{Specifications}}
{{Compat}}