HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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><svg role="img">
<title>Simple Fox Face</title>
<!-- paths -->
</svg></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><svg role="img"
aria-label="Geometric fox face">
<!-- paths -->
</svg></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><svg role="img">
<title>Minimalist Fox</title>
<desc>A simplified fox face</desc>
<!-- paths -->
</svg></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><svg role="img"
aria-labelledby="fox-title fox-desc">
<title id="fox-title">Fox Portrait</title>
<desc id="fox-desc">Detailed face</desc>
<!-- paths -->
</svg></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>
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;
}
Also see: Tab Triggers