<?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: Abdulqudus Abubakre</title>
    <description>The latest articles on DEV Community by Abdulqudus Abubakre (@ibn_abubakre).</description>
    <link>https://dev.to/ibn_abubakre</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%2F307129%2F6610ea2d-5775-46b6-980a-2f69adb5fedd.jpg</url>
      <title>DEV Community: Abdulqudus Abubakre</title>
      <link>https://dev.to/ibn_abubakre</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ibn_abubakre"/>
    <language>en</language>
    <item>
      <title>Using aria-labelledby for accessible names</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Wed, 12 Nov 2025 10:14:58 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/using-aria-labelledby-for-accessible-names-22p4</link>
      <guid>https://dev.to/ibn_abubakre/using-aria-labelledby-for-accessible-names-22p4</guid>
      <description>&lt;p&gt;When building UI, we often rely on icons or visual cues that don’t include visible text. While that might look clean, it can leave screen reader users guessing.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;aria-labelledby&lt;/code&gt; is one of the techniques we can use to give clear context to assistive technologies.  &lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;aria-labelledby&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;aria-labelledby&lt;/code&gt; lets you reference visible text elsewhere in the DOM to create an accessible name for an element.  &lt;/p&gt;

&lt;p&gt;It basically tells assistive technology: &lt;em&gt;“Use this other element’s text to label me.”&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;It’s commonly used when the text that explains an element is located outside the element itself.&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="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dialog-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Edit Profile&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"dialog-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  ✏️
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the button doesn’t have its own text label, but because it references &lt;code&gt;dialog-title&lt;/code&gt;, assistive tech will announce &lt;strong&gt;“Edit Profile.”&lt;/strong&gt;  &lt;/p&gt;




&lt;h3&gt;
  
  
  Why use it?
&lt;/h3&gt;

&lt;p&gt;Sometimes we have elements, especially icon-only controls, that need textual context.  &lt;/p&gt;

&lt;p&gt;There are several techniques:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aria-label="Edit profile"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;button&amp;gt;Edit Profile&amp;lt;/button&amp;gt;&lt;/code&gt; (preferred)
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;title="Edit profile"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-labelledby="id"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, &lt;strong&gt;&lt;code&gt;aria-labelledby&lt;/code&gt; has the highest priority&lt;/strong&gt;, and if used, its referenced text will always take precedence over any other naming source.  &lt;/p&gt;




&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;p&gt;1) Create an element with descriptive text:&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="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dialog-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Edit profile&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Reference its ID using &lt;code&gt;aria-labelledby&lt;/code&gt; on the target element:&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="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"dialog-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;✏️&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it.  &lt;/p&gt;




&lt;h3&gt;
  
  
  ⚠️ Important things to note
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aria-labelledby&lt;/code&gt; has the &lt;strong&gt;highest priority&lt;/strong&gt; among naming sources
→ It will override &lt;code&gt;aria-label&lt;/code&gt;, &lt;code&gt;title&lt;/code&gt;, and even visible text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8pglvff4idepm6i07jn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8pglvff4idepm6i07jn.png" alt="the accessibility tree showing the available labels" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It depends on other elements. If the referenced element is hidden or removed, the accessible name becomes invalid
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"label"&lt;/span&gt; &lt;span class="na"&gt;hidden&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Example&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, if the &lt;code&gt;span&lt;/code&gt; is hidden, the accessible name of the button is lost❌.  &lt;/p&gt;

&lt;p&gt;✅ As a rule of thumb, use &lt;code&gt;aria-labelledby&lt;/code&gt; when:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A descriptive text already exists on the page
&lt;/li&gt;
&lt;li&gt;The label needs to be more than just a plain string
&lt;/li&gt;
&lt;li&gt;You want to use multiple elements as a label
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  ✅ Learn more
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MDN → &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;W3C → &lt;a href="https://www.w3.org/TR/wai-aria/#aria-labelledby" rel="noopener noreferrer"&gt;https://www.w3.org/TR/wai-aria/#aria-labelledby&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  ✅ Final Thoughts
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;aria-labelledby&lt;/code&gt; is a powerful tool for providing context, especially when UI patterns scatter text visually.  &lt;/p&gt;

&lt;p&gt;Just remember:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It takes &lt;strong&gt;top priority&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It relies on another element
&lt;/li&gt;
&lt;li&gt;If that reference breaks → the name breaks
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When used well, it helps assistive tech users understand your UI as clearly as everyone else.  &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>a11y</category>
      <category>html</category>
    </item>
    <item>
      <title>Automated Testing with jest-axe</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Sun, 22 Dec 2024 19:45:21 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/automated-testing-with-jest-axe-6fa</link>
      <guid>https://dev.to/ibn_abubakre/automated-testing-with-jest-axe-6fa</guid>
      <description>&lt;p&gt;When building web applications, ensuring accessibility should be as important as delivering features or fixing bugs. Automated testing tools like &lt;a href="https://www.npmjs.com/package/jest-axe" rel="noopener noreferrer"&gt;jest-axe&lt;/a&gt; make it easy to catch common accessibility issues early in development.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is jest-axe?
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;jest-axe&lt;/code&gt; is a Jest matcher built on top of the &lt;a href="https://github.com/dequelabs/axe-core" rel="noopener noreferrer"&gt;&lt;code&gt;axe-core&lt;/code&gt;&lt;/a&gt; accessibility engine. It allows you to test your rendered components for accessibility violations, integrating seamlessly with your existing Jest test suite.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Catch Accessibility Issues Early?
&lt;/h4&gt;

