{"id":15691253,"url":"https://github.com/anandchowdhary/get-computed-label","last_synced_at":"2026-01-24T07:03:59.295Z","repository":{"id":35111091,"uuid":"207995011","full_name":"AnandChowdhary/get-computed-label","owner":"AnandChowdhary","description":"🏷️ Get an element's computed label from the Accessibility Tree","archived":false,"fork":false,"pushed_at":"2024-06-17T22:07:06.000Z","size":196,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T02:45:14.834Z","etag":null,"topics":["a11y","accessibility","aria","dom","javascript","library","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/get-computed-label","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnandChowdhary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-12T07:52:13.000Z","updated_at":"2021-03-26T08:50:13.000Z","dependencies_parsed_at":"2024-10-23T23:07:17.685Z","dependency_job_id":"b08e2970-63ef-4af4-90a0-e20e75200102","html_url":"https://github.com/AnandChowdhary/get-computed-label","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.10526315789473684","last_synced_commit":"1113a3183383fe119e0208747b0572a3b5b6fdd2"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fget-computed-label","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fget-computed-label/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fget-computed-label/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Fget-computed-label/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnandChowdhary","download_url":"https://codeload.github.com/AnandChowdhary/get-computed-label/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239441677,"owners_count":19639122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a11y","accessibility","aria","dom","javascript","library","typescript"],"created_at":"2024-10-03T18:20:49.549Z","updated_at":"2025-11-04T21:30:23.636Z","avatar_url":"https://github.com/AnandChowdhary.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏷️ Get computed label\n\nGet an element's computed label (\"Accessible Name\") from the Accessibility Tree\n\n## 💡 Why?\n\nSay you have a button which looks like this (this is invalid markup):\n\n```html\n\u003cbutton\n  alt=\"Alternate text\"\n  title=\"Title text\"\n  aria-label=\"ARIA label\"\n  aria-labelledby=\"ref1\"\n\u003e\n  \u003cspan id=\"ref\"\u003eA span with an ID\u003c/span\u003e\n  \u003cspan\u003eInner text\u003c/span\u003e\n\u003c/button\u003e\n```\n\n![Screenshot of the HTML button markup](https://user-images.githubusercontent.com/2841780/64767150-d47e3e80-d564-11e9-8563-c692779a4dcd.png)\n\nWhat would a screen reader read?\n\nUsing the Accessibility Tree, screen readers and other assistive technologies figure out what they should read. In this case, even though the `\u003cbutton\u003e` has inner text, the [ARIA](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) attributes take precedence. Even in that, the `aria-labelledby` is higher in the accessibility order than `aria-label`, but in this case, the element with the ID `#ref1` doesn't exist, so we fall back to `aria-label`.\n\nFinally, the label is computed to be `Aria label`.\n\n## 💻 Usage\n\nInstall the package from NPM:\n\n```bash\nnpm install get-computed-label\n```\n\n```js\nimport getComputedLabel from \"get-computed-label\";\n\nconst label = getComputedLabel(document.getElementById(\"example\"));\nconsole.log(label);\n```\n\nYou can also add this to the prototype, if you're into that:\n\n```js\nHTMLElement.prototype.getComputedLabel = function() {\n  return getComputedLabel(this);\n};\n\nconst image = document.querySelector(\"img\");\nconsole.log(image.getComputedLabel());\n```\n\n## ℹ️ Further reading\n\n- [Accessible Name and Description Computation 1.1](https://www.w3.org/TR/accname-1.1/)\n- **TODO** Use computation method described above\n\n## 📝 License\n\n[MIT](https://github.com/AnandChowdhary/get-computed-label/blob/master/LICENSE) © [Anand Chowdhary](https://anandchowdhary.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Fget-computed-label","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanandchowdhary%2Fget-computed-label","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Fget-computed-label/lists"}