{
  "name": "utilities/visually-hidden",
  "title": "Visually Hidden",
  "description": "The visually hidden utility makes content accessible to assistive devices without displaying it on the screen.",
  "docs": "https://test-apps.eurodata.de/a/eurodata-ui/docs/utilities/visually-hidden/",
  "sections": [
    {
      "heading": "Visually Hidden",
      "markdown": "> \"There are real world situations where visually hiding content may be appropriate, while the content should remain available to assistive technologies, such as screen readers. For instance, hiding a search field's label as a common magnifying glass icon is used in its stead.\" — [The A11Y Project](https://www.a11yproject.com/posts/2013-01-11-how-to-hide-content/)\n\nSince visually hidden content can receive focus when tabbing, the element will become visible when something inside receives focus. This behavior is intentional, as otherwise sighted keyboard users wouldn't be able to determine where the focus indicator is.\n\n```html\n<div style=\"min-height: 1.875rem;\">\n  <a href=\"#\" class=\"ed-visually-hidden\">Skip to main content</a>\n</div>\n```"
    },
    {
      "heading": "Examples",
      "markdown": "### Links That Open in New Windows\n\nIn this example, the link will open a new window. Screen readers will announce \"opens in a new window\" even though the text content isn't visible to sighted users.\n\n```html\n<a href=\"https://example.com/\" target=\"_blank\">\n  Visit External Page\n  <ed-icon name=\"arrow-up-right-from-square\" variant=\"regular\"></ed-icon>\n  <span class=\"ed-visually-hidden\">opens in a new window</span>\n</a>\n```\n\n### Content Conveyed By Context\n\nAdding a label may seem redundant at times, but they're very helpful for unsighted users. Rather than omit them, you can provide context to unsighted users with visually hidden content that will be announced by assistive devices such as screen readers.\n\n```html\n<ed-card style=\"width: 100%; max-width: 360px;\">\n  <header class=\"ed-visually-hidden\">Personal Info</header>\n  <ed-input label=\"Name\" style=\"margin-bottom: .5rem;\"></ed-input>\n  <ed-input label=\"Email\" type=\"email\"></ed-input>\n</ed-card>\n```\n\n### Visually Hidden Input Parts\n\nSometimes you want a form control to have a cleaner, more minimal appearance by hiding the `label` or `hint` visually. However, removing these elements entirely would make the form inaccessible to users with assistive devices.\n\nInstead, you can hide them visually while keeping them available to screen readers by adding the `ed-visually-hidden-label` or `ed-visually-hidden-hint` class.\n\n`ed-visually-hidden-hint` reaches the hint and nothing else. A validation message renders in its own element and stays visible — an error a sighted user can see but not read fails [WCAG 3.3.1 Error Identification](https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html), which asks for the error to be \"described to the user in text\". Where a message genuinely has no room, say so deliberately: set `error` as a bare attribute for the border and icon without any text, and reveal the reason another way. See [Error styling without a message](https://test-apps.eurodata.de/a/eurodata-ui/docs/form-controls#error-styling-without-a-message).\n\n```html\n<ed-input\n  label=\"Search Articles\"\n  type=\"search\"\n  placeholder=\"Search for...\"\n  class=\"ed-visually-hidden-label\"\n  style=\"margin-block-end: 1rem;\"\n>\n  <ed-icon slot=\"start\" name=\"magnifying-glass\" variant=\"regular\"></ed-icon>\n</ed-input>\n\n<ed-input\n  label=\"Phone Number\"\n  type=\"tel\"\n  hint=\"We'll send you a verification code\"\n  placeholder=\"(555) 867-5309\"\n  class=\"ed-visually-hidden-hint\"\n  style=\"margin-block-end: 1rem;\"\n>\n  <ed-icon slot=\"start\" name=\"phone\" variant=\"regular\"></ed-icon>\n</ed-input>\n\n<ed-select\n  label=\"Country\"\n  hint=\"Select your country for shipping calculations\"\n  class=\"ed-visually-hidden-hint\"\n  style=\"margin-block-end: 1rem;\"\n>\n  <ed-option value=\"us\">United States</ed-option>\n  <ed-option value=\"ca\">Canada</ed-option>\n  <ed-option value=\"mx\">Mexico</ed-option>\n  <ed-option value=\"uk\">United Kingdom</ed-option>\n  <ed-option value=\"de\">Germany</ed-option>\n  <ed-option value=\"fr\">France</ed-option>\n  <ed-option value=\"wakanda\">Wakanda</ed-option>\n  <ed-option value=\"genovia\">Genovia</ed-option>\n  <ed-option value=\"elbonia\">Elbonia</ed-option>\n  <ed-icon slot=\"start\" name=\"globe\" variant=\"regular\"></ed-icon>\n</ed-select>\n\n<ed-input\n  label=\"Email Address\"\n  type=\"email\"\n  hint=\"We'll never share your email or secret identity\"\n  placeholder=\"e.g. miles.morales@brooklynvisions.edu\"\n  class=\"ed-visually-hidden-label ed-visually-hidden-hint\"\n>\n  <ed-icon slot=\"start\" name=\"envelope\" variant=\"regular\"></ed-icon>\n</ed-input>\n```\n\n### Force Visually Hidden\n\nThere are cases where you want to _always_ visually hide certain content, even when it's focused. For example when hiding a checkbox to render a custom one:\n\n```html\n<label>\n  <span class=\"checkbox\">\n    <input type=\"checkbox\" class=\"ed-visually-hidden-force\" />\n  </span>\n  I have read the terms and conditions\n</label>\n\n<style>\n  .checkbox {\n    display: inline-flex;\n    vertical-align: middle;\n    width: var(--ed-font-size-l);\n    height: var(--ed-font-size-l);\n    background: var(--ed-color-neutral-fill-light);\n    color: var(--ed-color-neutral-on-light);\n    border-radius: var(--ed-border-radius-1x);\n    margin-inline-end: var(--ed-space-2);\n\n    &::after {\n      content: '✓' / '';\n      margin: auto;\n      transition: opacity var(--ed-transition-slow) var(--ed-transition-easing);\n    }\n\n    &:has(:checked) {\n      background: var(--ed-color-brand-fill-normal);\n      color: var(--ed-color-brand-on-normal);\n    }\n\n    &:not(:has(:checked)) {\n      &::after {\n        opacity: 0;\n      }\n    }\n\n    &:focus-within {\n      outline: var(--ed-focus-ring);\n      outline-offset: var(--ed-focus-ring-offset);\n    }\n  }\n</style>\n```"
    }
  ]
}