&lt;p&gt;Addressing accessibility errors early in the development process is crucial for several reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cost Efficiency:&lt;/strong&gt; Fixing issues during development is significantly cheaper and faster than addressing them after deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promotes Awareness:&lt;/strong&gt; Regularly testing with tools like &lt;code&gt;jest-axe&lt;/code&gt; helps developers become more mindful of accessibility considerations, influencing their decisions when writing HTML and designing components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preventing Technical Debt:&lt;/strong&gt; Early fixes prevent accessibility issues from snowballing into larger, harder-to-solve problems.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Setting Up jest-axe
&lt;/h4&gt;

&lt;p&gt;First, install the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; jest-axe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, add it to your test file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;axe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toHaveNoViolations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jest-axe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;toHaveNoViolations&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Writing a Basic Test
&lt;/h4&gt;

&lt;p&gt;Here’s an example of how you can test a simple component for accessibility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;axe&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jest-axe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should have no accessibility violations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;axe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveNoViolations&lt;/span&gt;&lt;span class="p"&gt;();&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;h4&gt;
  
  
  Testing a Vue Component
&lt;/h4&gt;

&lt;p&gt;If you’re working with Vue, &lt;code&gt;jest-axe&lt;/code&gt; integrates just as easily. Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mount&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vue/test-utils&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;axe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toHaveNoViolations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jest-axe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;toHaveNoViolations&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;button&amp;gt;Click me&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button component (Vue)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should have no accessibility violations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;axe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveNoViolations&lt;/span&gt;&lt;span class="p"&gt;();&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;h4&gt;
  
  
  Benefits
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Catch Issues Early:&lt;/strong&gt; &lt;code&gt;jest-axe&lt;/code&gt; helps you identify and fix accessibility problems during development.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy Integration:&lt;/strong&gt; Works with Jest, no steep learning curve.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actionable Feedback:&lt;/strong&gt; Provides detailed insights into violations.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Limitations
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Automated tests can’t catch everything—manual audits are still necessary for nuanced issues like keyboard navigation or color contrast.&lt;/li&gt;
&lt;li&gt;Studies show that automated tools can detect only about 30-50% of accessibility issues. For instance, they excel at identifying missing alt attributes but might miss issues with context or usability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Wrapping Up
&lt;/h4&gt;

&lt;p&gt;By adding &lt;code&gt;jest-axe&lt;/code&gt; to your test suite, you’re taking a solid step towards building accessible web applications. However, remember that no tool can guarantee full accessibility. Combine automated testing with manual checks and user testing for the best results.&lt;/p&gt;

&lt;p&gt;Happy testing!&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>testing</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding Accessible Names in HTML</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Tue, 03 Dec 2024 18:13:27 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/understanding-accessible-names-in-html-562</link>
      <guid>https://dev.to/ibn_abubakre/understanding-accessible-names-in-html-562</guid>
      <description>&lt;p&gt;Accessible names are a key part of ensuring that your web content is accessible to screen reader users. They provide the text that screen readers announce to describe an element, helping users navigate and interact with your content effectively.&lt;/p&gt;

&lt;p&gt;This post will explain how accessible names are determined, the order of precedence when multiple naming methods are used, and test your knowledge with real-world examples.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is an Accessible Name?
&lt;/h2&gt;

&lt;p&gt;An accessible name is a text or label that assistive technologies, like screen readers, announce to describe an element on a webpage. It is a critical part of digital accessibility, enabling users who rely on assistive technologies to understand and interact with web content effectively. &lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A button might have an accessible name like "Submit form."&lt;/li&gt;
&lt;li&gt;A link might be named "Learn more about our services."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is best to use visible text as the accessible name. Many elements, including &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;, can get their accessible name from their content. For example, given &lt;code&gt;&amp;lt;a href="services.html"&amp;gt;Learn more about our services&amp;lt;/a&amp;gt;&lt;/code&gt; , the accessible name of this link is "Learn more about our services"&lt;/p&gt;

&lt;p&gt;Without an accessible name, screen readers may announce generic or unhelpful labels like "button" or "link," leaving users confused.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Accessible Names are Computed
&lt;/h2&gt;

&lt;p&gt;The accessible name of an element is determined using a specific algorithm called the &lt;a href="https://w3c.github.io/accname/#mapping_additional_nd_description" rel="noopener noreferrer"&gt;Accessible Name and Description Computation&lt;/a&gt;. This algorithm evaluates different text sources in a defined order of precedence to compute the name.&lt;/p&gt;

&lt;p&gt;For elements like buttons and links, the accessible name is computed as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;aria-labelledby&lt;/code&gt;: References one or more elements whose text content provides the name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;aria-label&lt;/code&gt;: Directly defines the accessible name inline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Element Content: The visible text inside the element itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;title&lt;/code&gt; Attribute: Acts as a fallback when no other naming methods are provided.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For form inputs (e.g., &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;), the accessible name can also be determined by the associated &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;Elements: Text within a &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; linked to the input is the primary source for the name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples of Accessible Names in Action
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;A Button with Visible Text:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The accessible name is "Submit"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A Button with an Icon and &lt;code&gt;aria-label&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Settings"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;svg&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The accessible name is "Settings"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An Input Field with an Associated &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"search-box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Search&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"search-box"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The accessible name is "Search"&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Precedence of Accessible Names
&lt;/h2&gt;

