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>SVG Accessibility Patterns</h1>
    
    <div class="grid">
        <!-- Pattern 1: Basic title pattern -->
        <div class="card">
            <svg role="img" viewBox="0 0 200 200" class="svg-demo">
                <title>Simple Fox Face</title>
                <circle cx="100" cy="100" r="90" fill="#FF9B50"/>
                <path d="M 40,80 L 100,130 L 160,80" fill="none" stroke="#7E4B1C" stroke-width="6"/>
                <circle cx="70" cy="70" r="10" fill="#7E4B1C"/>
                <circle cx="130" cy="70" r="10" fill="#7E4B1C"/>
            </svg>
            <h3>Pattern 1: Basic Title</h3>
            <p class="support excellent">★★★ Excellent Support</p>
            <pre><code>&lt;svg role="img"&gt;
  &lt;title&gt;Simple Fox Face&lt;/title&gt;
  &lt;!-- paths --&gt;
&lt;/svg&gt;</code></pre>
            <p class="note">Basic pattern with excellent screen reader support across all tested browsers.</p>
        </div>

        <!-- Pattern 2: ARIA label pattern -->
        <div class="card">
            <svg role="img" aria-label="Geometric fox face" viewBox="0 0 200 200" class="svg-demo">
                <polygon points="100,20 170,100 100,160 30,100" fill="#FF7B54"/>
                <path d="M 70,80 L 100,100 L 130,80" fill="none" stroke="#5C3D2E" stroke-width="4"/>
                <circle cx="80" cy="70" r="8" fill="#5C3D2E"/>
                <circle cx="120" cy="70" r="8" fill="#5C3D2E"/>
            </svg>
            <h3>Pattern 2: ARIA Label</h3>
            <p class="support excellent">★★★ Excellent Support</p>
            <pre><code>&lt;svg role="img" 
  aria-label="Geometric fox face"&gt;
  &lt;!-- paths --&gt;
&lt;/svg&gt;</code></pre>
            <p class="note">Direct labeling with excellent support. Good for simple descriptions.</p>
        </div>

        <!-- Pattern 3: Title + Description -->
        <div class="card">
            <svg role="img" viewBox="0 0 200 200" class="svg-demo">
                <title>Minimalist Fox</title>
                <desc>A simplified fox face using basic shapes</desc>
                <rect x="30" y="30" width="140" height="140" rx="70" fill="#FFB26B"/>
                <path d="M 60,90 L 100,120 L 140,90" fill="none" stroke="#654321" stroke-width="5"/>
                <circle cx="80" cy="80" r="12" fill="#654321"/>
                <circle cx="120" cy="80" r="12" fill="#654321"/>
            </svg>
            <h3>Pattern 3: Title + Description</h3>
            <p class="support good">★★☆ Good Support</p>
            <pre><code>&lt;svg role="img"&gt;
  &lt;title&gt;Minimalist Fox&lt;/title&gt;
  &lt;desc&gt;A simplified fox face&lt;/desc&gt;
  &lt;!-- paths --&gt;
&lt;/svg&gt;</code></pre>
            <p class="note">Good for providing additional context, but desc support varies across screen readers.</p>
        </div>

        <!-- Pattern 4: ARIA Labelledby -->
        <div class="card">
            <svg role="img" aria-labelledby="fox-title fox-desc" viewBox="0 0 200 200" class="svg-demo">
                <title id="fox-title">Detailed Fox Portrait</title>
                <desc id="fox-desc">A detailed fox face with patterns</desc>
                <circle cx="100" cy="100" r="85" fill="#FFA07A"/>
                <path d="M 50,85 L 100,125 L 150,85" fill="none" stroke="#8B4513" stroke-width="6"/>
                <circle cx="75" cy="75" r="12" fill="#8B4513"/>
                <circle cx="125" cy="75" r="12" fill="#8B4513"/>
            </svg>
            <h3>Pattern 4: ARIA Labelledby</h3>
            <p class="support excellent">★★★ Excellent Support</p>
            <pre><code>&lt;svg role="img" 
  aria-labelledby="fox-title fox-desc"&gt;
  &lt;title id="fox-title"&gt;Fox Portrait&lt;/title&gt;
  &lt;desc id="fox-desc"&gt;Detailed face&lt;/desc&gt;
  &lt;!-- paths --&gt;
&lt;/svg&gt;</code></pre>
            <p class="note">Most robust pattern for complex descriptions. Excellent support across modern browsers.</p>
        </div>
    </div>

    <div class="card">
        <h2>Key Findings from Testing</h2>
        <ul>
            <li>All patterns require role="img" for consistent treatment</li>
            <li>Simple title and aria-label patterns have the most consistent support</li>
            <li>The desc element may be ignored by some screen readers</li>
            <li>aria-labelledby is the most robust way to combine title and description</li>
            <li>Support for these patterns is generally excellent in modern browsers</li>
        </ul>
        
        <h2>Best Practices</h2>
        <ul>
            <li>Always include role="img" on SVGs that function as images</li>
            <li>Use aria-label for simple, single-line descriptions</li>
            <li>Use aria-labelledby when combining title and description</li>
            <li>Ensure proper color contrast for all visual elements</li>
            <li>Test with multiple screen readers and browser combinations</li>
        </ul>
    </div>
              
            
!

CSS

              
                        body {
            font-family: system-ui, sans-serif;
            line-height: 1.5;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background: #f5f5f5;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }

        .card {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .svg-demo {
            width: 150px;
            height: 150px;
            margin: 0 auto 20px;
            display: block;
        }

        pre {
            background: #f6f8fa;
            padding: 15px;
            border-radius: 6px;
            overflow-x: auto;
            font-size: 14px;
        }

        code {
            font-family: monospace;
        }

        .support {
            display: flex;
            align-items: center;
            gap: 8px;
            margin: 10px 0;
        }

        .excellent { color: #00a854; }
        .good { color: #faad14; }

        .note {
            font-size: 0.9em;
            color: #666;
            margin-top: 10px;
        }
              
            
!

JS

              
                
              
            
!
999px

Console