<div class="box">
  <h1>A11Y Study case: Breaking text on a specific word and Screen Readers implications</h1>
  <a href="https://dev.to/a_sandrina_p/a11y-study-case-splitting-text-into-multiple-lines-and-screen-readers-implications-g72" class="link">Read article on Dev.to</a>
</div>

<div class="card">
  <h3>Continuous text</h3>
  <p>
    Hello human being
  </p>

  <p class="sr" aria-hidden="true">Voice Over: "Hello human being"</p>
</div>

<div class="box">
  <h2>Common (poor) approaches</h2>
</div>

<ul>
  <li class="card">
    <h3>1 - Using <code>br</code></h3>
    <!-- Do not use br. They are meant to be used when
  different lines have meaning. (eg stress addresses and poems) -->
    <p>
      Hello
      <br />
      human being
    </p>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Hello" [next block] "human being"</p>
  </li>

  <li class="card">
    <!-- A util class makes the job but SR still reads it "with pauses"
-->
    <h3>2 - Using <code>span</code> with <code>display:block</code></h3>
    <p>
      Hello <span class="u-newline"></span>
      human being
    </p>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Hello" [next block] "human being"</p>
  </li>

  <li class="card">
    <h3>3 - Using inline flexbox</h3>

    <p class="textInLines">
      <span>Hello</span>
      <span>human being</span>
    </p>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Hello" [next block] "human being"</p>
  </li>
</ul>

<div class="box">
  <h2>Solution attempts</h2>
</div>

<ul>

  <li class="card">
    <h3>1.1 - Using <code>role="text"</code> (in paragraphs)</h3>
    <p role="text">
      Hello
      <span class="u-newline"></span>
      human being
    </p>
    <p class="sr" aria-hidden="true">✅ Voice Over: "Hello human being"</p>
    </div>

  <li class="card">
    <h3>1.2 - Using <code>role="heading"</code> (in headings)</h3>

    <h4 role="heading" aria-level="3">
      Hello
      <span class="u-newline"></span>
      human being
    </h4>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Heading level 4 2 items Hello [pause] human being"</p>
  </li>

  <li class="card">
    <h3>2.1- Using <code>aria-label</code> (in paragraphs)</h3>

    <p aria-label="Hello human being">
      Hello
      <span class="u-newline"></span>
      human being
    </p>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Hello human being, group"</p>
  </li>

  <li class="card">
    <h3>2.2 - Using <code>aria-label</code> (in headings)</h3>

    <h4 aria-label="Hello human being">
      Hello
      <span class="u-newline"></span>
      human being

    </h4>
    <!-- I guess it says "2 items" because u-newline is
     "display block", which forces a "block" per line. -->
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Heading level 4 2 items, Hello human being"</p>
  </li>

  <li class="card">
    <!-- Solution from https://twitter.com/hzr/status/1317569835568693250 -->
    <h3>3.1 - Using <code>white-space: pre-line</code> v1</h3>
    <p class="u-preline">Hello
      human being</p>
    <p class="sr" aria-hidden="true">✅ Voice Over: "Hello human being"</p>
  </li>

  <li class="card">
    <!-- Solution from https://twitter.com/simevidas/status/1317586897548476418 -->
    <h3>3.2 - Using <code>white-space: pre-line</code> v2 (<code>&NewLine</code>)</h3>
    <p class="u-preline">Hello &NewLine; human being</p>
    <p class="sr" aria-hidden="true">✅ Voice Over: "Hello human being"</p>
  </li>

  <li class="card">
    <!-- Solution from https://twitter.com/ecbos_/status/1317740758431129600 -->
    <h3>4.1 - Using <code>br role="presentation"</code>(in paragraphs)</h3>
    <p>Hello
      <br role="presentation" />
      human being
    </p>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "Hello" [next block] "human being"</p>
  </li>

  <li class="card">
    <!-- Solution from https://twitter.com/ecbos_/status/1317740758431129600 -->
    <h3>4.2 - Using <code>br role="presentation"</code> (in headings)</h3>
    <h4>Hello
      <br role="presentation" />
      human being
    </h4>
    <p class="sr" aria-hidden="true">⚠️ Voice Over: "heading level 4 2 items Hello [pause] human being"</p>
  </li>
</ul>

<footer class="footer">
  <p>Made without coffee by <a href="https://twitter.com/a_sandrina_p" class="link">Sandrina Pereira</a>. Would you <a href="https://www.buymeacoffee.com/sandrinap" target="_blank" class="link">buy me one</a>?</p>
</footer>
.u-newline {
  display: block;
}

.u-preline {
  white-space: pre-line;
}

// ----- Theme styles -----

body {
  background: #f8f3ef;
  font-family: Arial, Helvetica, sans-serif;
  box-sizing: border-box;
  color: #343434;
  line-height: 1.5;
  padding: 1rem;
}

body * {
  box-sizing: inherit;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.box {
  position: relative;
  margin: 2rem auto;
  max-width: 30rem;
}

.card {
  position: relative;
  margin: 2rem auto;
  max-width: 30rem;
  background: white;
  padding: 0.5rem 1rem;
  box-shadow: 0.2rem 0.2rem #e9e1f8;

  &:last-of-type {
    margin-bottom: 6rem;
  }
}

h1 {
  font-size: 1.5rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.3rem;
  line-height: 1.2;
}

h3 {
  font-size: 0.9rem;
  color: #8c00ff;
}

h4 {
  font-weight: inherit;
}

.sr {
  font-style: italic;
  font-size: 0.9rem;
  opacity: 0.8;
  margin-top: -0.5rem;

  &:first-letter {
    font-style: normal;
  }
}

.textInLines {
  display: inline-flex;
  flex-direction: column;
}

code {
  background: #eee;
  padding: 0 2px;
}

.winner {
  margin-top: -0.5rem;
}

.footer {
  position: relative;
  width: 100%;
  margin-top: 60px;
  padding: 24px 16px;
  text-align: center;
  font-size: 0.9rem;
  background: white;

  p {
    margin: 0;
  }

  @media screen and (min-height: 26em) {
    position: fixed;
    left: 0;
    bottom: 0;
  }
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.