&lt;p&gt;The computation differs slightly for various element types when it comes to determining an element's accessible name, but the general order of precedence is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;code&gt;aria-labelledby&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;References one or more elements whose text content provides the name. This takes the highest precedence across all element types.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;code&gt;aria-label&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides an inline label directly on the element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Associated &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; Element&lt;/strong&gt; (for form inputs):  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text content within a &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; associated with a form control (e.g., &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;) is used as the accessible name.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Element Content&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The visible text inside the element, such as the content of a &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;alt&lt;/code&gt; Attribute&lt;/strong&gt; (for &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; Elements):  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Describes the content or purpose of an image.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;title&lt;/code&gt; Attribute&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Acts as a fallback and is used only if none of the higher-priority naming methods are provided.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Test Your Knowledge: Accessible Names
&lt;/h2&gt;

&lt;p&gt;Below are examples of HTML elements. For each, try to determine what the accessible name (announced by a screen reader) would be. Then, check your answer!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Element with Text Content and &lt;code&gt;aria-label&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Submit form"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;What do you think the accessible name is?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;
"Submit form"&lt;br&gt;
The &lt;code&gt;aria-label&lt;/code&gt; takes precedence over the visible text content.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Element with &lt;code&gt;aria-labelledby&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt; attribute&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"tac"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I agree to the Terms and Conditions.&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"tac"&lt;/span&gt; &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"Agree"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;What do you think the accessible name is?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;br&gt;
"I agree to the Terms and Conditions."&lt;br&gt;
The &lt;code&gt;aria-labelledby&lt;/code&gt; attribute takes precedence, so the title attribute is ignored.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Button with &lt;code&gt;aria-labelledby&lt;/code&gt; and &lt;code&gt;aria-label&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"label2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Profile Settings&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"label2"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Settings"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;What do you think the accessible name is?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;&lt;br&gt;
"Profile Settings"&lt;br&gt;
The &lt;code&gt;aria-labelledby&lt;/code&gt; takes precedence over the &lt;code&gt;aria-label&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How did you do?
&lt;/h3&gt;

&lt;p&gt;Understanding how accessible names are determined is essential for creating web content that is usable for everyone. By following the rules of accessible naming and testing your work, you can ensure a better experience for assistive technology users.&lt;/p&gt;




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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Accessible names are essential for improving usability for screen reader users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All controls elements (e.g buttons, links) should have an accessible name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use attributes like &lt;code&gt;aria-labelledby&lt;/code&gt; sparingly as it has the highest order of precedence and calculating the name of an element with &lt;code&gt;aria-labelledby&lt;/code&gt; can be complex and reference hidden content as well&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure to test with screen readers to be sure what gets announced to the user.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>a11y</category>
      <category>html</category>
    </item>
    <item>
      <title>Hiding Elements in CSS: The Accessible Way</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Sun, 17 Nov 2024 18:27:00 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/hiding-elements-in-css-the-accessible-way-5h1b</link>
      <guid>https://dev.to/ibn_abubakre/hiding-elements-in-css-the-accessible-way-5h1b</guid>
      <description>&lt;p&gt;Hiding elements in your UI is common, but doing so in an accessible manner ensures you don’t unintentionally exclude some users. In this article, we’ll cover three scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hiding elements from screen readers.&lt;/li&gt;
&lt;li&gt;Showing elements to only screen readers.&lt;/li&gt;
&lt;li&gt;Hiding elements from all users, including screen readers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each section includes code examples and practical use case&lt;/p&gt;




&lt;h2&gt;
  
  
  Hiding elements from screen readers
&lt;/h2&gt;

&lt;p&gt;If you want an element to be visible to sighted users but hidden from screen readers, you can use the &lt;code&gt;aria-hidden="true"&lt;/code&gt; attribute or CSS.&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This content is hidden from screen readers.&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use cases
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Hiding background images&lt;/li&gt;
&lt;li&gt;Decorative icons or visual elements that don’t convey meaningful information.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  Add Item
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Showing elements to only screen readers
&lt;/h2&gt;

&lt;p&gt;To make an element visible to screen readers but invisible to sighted users, you can use the "visually hidden" technique. Tailwind CSS provides a prebuilt utility class, &lt;code&gt;sr-only&lt;/code&gt;, for this purpose.&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sr-only"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  This content is only visible to screen readers.
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Writing the &lt;code&gt;sr-only&lt;/code&gt; class in CSS would look like this&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="nc"&gt;.sr-only&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;clip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;white-space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;nowrap&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;0&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;
  
  
  Use cases
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;For labeling interactive elements like inputs without visually displaying the text:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sr-only"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Username&lt;span class="nt"&gt;&amp;lt;/label&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="na"&gt;name=&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;/li&gt;
&lt;li&gt;
&lt;p&gt;Providing additional information for screen reader users using aria-describedby&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sr-only"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"instructions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Password must include 8 characters, one number, and one special 
  symbol.
