<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rant — Getting Out There</title><link>https://blog.ryanmoore.au/tags/rant/</link><description>This blog is dedicated to my adventures in the great outdoors, fishing trips, hiking routes, camping, etc. as well as a collection of thoughts and interests. It's not all outdoorsy: there's plenty of politics, work/coding, football and other random ~~rants~~ thoughts I have.</description><language>en-au</language><lastBuildDate>Sun, 14 Apr 2024 17:59:06 +1000</lastBuildDate><atom:link href="https://blog.ryanmoore.au/tags/rant/index.xml" rel="self" type="application/rss+xml"/><item><title>Dont ever use &lt;B> in HTML... err... Wrong!</title><link>https://blog.ryanmoore.au/posts/2024/dont-use-b-in-html-wrong/</link><pubDate>Sun, 14 Apr 2024 17:59:06 +1000</pubDate><guid>https://blog.ryanmoore.au/posts/2024/dont-use-b-in-html-wrong/</guid><description>&lt;p class="lead">If you&amp;rsquo;ve ever &lt;b class='brand'>Google&amp;rsquo;d&lt;/b> the humble HTML &lt;code>&amp;lt;b&amp;gt;&lt;/code> tag, and read more than three of the results returned, you&amp;rsquo;ll have inevitably come across the hordes of self-righteous knobs on &lt;b class='brand'>StackExchange&lt;/b> berating people (especially those new to HTML/CSS) for using the tag. Their reason? It&amp;rsquo;s semantically-invalid HTML. &lt;strong>They. Are. Wrong!&lt;/strong>&lt;/p>
&lt;p>The key to the &lt;code>&amp;lt;b&amp;gt;&lt;/code> tag, or even the &lt;code>&amp;lt;i&amp;gt;&lt;/code> for that matter (but that&amp;rsquo;s a different post for another day) is that the &lt;em>usage&lt;/em> is different than what you might expect&amp;hellip;&lt;/p>
&lt;blockquote cite="mdn web docs">&lt;dl>
&lt;dt>&lt;code>b&lt;/code> is the &lt;del>Boldface&lt;/del> &lt;q>Bring Attention To&lt;/q> element&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;/dt>
&lt;dd>The &lt;code>&amp;lt;b&amp;gt;&lt;/code> HTML element is used to draw the reader&amp;rsquo;s attention to the element&amp;rsquo;s contents, which are not otherwise granted special importance. This was formerly known as the Boldface element, and most browsers still draw the text in boldface. However, you should not use &lt;code>&amp;lt;b&amp;gt;&lt;/code> for styling text or granting importance. If you wish to create boldface text, you should use the CSS font-weight property. If you wish to indicate an element is of special importance, you should use the &lt;code>&amp;lt;strong&amp;gt;&lt;/code> element.&lt;/dd>
&lt;/dl>
&lt;/blockquote>
&lt;p>That does &lt;em>not&lt;/em> necessitate being &lt;strong>bold&lt;/strong>. &lt;em>That&lt;/em> is a design decision separate to the semantic one. In days of yore, &lt;code>b&lt;/code> meant &lt;q>Boldface&lt;/q>. This is where the angst arises, because it is automatically assumed that you&amp;rsquo;re using &lt;code>&amp;lt;b&amp;gt;&lt;/code> because you&amp;rsquo;re ignorant of &lt;code>&amp;lt;strong&amp;gt;&lt;/code>.&lt;/p>
&lt;p>I use this tag liberally across my site to mark up any text where I use a brand name, e.g. &lt;code>&amp;lt;b class=&amp;quot;brand&amp;quot;&amp;gt;Google&amp;lt;/b&amp;gt;&lt;/code> signifies that &lt;b class="brand">Google&lt;/b> is a brand name, and then I &lt;em>do&lt;/em> style it subtly differently (I switch out the serif font for the sans-serif and italicise) but &lt;strong>importantly&lt;/strong>: that does &lt;em>not&lt;/em> mean I am using it for that function. All I am doing by adding it to my HTML is saying that this text &lt;em>may&lt;/em> need to be marked up as standing somewhat different to its surrounding context. What I do in the stylesheet afterwards is &lt;em>not&lt;/em> a determinant of its validity as HTML markup.&lt;/p>
&lt;p>My stylesheet declaring that&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-css" data-lang="css">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">b&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nc">brand&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">font-family&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">sans-serif&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">font-style&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">italic&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>is purely decorative and has no semantic meaning to the original markup. I might decide one day to not treat brand names any different from the surrounding text, and if I was to remove that stylesheet, my markup would remain perfectly valid. Or I could just remove the &lt;code>font-style: italic&lt;/code> style:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-css" data-lang="css">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">b&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nc">brand&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">font-family&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">sans-serif&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line hl">&lt;span class="cl"> &lt;span class="k">font-style&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">italic&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Some browsers still render &lt;code>&amp;lt;b&amp;gt;&lt;/code> as bold, &lt;code>&amp;lt;i&amp;gt;&lt;/code> as italicised, but that&amp;rsquo;s easily solved with a reset style in the root of your stylesheet, and it&amp;rsquo;s the browser&amp;rsquo;s fault and problem, not yours.&lt;/p>
&lt;p>So the next time you get berated (or find yourself about to do the berat&lt;em>ing&lt;/em>) take a moment to first discern the &lt;em>reason&lt;/em> that page is marked up the way it is. Maybe drawing &lt;em>some&lt;/em> attention to that element is correct, and you&amp;rsquo;re merely arguing about the stylistic choices of your fellows.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>Definition from &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b">mdn web docs&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div>
&lt;hr>&lt;p>&lt;strong>Rant:&lt;/strong>&lt;/p>&lt;p>Why the rant? I use &amp;lt;b&amp;gt; all over the site and some goose had at me about it.&lt;/p></description></item></channel></rss>