A place to cache linked articles (think custom and personal wayback machine)
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.md 15KB

před 5 roky
12345678910111213
  1. title: You're using <em> wrong
  2. url: https://logrocket.com/blog/youre-using-em-wrong/
  3. hash_url: 755a9a5006ccdc5a0595ee76eb09e880
  4. <p>It’s been a bumpy road that somehow got us misusing one of the most important text-level semantic tags.</p><p>In the dark ages of HTML, &lt;em&gt; was barely used at all, despite being part of the specs since really early on (<a href="http://www.ietf.org/rfc/rfc1866.txt" rel="noreferrer nofollow noopener noopener">HTML 2.0</a> standard, 1995). But at that point in time and for some years to come, (almost) no one was thinking of semantics or even separation of concerns. Italics were simply marked up with &lt;i&gt; tags, and we wouldn’t give it a second thought.</p><p>Then somewhere along the way, someone shouted <em>“Semantics!”</em> and everybody started to hate the poor little &lt;i&gt; tag like a bad neighbor. A really, <em>really</em> bad neighbor.</p><p>&lt;em&gt; was all the rage, with supposed benefits for accessibility and SEO, which got us all using it everywhere. By <a href="https://www.w3.org/TR/html401/struct/text.html#edef-EM">HTML 4</a>, everybody knew &lt;em&gt; was for emphasis and styled as italics, &lt;strong&gt; was for stronger emphasis and styled as bold text. If you ever dared to use &lt;i&gt;, you would be instantly tagged as a bad developer.</p><p>There were even rumours that the <em>totally un-semantic</em> &lt;i&gt; and &lt;b&gt; would be deprecated any minute like &lt;u&gt; was, and our WYSIWYG editors didn’t even have a button for &lt;i&gt; or &lt;b&gt;, they would simply put an &lt;em&gt; whenever we clicked the italics icon and &lt;strong&gt; when clicking the bold.</p><p>But….</p><h2 id="the-em-tag-is-not-for-emphasis">The &lt;em&gt; tag is not for emphasis</h2><p>Let me repeat that: <strong>&lt;em&gt; is <em>not</em> for emphasis</strong>. In <a href="https://www.w3.org/TR/html50/text-level-semantics.html#the-em-element">HTML5</a>, <strong>&lt;em&gt; is for <em>stress </em>emphasis</strong>.</p><p>This might look like a subtle distinction, but that’s where all of this confusion comes from. The HTML 2, 3 and 4 specs were pretty vague on their definition of “emphasis”, making it look like a lesser version of &lt;strong&gt;. Something to mark text of higher importance, but not <em>so</em> important.</p><p>But when HTML5 rolled out, they made sure to draw a clearer line on what they intended &lt;em&gt; to be, while redefining the &lt;i&gt; from a text-italicising tag into a semantic tag that pretty much wraps most other use cases for italics.</p><p>But <strong>what is stress emphasis?</strong> Stress emphasis is the phonetic resource of changing pitch and/or dragging the word to denote a special meaning to it. It marks a word in a way that changes the meaning of the whole sentence. It’s used for a correction, clarification, sarcasm, the key part of a counter-argument, etc.</p><p>Native English speakers do this without even thinking about it, but more often than not, those of us for whom English is a second language had to sit through really boring lessons about it. </p><p>A quick look at the <a href="https://www.w3.org/TR/html50/text-level-semantics.html#the-em-element">examples from the spec itself</a> should make it clearer: they take the phrase “Cats are cute animals” and change the &lt;em&gt; tag from word to word, thus changing the meaning from implying that the discussion was about which animals are cute, to imply that the truth of the whole sentence was in question, implying that someone else said they were ugly, to the ridiculous notion that someone confused cats for plants. Or gods. Probably gods.</p><h2 id="some-use-cases">Some use cases</h2><p>We can use stress emphasis to communicate the higher importance of a word:</p><pre><code>&lt;p&gt;"I'm not &lt;em&gt;that&lt;/em&gt; into text semantics"&lt;/p&gt;</code></pre><p>The emphasis on “that” makes it clear that, while interested in it, it will not stop the speaker from using incorrect tags every now and then.</p><p>But we can use it to indicate sarcasm as well:</p><pre><code>&lt;p&gt;Sure, another TV is &lt;em&gt;exactly&lt;/em&gt; what our family needs&lt;/p&gt;</code></pre><p>To correct or clarify information, quoting <a href="https://www.quackit.com/html/tags/html_em_tag.cfm">Quackit excellent guide on text-level semantics:</a></p><pre><code>&lt;p&gt;"Did you say that you are a &lt;em&gt;chameleon&lt;/em&gt;?"&lt;/p&gt;
  5. &lt;p&gt;"No, I am a &lt;em&gt;comedian&lt;/em&gt;"&lt;/p&gt;</code></pre><p>We might also use it to hint at some implications:</p><pre><code>&lt;p&gt;What &lt;em&gt;we&lt;/em&gt; need to do is finish this project asap&lt;/p&gt;</code></pre><p>The emphasis implies that there’s <em>someone else</em> who needs to do <em>something else</em>.</p><p>It’s also used to mark the point of confrontation:</p><pre><code>&lt;p&gt;&lt;em&gt;Dogs&lt;/em&gt; are cute animals&lt;/p&gt;</code></pre><p>I’m implying a confrontation with somebody else who claimed <em>other</em> animals are cute (in this case, whoever wrote the HTML5 spec example) and marking the point of discrepancy.</p><p>&lt;em&gt; tags would normally be used on single words, maybe two, but we can sometimes use it on the whole sentence, to mark that the speaker is <em>really</em> fighting to get their point across, or denote an urgency. An exclamation can be the right use for &lt;em&gt; in a phrase:</p><pre><code>&lt;p&gt;&lt;em&gt;We need to get out of here!&lt;/em&gt;&lt;/p&gt;</code></pre><p>There are a gazillion WYSIWYG editors that get this wrong. From actual software intended to ease the creation of simple websites by drag-and-drop to blogging platforms; If your editor has the typical “italics — bold — underline” buttons, then most likely there’s nothing semantic about it.</p><p>Most (possibly all) of the ones that claim to be “semantic” are just throwing &lt;em&gt; for any italicised text and &lt;strong&gt; for bold text, without giving a thought about <em>why</em> the text is formatted that way (which is exactly what “semantics” try to solve). <strong>If there are no independent buttons for &lt;i&gt; and &lt;em&gt;</strong>, or a super-intelligent algorithm capable of interpreting <em>why</em> you are italicising text and applying the correct tag for the use case, <strong>it’s <em>not</em> semantic.</strong></p><p>Even our modern tools fall short when it comes to this. <strong>Markdown</strong> implementations use exactly the same approach of &lt;em&gt; for italicised text, &lt;strong&gt; for bold text.</p><p>Some of the reference <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#emphasis">guides </a>on it even go as far as saying</p><blockquote>Emphasis, <strong>aka </strong>italics, with asterisks or underscores.</blockquote><p>Which, at that point, really makes me think it might be the developers and not the tools.</p><p>I get it, Markdown is intended for quick writing, it even says so in the <a href="https://daringfireball.net/projects/markdown/syntax#html" rel="noreferrer nofollow noopener noopener">documentation</a></p><blockquote>Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is <strong>not </strong>to create a syntax that makes it easier to insert HTML tags. (…) HTML is a <strong>publishing </strong>format; Markdown is a <strong>writing </strong>format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.</blockquote><p>We could (in some implementations) manually use the &lt;i&gt; tag inside markdown formatted text, but even then, I feel like they should have addressed both in the language.</p><h2 id="when-not-to-use-em">When NOT to use &lt;em&gt;</h2><p>There are many cases where italics are meant to represent <em>something other than</em> emphasis.</p><p>In which case, the correct tag is actually <strong>&lt;i&gt;.</strong> Some may think &lt;i&gt; is a non-semantic tag, but it’s actually pretty much a catch-all tag for use cases where we want italicised text <em>without</em> stress emphasis.</p><p>To quote from the spec</p><blockquote>The i element represents a span of text in an <strong>alternate voice or mood</strong>, or otherwise offset from the normal prose in a manner indicating a different quality of text</blockquote><p>For instance, we should use &lt;i&gt; when marking an idiomatic phrase from another language, with their corresponding <strong>lang</strong> attribute so screen readers get the right pronunciation:</p><pre><code>&lt;p&gt;I would like us all to use better text-level semantics, but &lt;i lang="fr"&gt;c'est la vie&lt;/i&gt;&lt;/p&gt;
  6. &lt;p&gt;Major of Springfield, &lt;i lang="la"&gt;Corruptus in Extremis&lt;/i&gt;&lt;/p&gt;</code></pre><p>It is also used for taxonomic nomenclature:</p><pre><code>&lt;p&gt;&lt;i lang="la"&gt;Carnivorous Vulgaris&lt;/i&gt; keeps chasing his prey, &lt;i lang="la"&gt;Accelerati Incrediblus&lt;/i&gt; &lt;/p&gt;</code></pre><p>To mark a technical term:</p><pre><code>&lt;p&gt;Concepts like &lt;i&gt;closure&lt;/i&gt; can be confusing to JavaScript beginners&lt;/p&gt;</code></pre><p>fictional character voices:</p><pre><code>&lt;p&gt;&lt;i&gt;- That's what I do: I drink and I know things&lt;/i&gt;&lt;/p&gt;</code></pre><p>thoughts:</p><pre><code>&lt;p&gt;&lt;i&gt;I am better than this&lt;/i&gt;, she thought as she walked away&lt;/p&gt;</code></pre><p>and some other use cases, depending on the language (such as ship names).</p><p>Another italic-causing tag that we might find a good use for is the <strong>&lt;cite&gt;</strong> element.</p><p>It is used to mark the title of a work (painting, book, etc):</p><pre><code>&lt;p&gt;&lt;cite&gt;The persistence of memory&lt;/cite&gt; by Salvador Dalí. Painted in 1931&lt;/p&gt;</code></pre><p>or the author:</p><pre><code>&lt;p&gt; According to &lt;cite title="You're using &lt;em&gt; wrong. Published by LogRocket (October, 2018)"&gt;Facundo Corradini&lt;/cite&gt;, we should reconsider the tags we're using to italicise text.</code></pre><p>In many platforms &lt;blockquote&gt; causes the text to be italicised (as well as indented), but I don’t think anyone is confusing that one with &lt;em&gt;, and editors always have the proper button for it. It can cause some nesting issues though, so that’s something to keep in mind.</p><h2 id="why-it-matters">Why it matters</h2><p>Accessibility, of course. Every time we use the wrong tag to italicise a word, most of our users won’t even notice. As long as we are doing so according to our language conventions, the word will be read with the intended emphasis.</p><p>But <strong>we are making things so much more complicated for screen readers</strong>, especially when nesting. If we were doing our job right, speech synthesizers would be able to easily make the right pitch corrections. But we’re so far gone in this that all of them (as far as I know) have it disabled by default, and <strong>that’s a big part of what makes them feel so unnatural</strong>.</p><p>It can be enabled in some, but even then, they opted to just get anything that’s italicised and apply the inflection.. which is just as bad. They are correcting our errors.</p><p>But maybe, if we all start doing it the right way, we can get them to work properly in the future and feel much more human. <strong>We can communicate better</strong>.</p><p>I have to admit, this whole article kind of started with my strong disagreement with this <a href="https://twitter.com/css/status/1037774960943620097" rel="noreferrer nofollow noopener noopener">CSS-Tricks tweet on “nested emphasis”</a>.</p><figure class="kg-card kg-embed-card"><blockquote class="twitter-tweet"><p lang="en" dir="ltr">Nested emphasis? Undo it.<br/><br/>```<br/>em em {<br/> font-style: normal;<br/>}<br/>``` <a href="https://t.co/YIaBPoKvod">pic.twitter.com/YIaBPoKvod</a></p>— CSS-Tricks (@css) <a href="https://twitter.com/css/status/1037774960943620097?ref_src=twsrc%5Etfw">September 6, 2018</a></blockquote>
  7. </figure><p><br/>Let’s break that down: </p><pre><code>&lt;em&gt;Now &lt;em&gt;that's&lt;/em&gt; a change, she thought&lt;/em&gt;
  8. em em { font-style: normal;}</code></pre><p><em>Now</em> that’s <em>a change, she thought</em></p><p>The given phrase is a fictional character’s thought, who is putting emphasis on “that’s”, implying the change they’re talking about is really noticeable, probably compared to another, previous small change.</p><p>For starters, “Now that’s a change” is a thought, so it should be marked down with an &lt;i&gt; tag, not &lt;em&gt;. But as we previously discussed, pretty much all of our tools are forcing us to do these kinds of things, so I can live with that.</p><p>The part that really bugged me was the core idea of resetting the italics. To me, it looks like the worst possible solution. It doesn’t just fail to convey the intended <em>stress</em> on that word, it actually makes it appear outside the scope of the fictional character’s thought.</p><p>Look how much better it conveys the stress if we opt for adding bold weight instead:</p><pre><code>&lt;i&gt;Now &lt;em&gt;that's&lt;/em&gt; a change&lt;/i&gt;, she thought
  9. i em { font-weight: bold;}</code></pre><p><em>Now </em><strong><em>that’s</em></strong><em> a change</em>, she thought</p><p>Some might argue that an underline would get the job done just as well, which might be true for print, but it’s clearly a no-go for the web, as it would make it look like a link:</p><pre><code>&lt;i&gt;Now &lt;em&gt;that's&lt;/em&gt; a change&lt;/i&gt;, she thought
  10. i em {text-decoration: underline;}</code></pre><p>Or maybe use caps, after all, it’s just one word. Personally, I believe this one goes over-the-top and might be better suited for nesting bold-causing tags, as it’s commonly interpreted as shouting:</p><pre><code>&lt;i&gt;Now &lt;em&gt;that's&lt;/em&gt; a change&lt;/i&gt;, she thought
  11. i em {text-transform: uppercase;}</code></pre><p><em>Now THAT’S a change</em>, she thought</p><p>There are some other combinations of tags that would cause italicised text inside an italicised scope, but most of them are &lt;em&gt; inside some other tag, so I would argue that just setting the inner tag to bold does the trick almost every time.</p><h2 id="takeaways">Takeaways</h2><ul><li>Whenever you’re throwing italics at a word/phrase, think about why are you doing so and choose the right tag for the task if possible</li><li>When in doubt, read it aloud. Or get someone else to read it aloud and see if it matches your expected inflections</li><li>If you’re using italics on more than one or two words, &lt;em&gt; is probably not the right tag</li><li>Marking a whole phrase with &lt;em&gt; means urgency, so it would normally only be used in exclamations</li><li>When nesting italics-producing tags, go for a bold weight. And for the love of HTML, do not undo them!</li></ul><p>We need to start considering why we are italicising text and using the right tag for it. We can make our tools better. We can make the web better.</p>