&lt;span class="nt"&gt;&amp;lt;/div&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;"password"&lt;/span&gt; &lt;span class="na"&gt;aria-describedby=&lt;/span&gt;&lt;span class="s"&gt;"instructions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hiding Input Elements for Custom Radio Buttons&lt;/strong&gt;&lt;br&gt;
When creating custom radio buttons (or checkboxes), you often hide the native input element and replace it with a visually styled element. To do this accessibly, the hidden input must remain visible to screen readers.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Hiding Elements from All Users
&lt;/h2&gt;

&lt;p&gt;To completely hide an element from both sighted users and screen readers, you can use &lt;code&gt;display: none&lt;/code&gt; or &lt;code&gt;visibility: hidden&lt;/code&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="nc"&gt;.hidden&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&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="c"&gt;/* or visibility: hidden; */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the class:&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This content is hidden from all users.&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Here’s a table summarizing how various CSS attributes affect visibility for different types of users:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;CSS Attribute&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Hides for All Users&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Hides for Sighted Users&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Hides for Screen Readers&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;display: none&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Completely removes the element from the visual and accessibility tree.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;visibility: hidden&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Hides the element visually but keeps it in the layout and accessibility tree.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;opacity: 0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Makes the element fully transparent but still visible to screen readers and interactive.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;clip: rect(0, 0, 0, 0)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Commonly used in the "visually hidden" technique; removes visual rendering but accessible.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;position: absolute; width: 1px; height: 1px;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Used with the "visually hidden" technique; keeps elements accessible to screen readers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;aria-hidden="true"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Removes the element from the accessibility tree but leaves it visually present.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;overflow: hidden&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅ (if out of bounds)&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Hides content visually if it overflows the container but does not affect screen readers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;height: 0; width: 0;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Hides content visually while keeping it accessible to screen readers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;z-index: -1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Moves the element behind others, making it invisible to sighted users but screen reader-accessible.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;opacity: 0; pointer-events: none;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Makes an element fully transparent and non-interactive, but accessible to screen readers.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>a11y</category>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Pausing, Stopping, and Hiding Animations with animation-play-state</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Sun, 20 Oct 2024 18:44:52 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/pausing-stopping-and-hiding-animations-with-animation-play-state-482</link>
      <guid>https://dev.to/ibn_abubakre/pausing-stopping-and-hiding-animations-with-animation-play-state-482</guid>
      <description>&lt;p&gt;When working with animations, it’s essential to ensure they are accessible to everyone. According to &lt;a href="https://www.w3.org/WAI/WCAG21/Understanding/pause-stop-hide.html" rel="noopener noreferrer"&gt;WCAG SC 2.2.2: Pause, Stop, Hide&lt;/a&gt;, users must be able to pause, stop, or hide animations that last more than 5 seconds. Let's break down how you can use CSS and JavaScript to create an animation that users can control.&lt;/p&gt;

&lt;h2&gt;
  
  
  A simple animation
&lt;/h2&gt;

&lt;p&gt;We'll start by creating a simple animation using CSS keyframes. This animation moves a box horizontally across the screen.&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"animated-box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
  &lt;span class="nc"&gt;.animated-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&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="m"&gt;#3498db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;move&lt;/span&gt; &lt;span class="m"&gt;4s&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;move&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding play state
&lt;/h2&gt;

&lt;p&gt;Next, we introduce the &lt;code&gt;animation-play-state&lt;/code&gt; property. This property allows us to control whether the animation is running or paused. We use a CSS variable, &lt;code&gt;--play-state&lt;/code&gt;, to set the default state of the animation.&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--play-state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.animated-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-play-state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--play-state&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;p&gt;Here, we define a &lt;code&gt;--play-state&lt;/code&gt; variable at the root level and set its initial value to running. The animation will run initially, but this variable gives us a way to control it later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding control with javascript
&lt;/h2&gt;

&lt;p&gt;We add a button that allows users to pause/play the animation by updating the &lt;code&gt;--play-state&lt;/code&gt; variable&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="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"toggle-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Pause Animation&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toggleButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toggle-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;toggleButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentPlayState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;getPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--play-state&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentPlayState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--play-state&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;paused&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;toggleButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resume Animation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--play-state&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;toggleButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pause Animation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use &lt;code&gt;getComputedStyle&lt;/code&gt; to get the current value of the &lt;code&gt;--play-state&lt;/code&gt; variable. Depending on whether the animation is running or paused, we toggle the value and also update the text of the button accordingly.&lt;/p&gt;

&lt;p&gt;You can find the complete working example on &lt;a href="https://codepen.io/abdulqudus001/pen/poMPzWG" rel="noopener noreferrer"&gt;codepen&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By implementing simple solutions like &lt;code&gt;animation-play-state&lt;/code&gt; and providing controls for animations, you help create a more inclusive digital experience.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>Building Accessible Animations with prefers-reduced-motion</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Sun, 26 Nov 2023 20:17:09 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/building-accessible-animations-with-prefers-reduced-motion-280a</link>
      <guid>https://dev.to/ibn_abubakre/building-accessible-animations-with-prefers-reduced-motion-280a</guid>
      <description>&lt;p&gt;Animations can be beautiful, but some animations can also be &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/Seizure_disorders" rel="noopener noreferrer"&gt;triggering&lt;/a&gt; for some users, and that's why electronic devices provide ways to turn off animations, e.g:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android =&amp;gt; Settings &amp;gt; Accessibility &amp;gt; Remove Animations&lt;/li&gt;
