<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xml:base="https://bjorn.now/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Css on bjorn.now</title><link>https://bjorn.now/tags/css/</link><description>Recent content in Css on bjorn.now</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 30 Sep 2025 13:09:33 +0200</lastBuildDate><atom:link href="https://bjorn.now/tags/css/feed.xml" rel="self" type="application/rss+xml"/><item><title>Use :focus-visible instead of :focus, because it will only show when helpful</title><link>https://bjorn.now/til/2025-09-30-focus-visible-instead-of-focus-to-avoid-extra-styling/?utm_medium=feed</link><pubDate>Tue, 30 Sep 2025 13:09:33 +0200</pubDate><guid>https://bjorn.now/til/2025-09-30-focus-visible-instead-of-focus-to-avoid-extra-styling/</guid><description>Use :focus-visible instead of :focus, because it will only show when helpful.
:focus-visible only shows focus styling when the browser determines keyboard navigation is being used, unlike :focus which triggers on all interactions including mouse clicks.</description><content:encoded><![CDATA[<p>Use <code>:focus-visible</code> instead of <code>:focus</code>, because it will <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible#focus_vs_focus-visible">only show when helpful.</a></p>
<p><code>:focus-visible</code> only shows focus styling when the browser determines keyboard navigation is being used, unlike <code>:focus</code> which triggers on all interactions including mouse clicks.</p>
<div class=" copy-enabled">
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-css" data-lang="css"><span class="line"><span class="cl"><span class="nt">button</span><span class="p">:</span><span class="nd">focus-visible</span> <span class="p">{</span> <span class="k">outline</span><span class="p">:</span> <span class="mi">2</span><span class="kt">px</span> <span class="kc">solid</span> <span class="kc">blue</span><span class="p">;</span> <span class="p">}</span></span></span></code></pre></div>
</div>
<p>This prevents the &ldquo;clicked button stays highlighted&rdquo; problem while preserving accessibility for keyboard users. <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible#focus_vs_focus-visible">Full browser logic on MDN</a>.</p>]]></content:encoded></item></channel></rss>