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>Simulating screen reader text experiences</h1>
<h2>Examples</h2>
<ul>
  <li>
    <a href="#">Link with hidden text<span class="sr-only">for screen readers</span></a>
  </li>
  <li>
    <a href="#">Link with no hidden text</a>
  </li>
  <li>
    <a href="#">Another link with hidden text<span class="sr-only">for screen readers only</span></a>
  </li>
  <li>
    <a href="/">Learn more<span class="sr-only">about product one</span></a>
  </li>
  <li>
    <a href="#">Learn more<span class="sr-only">about product two</span></a>
  </li>
</ul>

<p>
This is some marketing text that explains how a product works. Sometimes <a href="#">links<span class="sr-only">with no context for screen readers</span></a> are included. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.
</p>

<h2>Add Bookmarklet</h2>
<ol>
  <li>
    <button class="js-copy-button">Copy code</button>
  </li>
  <li>
    Add bookmarklet code in the URL field for a bookmarket
  </li>
  <li>
    Navigate to a page and click the bookmarklet to add the "listen" buttons
  </li>
  <li>
    Or just try running the code on any page by running it in your console!
  </li>
</ol>
<pre>
  <code class="language-javascript">javascript:(function(){const addSrOnlyButtons=()=>{const createListenButton=button=>{const buttonItem=document.createElement("button"),buttonText=button.innerText.replace(/\n/g," ");buttonItem.setAttribute("onclick",`readSrOnlyText('${buttonText}')`),buttonItem.innerText="Listen",buttonItem.style.backgroundColor="yellow",buttonItem.style.color="black",buttonItem.style.border="1px gray solid",buttonItem.style.borderRadius="5px",buttonItem.style.padding="5px",buttonItem.style.fontSize="14px",buttonItem.style.marginLeft="5px",button.after(buttonItem)},buttons=document.querySelectorAll("a");buttons.forEach(button=>createListenButton(button))},readSrTextFunction=document.createElement("script");readSrTextFunction.innerHTML="const readSrOnlyText = (buttonText) => {const speech = new SpeechSynthesisUtterance(); speech.text = buttonText; speech.volume = 1; speech.rate = 1; speech.pitch = 1; window.speechSynthesis.speak(speech);};",document.querySelector("body").appendChild(readSrTextFunction),addSrOnlyButtons();})();</code>
</pre>
              
            
!

CSS

              
                body{
  font-family: sans-serif;
  max-width: 800px;
  margin: auto;
  padding-left: 1em;
  padding-right: 1em;
}

/* From Bootstrap */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    border: 0;
}

/* Prism */
code[class*="language-"],
pre[class*="language-"] {
	color: #c5c8c6;
	text-shadow: 0 1px rgba(0, 0, 0, 0.3);
    font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace;
	direction: ltr;
	text-align: left;
	white-space: pre;
	word-spacing: normal;
	word-break: normal;
	line-height: 1.5;
	-moz-tab-size: 4;
	-o-tab-size: 4;
	tab-size: 4;
	-webkit-hyphens: none;
	-moz-hyphens: none;
	-ms-hyphens: none;
	hyphens: none;
}

/* Code blocks */
pre[class*="language-"] {
	padding: 1em;
	margin: .5em 0;
	overflow: auto;
	border-radius: 0.3em;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
	background: #1d1f21;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
	padding: .1em;
	border-radius: .3em;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
	color: #7C7C7C;
}

.token.punctuation {
	color: #c5c8c6;
}

.namespace {
	opacity: .7;
}

.token.property,
.token.keyword,
.token.tag {
    color: #96CBFE;
}

.token.class-name {
	color: #FFFFB6;
	text-decoration: underline;
}

.token.boolean,
.token.constant {
    color: #99CC99;
}

.token.symbol,
.token.deleted {
	color: #f92672;
}

.token.number {
	color: #FF73FD;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
	color: #A8FF60;
}

.token.variable {
	color: #C6C5FE;
}

.token.operator {
    color: #EDEDED;
}

.token.entity {
    color: #FFFFB6;
    /* text-decoration: underline; */
}

.token.url {
    color: #96CBFE;
}

.language-css .token.string,
.style .token.string {
	color: #87C38A;
}

.token.atrule,
.token.attr-value {
    color: #F9EE98;
}

.token.function {
	color: #DAD085;
}

.token.regex {
    color: #E9C062;
}

.token.important {
	color: #fd971f;
}

.token.important,
.token.bold {
	font-weight: bold;
}
.token.italic {
	font-style: italic;
}

.token.entity {
	cursor: help;
}

              
            
!

JS

              
                const addSrOnlyButtons = () => {
  const createListenButton = (button) => {
    const buttonItem = document.createElement("button");

    // trim buttons text to a single line
    const buttonText = button.innerText.replace(/\n/g, " ");
    buttonItem.setAttribute("onclick", `readSrOnlyText('${buttonText}')`);
    
    //adding some inline styles to make it easier to see the button
    buttonItem.innerText = "Listen";
    buttonItem.style.backgroundColor = "yellow";
    buttonItem.style.color = "black";
    buttonItem.style.border = "1px gray solid";
    buttonItem.style.borderRadius = "5px";
    buttonItem.style.padding = "5px";
    buttonItem.style.fontSize = "14px";
    buttonItem.style.marginLeft = "5px";
    
    //appending the button
    button.after(buttonItem);
  };

  const buttons = document.querySelectorAll("a");
  buttons.forEach((button) => createListenButton(button));
};

const readSrOnlyText = (buttonText) => {
  const speech = new SpeechSynthesisUtterance();
  speech.text = buttonText;
  speech.volume = 1;
  speech.rate = 1;
  speech.pitch = 1;
  window.speechSynthesis.speak(speech);
};

addSrOnlyButtons();


const copyButton = document.querySelector(".js-copy-button")

copyButton.onclick = function() {
  const code = document.querySelector(".language-javascript").innerText;
  navigator.clipboard.writeText(code);
  copyButton.innerText = "Copied code!"
  
  setTimeout(function(){ 
    copyButton.innerText = "Copy code" 
  }, 3000);
}
              
            
!
999px

Console