&lt;li&gt;iOS =&amp;gt; Settings &amp;gt; Accessibility &amp;gt; Motion&lt;/li&gt;
&lt;li&gt;Windows 10 =&amp;gt; Settings &amp;gt; Ease of Access &amp;gt; Display &amp;gt; Show animations in Windows&lt;/li&gt;
&lt;li&gt;Windows 11 =&amp;gt; Settings &amp;gt; Accessibility &amp;gt; Visual Effects &amp;gt; Animation Effects&lt;/li&gt;
&lt;li&gt;MacOS =&amp;gt; System Preferences &amp;gt; Accessibility &amp;gt; Display &amp;gt; Reduce motion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ensure the animations in our web application respect these settings, we need to make use of the &lt;code&gt;prefers-reduced-motion&lt;/code&gt; CSS feature to detect the user settings and carry out appropriate actions. In the example below, we have a simple button that by default has a pulse animation;&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="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn--animated"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Fancy Animation&lt;span class="nt"&gt;&amp;lt;/button&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="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;pulse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#577FAE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&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="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn--animated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pulse&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt; &lt;span class="n"&gt;infinite&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;p&gt;To disable any animation if the user has it turned off using the &lt;code&gt;prefers-reduced-motion&lt;/code&gt; feature, we can add the following block to our CSS;&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="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.btn--animated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;animation&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, with just a few lines of code, we're able to make our animated button accessible, which is sufficient to pass the &lt;a href="https://www.w3.org/WAI/WCAG21/Understanding/animation-from-interactions.html" rel="noopener noreferrer"&gt;WCAG Criterion 2.3.3&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Writing meaningful alt texts</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Fri, 13 Oct 2023 14:04:05 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/writing-meaningful-alt-texts-564e</link>
      <guid>https://dev.to/ibn_abubakre/writing-meaningful-alt-texts-564e</guid>
      <description>&lt;p&gt;When talking about techniques to improve accessibility, one topic that comes up quite often is alt (alternative) texts.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is alt text?
&lt;/h2&gt;

&lt;p&gt;Alt text, sometimes called alt descriptions or alt tags, is a short description in the form of an HTML attribute that we use to give context to an image when it cannot be viewed for some reason. The code below shows how you would add an alt attribute to an image tag in HTML:&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="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"sample alt text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why is it important?
&lt;/h2&gt;

&lt;p&gt;Having an alt text for your media files is important for so many reasons, some of them being:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Accessibility: users with some form of impairment who are not able to see an image would rely on tools like screen readers to describe what that image is.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User experience: when a user has a poor internet connection and is not able to load up an image, having an alt text that shows up, describing the image to the user massively improves the experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search Engine Optimization: having an alt text is good for SEO because your image could easily come up in an image search, hence increasing traffic to your website.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to write &lt;em&gt;meaningful&lt;/em&gt; alt text
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be descriptive but concise&lt;/strong&gt;: according to &lt;a href="https://www.w3.org/WAI/tutorials/images/tips/" rel="noopener noreferrer"&gt;web accessibility initiative tips&lt;/a&gt;, your alt text should be the most concise description possible of the image’s purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try to keep the description to no more than a sentence or two. For images that need to have a longer description, consider using the &lt;a href="https://www.w3.org/WAI/tutorials/images/complex/" rel="noopener noreferrer"&gt;long description technique&lt;/a&gt; for complex images.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid using phrases like "image of" or "picture of" because tools like screen readers already announce the presence of an image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't include copyright and photo credit information as part of the alt text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Provide context&lt;/strong&gt;: context in an alt text is very important. The same image can have a different description depending on the content of the page. For example, an image of a person at a football field can have an alt text of "Man waiting at the football field for his teammates to arrive" or "Man wearing the new bike boots for his first training session" depending on the content of the web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not all images need an alt text&lt;/strong&gt;. Some images are meant to be for decorative purposes only and, as such, do not need to have alt texts. To mark an image as decorative so it's not read out by the screen reader, you need to pass an empty alt text like this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For images used as links or buttons (functional images), the alt text should be what the link does rather than describing the image. An image of a printer should have the alt text "Print this page" which indicates the function of the image rather than what the image looks like.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, crafting meaningful alt text is a simple yet powerful way to enhance accessibility when executed correctly, but it can also lead to accessibility issues if not approached thoughtfully. The process of composing alt text isn't one-size-fits-all, as it hinges on various factors, including the image's nature, the website's content, and its functionality. Incorporating well-crafted alt text into your application significantly enhances the overall user experience.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Improving UX of your forms</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Wed, 01 Sep 2021 20:09:25 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/improving-ux-of-your-forms-166j</link>
      <guid>https://dev.to/ibn_abubakre/improving-ux-of-your-forms-166j</guid>
      <description>&lt;p&gt;Forms, without a doubt play an important role in our day to day activities. Whether you're trying to apply for a visa, or you're trying to sign up on an e-commerce platform to purchase an item.&lt;/p&gt;

&lt;p&gt;As a developer, making sure these forms are usable should be a top priority. There are a lot of things to worry about already, no one wants to worry so much about filling a form.&lt;/p&gt;

