Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG text accessibility

I have the following structure

<h2>
  <svg viewBox='-5 -40 100 50'>
    <!-- some filters that get applied on the elements below -->
    
    <clipPath id='c'>
      <text id='t'>Scooby</text>
    </clipPath>
    
    <g clip-path='url(#c)'>
      <rect x='-5' y='-40' width='100%' height='100%'/>
      <path/>
    </g>
    
    <use xlink:href='#t'/>
    <use xlink:href='#t'/>
  </svg>
</h2>

How can I ensure the text inside the clipPath ("Scooby") gets seen by screen readers and only once?

I know SVG text should be read by screen readers, but is that the still the case when it's inside a clipPath element? And what about use copies of it?

I'm using this structure in order to get some fancy effects (think stuff like this) on the heading text (and ditch the .jpg image that's currently used).

like image 397
Ana Avatar asked Oct 26 '18 06:10

Ana


People also ask

Are SVGs with text accessible?

Accessibility – Markup can be added to the SVGs directly so more information can be added within the image itself – which is helpful for people using assistive technology devices such as screen readers.

How do I make my SVG image accessible?

Add aria-describedby for a better accessibility First, you'll have to add a <title> to your code. The <title> should always come right after the opening <svg> and before the <path> . Now you'll have to add aria-describedby to the <svg> . You can read about this aria-attribute on the page about aria-describedby.

Can an SVG have alt text?

An <svg> element with an image or graphics role must have alternative text.

Can SVG have aria label?

SVG online (inline) # The best support for SVGs is to display them inline. You must use aria-labelledby as the first choice by referencing the "title" and the "desc" (avoid aria-describedby for the "desc", still bad support) to ensure maximum support.


1 Answers

Remove the SVG from your screenreader using aria-hidden and define the label for your h2 using aria-labelledby.

<h2 aria-labelledby="t">
  <svg viewBox='-5 -40 100 50' aria-hidden="true">
    <!-- some filters that get applied on the elements below -->

    <clipPath id='c'>
      <text id='t'>Scooby</text>
    </clipPath>

    <g clip-path='url(#c)'>
      <rect x='-5' y='-40' width='100%' height='100%'/>
      <path/>
    </g>

    <use xlink:href='#t'/>
    <use xlink:href='#t'/>
  </svg>
</h2>
like image 189
Adam Avatar answered Oct 01 '22 00:10

Adam