Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Using SVG Accessibly for Buttons and Links</h1>
<p style="font-size: 1.3em;"><strong>NOTE: this is from 2016.  <a href="https://codepen.io/haltersweb/pen/VBEwyz">See the new 2018 findings</a>.</strong></p>
<p>See <a href="#findings">table of screen-reader outputs</a> at the bottom of this page</p>
<h2>Test Cases</h2>
<p>The button is called "reveal navigation" and the link is called "change password"</p>
<h3>Using an Image</h3>
<p>
  A button element: <button type="button" style="overflow: hidden; padding: 5px; border: 0; background-color: red;" aria-label="Reveal navigation">
    <img src="https://placeimg.com/96/139/animals" alt="" style="width: 40px" />
  </button>
</p>
<p>
  A link element: <a href="https://sp.wikipedia.org/" style="display: inline-block; overflow: hidden; padding: 5px; border: 0; background-color: blue;">
    <span class="screen-reader-text">change password</span>
    <img src="https://placeimg.com/96/139/animals" alt="" style="width: 40px" />
  </a>
</p>
<h3>SVGs using desc (and no role)</h3>
<p>
  A button element: <button type="button" style="width: 50px; height: 50px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" focusable="false">
      <desc>Reveal navigation</desc>
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="red" />
    </svg>
  </button>
</p>
<p>
  A link element: <a href="https://sp.wikipedia.org/" style="display: inline-block; width: 50px; height: 50px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" focusable="false">
      <desc>change password</desc>
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="blue" />
    </svg>
  </a>
</p>
<h3>SVGs using title and role="img"</h3>
<p>
  A button element: <button type="button" style="width: 50px; height: 50px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" role="img" focusable="false">
      <title>Reveal navigation</title>
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="red" />
    </svg>
  </button>
</p>
<p>
  A link element: <a href="https://sp.wikipedia.org/" style="display: inline-block; width: 50px; height: 50px;">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" role="img" focusable="false">
      <title>change password</title>
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="blue" />
    </svg>
  </a>
</p>
<h3>SVGs using  and role="presentation" on the svg and aria-label (button) or span.screen-reader-text</h3>
<p>
  A button element: <button type="button" style="width: 50px; height: 50px;" aria-label="Reveal navigation">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" role="presentation" focusable="false">
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="red" />
    </svg>
  </button>
</p>
<p>
  A link element: <a href="https://sp.wikipedia.org/" style="display: inline-block; width: 50px; height: 50px;">
    <span class="screen-reader-text">change password</span>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="00 0 90 90" role="presentation" focusable="false">
      <circle cx="45" cy="45" r="40" stroke="black" stroke-width="3" fill="blue" />
    </svg>
  </a>
</p>
<table id="findings">
	<caption>
		<h2>Screen-reader Findings</h2>
	</caption>
  <colgroup>
    <col/>
    <col/>
    <col/>
    <col/>
    <col/>
  </colgroup>
	<thead>
		<tr>
			<th scope="col">Screen Reader</th>
			<th scope="col">Control: Using an Image</th>
			<th scope="col">SVG using desc (no role)</th>
			<th scope="col">SVG using title and role="img"</th>
			<th scope="col">SVG using hidden text and role="presentation"</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th scope="row">NVDA 2016.3 w FF 50.0</th>
			<td>
        "Reveal navigation, button"<br/>
        "Change password, link"
      </td>
			<td>
        "Button"<br/>
        "sp.wikipedia.org, link"
      </td>
			<td>
        "Reveal navigation, reveal navigation, graphic, button"<br/>
        "Change password, change password, graphic, link"
      </td>
			<td>
        "Reveal navigation, button"<br/>
        "Change password, link"
      </td>
		</tr>
		<tr>
			<th scope="row">JAWS 18.0 w IE 11.0</th>
			<td>
        Reveal navigation, button<br/>
        Link, change password
      </td>
			<td>
        Button, reveal navigation, button, graphic<br/>
        Link, graphic, change password.
      </td>
			<td>
        Button, Reveal navigation, button, graphic<br/>
        Link, graphic, change password
      </td>
			<td>
        Reveal navigation, button<br/>
        Link, change password
      </td>
		</tr>
		<tr>
			<th scope="row">Mac Safari w VO</th>
			<td>
        "Reveal navigation, button"<br/>
        "Link, change password"
      </td>
			<td>
        "Button"<br/>
        "Link /"
      </td>
			<td>
        "Reveal navigation, button"<br/>
        "Link, image, change password"
      </td>
			<td>
        "Reveal navigation, button"<br/>
        "Link, change password"
      </td>
		</tr>
		<tr>
			<th scope="row">iOS Safari w VO</th>
			<td>
        "Reveal navigation, button"<br/>
        "Change password, link"
      </td>
			<td>
        "Button"<br/>
        [element is skipped completely]
      </td>
			<td>
        "Button"<br/>
        "Change password, link"
      </td>
			<td>
        "Reveal navigation, button"<br/>
        "Change password, link"
      </td>
		</tr>
	</tbody>
</table>
              
            
!

CSS

              
                .screen-reader-text { /* Hide only visually, but have it available for screenreaders */
	position: absolute !important;
	display: block;
	visibility: visible;
	overflow: hidden;
	width: 1px;
	height: 1px;
	margin: -1px;
	border: 0;
	padding: 0;
	clip: rect(0px, 0px, 0px, 0px); /* deprecated */
	clip-path: polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px);
    }
table {
  border-collapse: collapse;
  margin: 1em;
  font-family: arial, helvetica, sans-serif;
}
col {
  width: 20%;
  border: 1px solid black;
}
tr {
    border-bottom: 1px solid black;
}
thead th {
  padding: 1em;
  background-color: black;
  border-right: 1px solid white;
  color: white;
}
thead th:last-child {
  border-right: none;
}
td, tbody th {
  padding: 1em;
  text-align: left;
  vertical-align: top;
}
              
            
!

JS

              
                
              
            
!
999px

Console