&lt;p&gt;In this article, I'd be listing some points I feel can improve the overall experience of filling forms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Validations Simple
&lt;/h2&gt;

&lt;p&gt;While it can be tempting to add a lot of validations to your form fields, try to keep them as simple as possible. Don't make assumptions based on what you already know. For example, it's very common to find name fields that are restricted to only alphabets when there are names that have hyphen and apostrophe in them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fioh3ombhvtt3k27w0pft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fioh3ombhvtt3k27w0pft.png" alt="Form complaining about name containing an apostrophe" width="638" height="991"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another example is validating phone numbers to make sure it matches a certain format (xxx-xxxx-xxxx). Instead, give the users some level of freedom and allow formats like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;01234567892&lt;/li&gt;
&lt;li&gt;012 3456 7892&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can then format the phone number in the background before sending it to the backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Show Error on Blur
&lt;/h2&gt;

&lt;p&gt;A painful part about filling a form field is when you keep seeing errors as you type ("&lt;em&gt;let me finish typing for God's sake&lt;/em&gt;"). Instead of showing errors immediately a user begins typing in an input field, consider waiting until the user is done typing and is about moving to the next field. Another option is to add  a delay, say about 500ms after user has stopped typing before showing the error message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Break Forms Into Steps
&lt;/h2&gt;

&lt;p&gt;Seeing a very long form can be intimidating so it's usually better to split them into steps with some sort of progress indicator. This way, users are more likely complete the form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't Just Disable The Submit Button
&lt;/h2&gt;

&lt;p&gt;A very popular practice is to disable the submit button whenever all validations have not been met. This works, but can be made better but allowing the users click the submit button, then if there are any invalid fields, scroll to that field and show the corresponding error message. This has a better user experience and is also more secure. Just adding the disabled attribute means the user and toggle the attribute from the devtools and be able to submit the button regardless&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Either Confirm Password Or Toggle Password Visibility
&lt;/h2&gt;

&lt;p&gt;If you have a password field with the options to toggle visibility, then there's no much need to have a confirm password field. Why do I have to confirm password when I can already see the password I entered?&lt;br&gt;
One way to implement this is to check if the password is visible, if yes, then hide the &lt;code&gt;confirm password&lt;/code&gt; field, otherwise, show it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Clear or Reset Button
&lt;/h2&gt;

&lt;p&gt;While this might seem like a handy feature, it can become painful when a user has filled a long form and is about to click submit, but mistakenly clicked the clear button&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Appropriate Input Type
&lt;/h2&gt;

&lt;p&gt;This allows the device to show the corresponding keyboard for a particular input. Like showing an &lt;strong&gt;@&lt;/strong&gt; for en email type, or a number pad for a type &lt;strong&gt;tel&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ux</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Why your z-index isn't working</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Mon, 10 May 2021 09:16:14 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/why-your-z-index-isn-t-working-i6j</link>
      <guid>https://dev.to/ibn_abubakre/why-your-z-index-isn-t-working-i6j</guid>
      <description>&lt;p&gt;I was building a sidebar recently, and I encountered a bug where the content of the page was always on top of the mobile navbar no matter how high I raised the z-index of the sidebar. This took me a while to figure out and I'm writing this article hoping that someone out there won't waste a lot of time like I did trying to solve the bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is z-index
&lt;/h2&gt;

&lt;p&gt;z-index is a CSS property that allows you to set the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context" rel="noopener noreferrer"&gt;stacking order&lt;/a&gt; of &lt;em&gt;positioned&lt;/em&gt; elements in the DOM. Here's how to specify the z-index from your CSS:&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="nc"&gt;.element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&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;p&gt;When no z-index is set, the stacking order follows the appearance &lt;br&gt;
of the elements in the DOM. &lt;/p&gt;
&lt;h2&gt;
  
  
  I set the z-index correctly, so why doesn't it work?
&lt;/h2&gt;

&lt;p&gt;The z-index of an element depends on a number of things, and usually, when these conditions aren't met, the z-index of your element would most likely not take effect.&lt;/p&gt;

&lt;p&gt;Here are some of the reasons why your z-index doesn't work;&lt;/p&gt;
&lt;h3&gt;
  
  
  You set z-index on a static element
&lt;/h3&gt;

&lt;p&gt;By default, every element has a position of static. z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.&lt;/p&gt;
&lt;h3&gt;
  
  
  A ridiculously large z-index was previously set
&lt;/h3&gt;

&lt;p&gt;You might be working on an existing codebase that had the z-index of an element set to 999 (for example). This would affect the stacking order as only an element with a higher z-index can show on top. So you would need to set the z-index of at least 1000 for the z-index to work. Also, it's good practice to avoid setting large z-index values, that way you can avoid issues such as this.&lt;/p&gt;
&lt;h3&gt;
  
  
  The parent element has a lower z-index
&lt;/h3&gt;

