<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emmanuel</title>
    <description>The latest articles on DEV Community by Emmanuel (@masynctech).</description>
    <link>https://dev.to/masynctech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F266531%2F7ee83ca9-615a-4d90-9edb-59b4b2ee1f41.jpg</url>
      <title>DEV Community: Emmanuel</title>
      <link>https://dev.to/masynctech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/masynctech"/>
    <language>en</language>
    <item>
      <title>Focus on Accessibility: Mastering Form Input States for All Users</title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Tue, 19 Sep 2023 13:42:40 +0000</pubDate>
      <link>https://dev.to/masynctech/focus-on-accessibility-mastering-form-input-states-for-all-users-25ga</link>
      <guid>https://dev.to/masynctech/focus-on-accessibility-mastering-form-input-states-for-all-users-25ga</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Web accessibility is more important than ever, and understanding the finer points can make a world of difference. One crucial but often neglected feature is the focus state in form inputs. In this blog post, we will delve into how you can improve focus states for better accessibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Focus State
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Focus State?
&lt;/h3&gt;

&lt;p&gt;Focus state indicates which form input is currently active and ready to accept data. Typically, the browser will highlight this in some way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* CSS */&lt;/span&gt;
&lt;span class="nf"&gt;#username&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why is Focus State Important?
&lt;/h3&gt;

&lt;p&gt;The focus state is crucial for keyboard navigation. By making it clear which input is currently focused, you help users navigate your forms more easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Using &lt;code&gt;outline:none&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Many designers get rid of the focus state by setting &lt;code&gt;outline:none&lt;/code&gt;, mainly for aesthetic reasons. This, however, is a bad practice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Don't do this */&lt;/span&gt;
&lt;span class="nf"&gt;#username&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Better Practices: Using &lt;code&gt;:focus&lt;/code&gt; Wisely
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;:focus&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;:focus&lt;/code&gt; pseudo-class can be a game-changer for accessibility when used correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Good Practice */&lt;/span&gt;
&lt;span class="nf"&gt;#username&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why &lt;code&gt;outline&lt;/code&gt; Over &lt;code&gt;border&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;outline&lt;/code&gt; property does not affect the layout of your page, unlike &lt;code&gt;border&lt;/code&gt;, making it a better choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Using outline */&lt;/span&gt;
&lt;span class="nf"&gt;#username&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Using border */&lt;/span&gt;
&lt;span class="nf"&gt;#username&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Highlighting Form Groups
&lt;/h2&gt;

&lt;p&gt;Sometimes, making an entire form group stand out can be more beneficial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Using :focus-within to highlight a whole form group */&lt;/span&gt;
&lt;span class="nc"&gt;.form-group&lt;/span&gt;&lt;span class="nd"&gt;:focus-within&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Never eliminate the focus state; it's crucial for accessibility.&lt;/li&gt;
&lt;li&gt;Use high contrast for your focus styles.&lt;/li&gt;
&lt;li&gt;Test your focus states with real users and make adjustments as needed.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