&lt;p&gt;The z-index of an element can only go as far as the maximum z-index of its parent (it cannot appear in a higher stacking context than its parent). Take for example;&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="nc"&gt;.child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.element-to-cover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&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;p&gt;In this case, you want to display the &lt;code&gt;child&lt;/code&gt; element over the &lt;code&gt;element-to-cover&lt;/code&gt; element so you set the z-index to 3. This should work since it has a z-index higher than the &lt;code&gt;element-to-cover&lt;/code&gt;, but because the parent element has a z-index of 1, the &lt;code&gt;child&lt;/code&gt; element would not appear above the &lt;code&gt;element-to-cover&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;You have to set the position of an element for the z-index to work&lt;/li&gt;
&lt;li&gt;Check to see if the element has a lower z-index value than the element you want it to appear over &lt;/li&gt;
&lt;li&gt;The z-index won't work if the parent element has a z-index lower than the z-index of your element&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This article was originally post on &lt;a href="https://ibnabubakre.xyz/blog/why-your-z-index-isnt-working/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Font loading strategies: FOIT and FOUT</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Wed, 21 Apr 2021 22:37:02 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/font-loading-strategies-foit-and-fout-393b</link>
      <guid>https://dev.to/ibn_abubakre/font-loading-strategies-foit-and-fout-393b</guid>
      <description>&lt;p&gt;Flash Of Invisible Text and Flash Of Unstyled Text are two font loading strategies used in major browsers. This post looks at what they are and how they affect your website.&lt;/p&gt;

&lt;p&gt;Custom web fonts have been around for a while now but sadly web browsers still don't have an optimal way of loading them. Web fonts are usually large files and they take quite some time to load on your web page. Different browsers have different ways of handling this delay. While some browsers would show a system font pending when the custom font gets loaded (&lt;em&gt;Flash Of Unstyled Text&lt;/em&gt;), some browsers would show blank text until the font has been loaded (&lt;em&gt;Flash Of Invisible Text&lt;/em&gt;). &lt;/p&gt;

&lt;h2&gt;
  
  
  Flash Of Invisible Text (FOIT)
&lt;/h2&gt;

&lt;p&gt;When a custom font is not ready to be loaded, some browsers would hide the text completely while others would only hide it for a few seconds. Browsers like Chrome and Firefox would hide the text for 3 seconds and if the font doesn't get loaded by then, a system font would be loaded. Other browsers like Safari completely hides the text until the font is ready to be loaded. The image below is a screenshot of a lighthouse audit that shows what happens when you don't account for FOIT in your application&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7br542i2q4w5xa7obcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7br542i2q4w5xa7obcj.png" alt="Screenshot of lighthouse test showing effect of FOIT" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Flash Of Unstyled Text (FOUT)
&lt;/h2&gt;

&lt;p&gt;In this case, before the custom font is loaded, a system font is loaded by default and swapped out as soon as the custom font is ready. This is the preferred behavior because showing a &lt;em&gt;flash of invisible text&lt;/em&gt; has a significant effect on your websites overall performance.&lt;/p&gt;

&lt;p&gt;In this article, we will look at two ways to avoid showing the invisible text. The first option, which is quite simple and straightforward is to add the &lt;code&gt;font-display: swap&lt;/code&gt; rule to our CSS. Such that when you want to setup your custom font, we tell the browser to load a system font and swap it out when our font is done loading. Here's how that would look like:&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="k"&gt;@font-face&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Poppins&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;font-display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;swap&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;p&gt;This method is quite straightforward but sadly, not supported by all browsers, So, if you're looking to account for all browsers, this might not work for you.&lt;/p&gt;

&lt;p&gt;Another method, though involves more code but can work across all browsers involve the use of an external library called &lt;a href="https://github.com/bramstein/fontfaceobserver" rel="noopener noreferrer"&gt;FontFaceObserver&lt;/a&gt;. To make this work, you have to;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you don't use the custom font in your CSS on initial page load.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;FontFaceObserver&lt;/code&gt; library to detect when the font is loaded.&lt;/li&gt;
&lt;li&gt;Update the page styling to use the custom font.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a &lt;a href="https://web.dev/codelab-avoid-invisible-text/" rel="noopener noreferrer"&gt;codelab&lt;/a&gt; by google that helps understand how to use the &lt;code&gt;FontFaceObserver&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;TL;DR&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FOIT and FOUT are font loading strategies used by browsers to load custom fonts.&lt;/li&gt;
&lt;li&gt;FOIT shows an invisible text while FOUT uses a system font until the font is loaded.&lt;/li&gt;
&lt;li&gt;FOUT should be preferred over FOIT.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Default behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Edge;&lt;/td&gt;
&lt;td&gt;Uses system font until the custom font is ready (FOUT)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari;&lt;/td&gt;
&lt;td&gt;Hides text until the custom font is ready (FOIT)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox;&lt;/td&gt;
&lt;td&gt;Initially hides text for 3 seconds. Uses system font after that until the custom font is ready (FOIT &amp;amp; FOUT)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome;&lt;/td&gt;
&lt;td&gt;Initially hides text for 3 seconds. Uses system font after that until the custom font is ready (FOIT &amp;amp; FOUT)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>performance</category>
      <category>css</category>
    </item>
    <item>
      <title>Styling file inputs like a boss</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Fri, 21 Aug 2020 15:24:38 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/styling-file-inputs-like-a-boss-mhm</link>
      <guid>https://dev.to/ibn_abubakre/styling-file-inputs-like-a-boss-mhm</guid>
      <description>&lt;p&gt;HTML elements have default styles applied to them by individual browsers. These styles could vary depending on the browser, and applying your own custom styles could range from being very easy to unnecessarily complicated (sometimes impossible).&lt;/p&gt;

&lt;p&gt;In this article we would be going through how to style file inputs, which happens to be one of those difficult elements to style using CSS.&lt;/p&gt;

&lt;p&gt;If you've worked with file inputs in your application, you'd know that the default style doesn't look so nice. Here's an example of how it looks in chrome and firefox in case you're wondering.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4peb4xad0aj8skvkh5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4peb4xad0aj8skvkh5x.png" alt="Default file inputs in firefox and chrome" width="800" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The good news is, we can fix this...the bad news is we won't be able to use the &lt;em&gt;"conventional"&lt;/em&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling File Inputs
&lt;/h2&gt;

&lt;p&gt;Let's create a simple file input in our HTML.&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"file-input"&lt;/span&gt;&lt;span class="nt"&gt;&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;"file"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Select file&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To style a file input, the first thing we would need to do is get rid of the default file input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hiding the input
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.file&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&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;p&gt;You might be thinking, why not use &lt;code&gt;display: none&lt;/code&gt; to hide the input. Well the problem with that is the input field would be removed from the layout and then become inaccessible to people using screen readers which would be very bad.&lt;/p&gt;

&lt;p&gt;Another important thing to note is the &lt;code&gt;label&lt;/code&gt;. With file inputs, clicking on the label also opens up the file picker, so we can use that to our advantage and style the label anyway we want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Styling the label
&lt;/h3&gt;

&lt;p&gt;Now that we've hidden the default input, we can decide to style the label however we want. For simplicity sake, let's just make it look like a button.&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="nc"&gt;.file-input&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;40deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#ff6ec4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#7873f5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="m"&gt;7px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="m"&gt;.2s&lt;/span&gt; &lt;span class="n"&gt;ease-out&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;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8k4m11jf03ie3pk94jz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8k4m11jf03ie3pk94jz.png" alt="Styled input with purple gradient" width="200" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessibility
&lt;/h3&gt;

&lt;p&gt;So we've been able to style the label to look like a button, but that's not all. We need to add some sort of indications to the label for when people hover on the field, or try to focus on the file field using the keyboard. I'm just going to do something simple here and increase the size of the label when that happens.&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="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.02&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;p&gt;We can also decide to add an outline to the label on focus&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="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;label&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;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#000&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="n"&gt;-webkit-focus-ring-color&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="m"&gt;2px&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;p&gt;The &lt;code&gt;-webkit-focus-ring-color&lt;/code&gt; is used to get the default outline look on webkit browsers like chrome or safari. For non webkit browsers, a black outline would be applied to the element.&lt;/p&gt;

&lt;h3&gt;
  
  
  Javascript Enhancements
&lt;/h3&gt;

&lt;p&gt;We can use JavaScript to display the name and size of the file selected. This would create a slightly more natural feel to the custom field. So let's modify our HTML and CSS a bit.&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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"file-input"&lt;/span&gt;&lt;span class="nt"&gt;&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;"file"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Select file
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"file-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&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="nc"&gt;.file-name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-35px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.85rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#555&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;p&gt;Finally, we would add an event listener to the file input and reflect the name and size of the file below the label.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#file&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the selected file&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the file name and size&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Convert size in bytes to kilo bytes&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Set the text content&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileNameAndSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; - &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fileSize&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;KB`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.file-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fileNameAndSize&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;p&gt;Here's how everything looks.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/abdulqudus001/embed/rNORJYo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;And that's it for the file input. You could decide to style this however you want to get the behavior you want, it's up to you. Happy styling!😁😁&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Don't Just Say Hi....</title>
      <dc:creator>Abdulqudus Abubakre</dc:creator>
      <pubDate>Sat, 01 Aug 2020 05:14:16 +0000</pubDate>
      <link>https://dev.to/ibn_abubakre/don-t-just-say-hi-25eo</link>
      <guid>https://dev.to/ibn_abubakre/don-t-just-say-hi-25eo</guid>
      <description>&lt;p&gt;As tech enthusiasts, we would at some point, for one reason or another need to reach out to someone. It could be that you need help with a bug in your code, career advice, or mentorship....whichever case, just &lt;strong&gt;go straight to the point&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're most likely going to get a response if you go straight to the point rather than just saying &lt;em&gt;hi&lt;/em&gt; or &lt;em&gt;hello&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;You'll save yourself a lot of time, especially if you have a bug you need help with. Rather than going through the whole process of exchanging pleasantries, just go straight to the point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine I have a bug in my code I've been trying to fix, and I need help from someone. Rather than just saying hi and waiting for a response, here's how I would reach out to them&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hi, I have issues trying to setup docker on my computer, I keep getting xxxx error message. Here's a screenshot of the error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Or I could go further to introduce myself&lt;br&gt;
&lt;code&gt;Hi, I'm xyz and I got your number from abc. I get this error in my console, it says xxxx and it happens whenever I click on xxxx button. Here's the function called whenever the button is clicked&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's that simple. You don't have to go through the whole &lt;strong&gt;hello, how are you, how's your day going....&lt;/strong&gt;. Like I said, it saves you a lot of time, and you're most probably going to get a response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This is just my opinion. If you have contrary opinions and you would like to discuss them with me, my DMs are open on &lt;a href="https://www.twitter.com/ibn_abubakre" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;, feel free to reach out...and don't just say hi 😉&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
