<?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: mighty_peach</title>
    <description>The latest articles on DEV Community by mighty_peach (@mighty_peach).</description>
    <link>https://dev.to/mighty_peach</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%2F52085%2Ffe8f6e29-a31d-4270-9c83-c0d460806337.jpg</url>
      <title>DEV Community: mighty_peach</title>
      <link>https://dev.to/mighty_peach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mighty_peach"/>
    <language>en</language>
    <item>
      <title>Accessible images, pictures and SVGs</title>
      <dc:creator>mighty_peach</dc:creator>
      <pubDate>Thu, 02 Feb 2023 08:06:45 +0000</pubDate>
      <link>https://dev.to/mighty_peach/accessible-images-pictures-and-svgs-4odd</link>
      <guid>https://dev.to/mighty_peach/accessible-images-pictures-and-svgs-4odd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Author of cover image is Marek Piwnicki&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Accessible images
&lt;/h2&gt;

&lt;p&gt;Images are an important part of any web app. We are using them for a lot of different purposes: decoration of text content, information about interactive UI, logos and icons. And how many goals we have for images, so many problems we meet in everyday routine. How to make image accessible? How to load different image for different device? What to do with &lt;code&gt;&amp;lt;svg /&amp;gt;&lt;/code&gt;? Animated &lt;code&gt;&amp;lt;svg /&amp;gt;&lt;/code&gt;?! Through this guideline, I want to solve these main, common problems with accessible images in web.&lt;/p&gt;

&lt;p&gt;As always, I want to refer to &lt;a href="https://www.w3.org/WAI/tutorials/images/" rel="noopener noreferrer"&gt;W3C guidelines&lt;/a&gt;, as the source of most reliable and safe information. It splits images by several categories, we will check few of them in detail. But it doesn’t describe how to optimise images, which image format to use, we will check these topics too. Let’s start with categories.&lt;/p&gt;

&lt;p&gt;Why we can’t just put image to DOM with &lt;code&gt;&amp;lt;img src=”my/image.jpeg” /&amp;gt;&lt;/code&gt; and keep it like this? Because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User may use your site with a screen reader.&lt;/li&gt;
&lt;li&gt;Your site needs to have proper Search Engine Optimisation.&lt;/li&gt;
&lt;li&gt;User could use your site from difference devices/screens.&lt;/li&gt;
&lt;li&gt;User could browse your site with bad internet connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Simple setup
&lt;/h3&gt;

&lt;p&gt;If the image is simple enough, that you could describe it with one sentence, or it presents simple information, a small piece of data, we could use &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt; with &lt;code&gt;alt&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F5k5dhsuqgrw37r5tu06a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F5k5dhsuqgrw37r5tu06a.jpg" alt="A white owl"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;”my/img.jpeg”&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;”A&lt;/span&gt; &lt;span class="na"&gt;white&lt;/span&gt; &lt;span class="na"&gt;owl&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple rules for &lt;code&gt;alt&lt;/code&gt; content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not use words “picture”, “image of”, “pic of”.
&lt;code&gt;&amp;lt;img src=”my/img.png” alt=”picture of beautiful white owl” /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Describe shortly what is going on in the image.&lt;/li&gt;
&lt;li&gt;Provide instruction if needed instead of describing image’s content.&lt;/li&gt;
&lt;li&gt;Add small explanation for images with icon role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Providing &lt;code&gt;alt&lt;/code&gt; attribute also helps for SEO – some search engines rely on it for “understanding” content of images on your site.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decorative images
&lt;/h3&gt;

&lt;p&gt;We often use images to decorate content: add snowfall to the site ❄️, add emotions for phrases 😂, create special mood 🌓. For this type of images, we have a really simple rule – keep &lt;code&gt;alt&lt;/code&gt; attribute empty.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fwiu11wfb8gjd1h356gay.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwiu11wfb8gjd1h356gay.jpg" alt="Abstract texture"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Texture for background image&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;”src.jpeg”&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;p&gt;Attribute &lt;code&gt;role=”presentation”&lt;/code&gt; also allow skipping this image for screen-readers. If we do not add empty &lt;code&gt;alt&lt;/code&gt; attribute to &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt; tag, screen readers will find and pronounce &lt;code&gt;src&lt;/code&gt; attribute of image, that can confuse users. And do not put whitespace accidentally, &lt;code&gt;alt&lt;/code&gt; attribute will be not hidden from screen readers then.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functional Images
&lt;/h3&gt;

&lt;p&gt;If you have buttons with only image as content - you need to add simple description as: “what will happen if I will click on button”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fl0ubq1u0023i11xacq46.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fl0ubq1u0023i11xacq46.jpg" alt="Printer icon"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;”src/print.png”&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;”print&lt;/span&gt; &lt;span class="na"&gt;the&lt;/span&gt; &lt;span class="na"&gt;form&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should never use image as a single source of truth. Always add text or tooltip for icon, that could be an action too and have some sense in text. You can add, at least, title attribute.&lt;/p&gt;

&lt;h3&gt;
  
  
  Graphs and charts
&lt;/h3&gt;

&lt;p&gt;Sometimes we have a very complex image that represents some data: image of a table, a graph or maybe screenshot of some chart. In this situation, we can’t describe image with simple sentence, but user of screen reader or search engine could have profit of reading data of image. Tag &lt;code&gt;&amp;lt;figure /&amp;gt;&lt;/code&gt; will help us in with the problem:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fu8xad41l2p0skf0iwb22.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fu8xad41l2p0skf0iwb22.jpg" alt="Graph with Vite vs Webpack data"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;figure&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"chart.png"&lt;/span&gt;
         &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Interest about Vite and Webpack over the year"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;figcaption&amp;gt;&lt;/span&gt;
        On graph we can see, that Vite is on the pick of popularity with rate 100, webpack has stable 13 points of popularity WorldWide. 
    &lt;span class="nt"&gt;&amp;lt;/figcaption&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/figure&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So then we associate an image with provided text. If this text shouldn’t be in site content - we can visually hide &lt;code&gt;&amp;lt;figcaption /&amp;gt;&lt;/code&gt; from user:&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;.visually-hidden&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;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt; &lt;span class="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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="cp"&gt;!important&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;
  
  
  SVG
&lt;/h3&gt;

&lt;p&gt;Often, sites have SVG icons for logotypes, as secondary icons or even as a hero picture. We are using them to provide better quality of content, to inline image or animate it. But how to do &lt;code&gt;&amp;lt;svg /&amp;gt;&lt;/code&gt; content more accessible?&lt;/p&gt;

&lt;p&gt;Let’s imagine that we have this SVG:&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;svg&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"red"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, let’s add &lt;code&gt;&amp;lt;title /&amp;gt;&lt;/code&gt; tag to the body:&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;svg&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Red Circle&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"red"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hmm, what if our &lt;code&gt;&amp;lt;svg /&amp;gt;&lt;/code&gt;asks for proper description? Let’s add &lt;code&gt;&amp;lt;desc /&amp;gt;&lt;/code&gt; tag:&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;svg&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Red Circle&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;desc&amp;gt;&lt;/span&gt;Red circle with black border and transparent background&lt;span class="nt"&gt;&amp;lt;/desc&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"red"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, let’s add &lt;code&gt;role=”image”&lt;/code&gt; attribute, to make browser “think” that this bunch of SVG tags are single image:&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;svg&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;”image”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Red Circle&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;desc&amp;gt;&lt;/span&gt;Red circle with black border and transparent background&lt;span class="nt"&gt;&amp;lt;/desc&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"50"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"red"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  User Generated Content
&lt;/h3&gt;

&lt;p&gt;A lot of content on the Internet is user generated. Users are loading photos, custom thumbnails for articles, user avatars. How to make this content accessible? There is a complex solution - check what is on photo, add keywords to &lt;code&gt;alt&lt;/code&gt; attribute as Twitter does. Yeah, sounds almost impossible. As simple solution - you could provide to user an input, where users could describe pictures or even add &lt;code&gt;alt&lt;/code&gt; attribute. &lt;br&gt;
I agree, we can’t do this for every image, but we could add “speculative” &lt;code&gt;alt&lt;/code&gt; attribute, for example, we could add &lt;code&gt;alt=”Profile picture of user @peact_tea”&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Wrapping up
&lt;/h3&gt;

&lt;p&gt;With all this content, we could say - easiest way to make image accessible is just adding &lt;code&gt;alt&lt;/code&gt; attribute (even empty still works - &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt; tag without it is not valid) to &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt; tag made it accessible. Unless somebody wrote something unexpected here 😅. Add title attribute to SVG and icons, to buttons and links, that contains only images and never use image as single source of truth.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(&lt;a href="https://www.w3.org/WAI/tutorials/images/)%5Bhttps://www.w3.org/WAI/tutorials/images/%5D" rel="noopener noreferrer"&gt;https://www.w3.org/WAI/tutorials/images/)[https://www.w3.org/WAI/tutorials/images/]&lt;/a&gt; - accessibility guidelines&lt;/li&gt;
&lt;li&gt;(&lt;a href="https://squoosh.app/)%5Bhttps://squoosh.app/%5D" rel="noopener noreferrer"&gt;https://squoosh.app/)[https://squoosh.app/]&lt;/a&gt; - optimise your images via squoosh&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>web</category>
      <category>html</category>
      <category>a11y</category>
    </item>
    <item>
      <title>About a11y in general</title>
      <dc:creator>mighty_peach</dc:creator>
      <pubDate>Sat, 21 Jan 2023 18:39:00 +0000</pubDate>
      <link>https://dev.to/mighty_peach/accessibility-in-general-1p7i</link>
      <guid>https://dev.to/mighty_peach/accessibility-in-general-1p7i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Author of cover image is Wolfgang Hasselmann&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is accessibility?
&lt;/h2&gt;

&lt;p&gt;User of old laptop with bad performance - &lt;em&gt;accessibility&lt;/em&gt;. User of mobile app who have broken hand - &lt;em&gt;accessibility&lt;/em&gt;. ASAP task that you need to do with bad Wi-Fi in a loud place - &lt;em&gt;accessibility&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Accessibility&lt;/em&gt; is the ability of users to complete their tasks in a product in any condition: with broken hand, in loud place, even without internet. I plan to help you find easy ways to correct accessibility of your app/site and how to manage accessibility in future.&lt;/p&gt;

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

&lt;p&gt;Yeah, we all heard that accessibility is mostly for screen-reader users, or that percent of users so low that we can neglect accessible UI. That is not really true. Imagine a user, who is trying to answer something really important via phone app with having grocery bags or even little child in one hand. Or user, who is working using your site, while being in train with continued tunnels on a way. Or even simpler, a user who turned on battery save mode, and because of that display lost its contrast. What do scenarios have in common? User without any disability became to have problem with access to a product, with usage of a product.&lt;/p&gt;

&lt;p&gt;Accessibility is not only about people with disabilities. A product with accessibility-oriented design would help every user of your app. (And even to you, if you are a mouse-less user 😅). Some rules and core principals further in text will show, that accessibility is not about “how to design this particular component”, it’s more about “how to make system and every-day routine being more accessibility friendly without waste of time”.&lt;/p&gt;

&lt;p&gt;I would even count performance of your product as an accessibility issue. I was in situation with 4Mb Internet, that constantly toggle its workability, and I got used to download everything that I need during night. And if your product works only with stable optic Internet, some users with bad devices, in places with bad Internet just can’t use it, so have no &lt;strong&gt;access&lt;/strong&gt; to your product. &lt;/p&gt;

&lt;p&gt;In web, &lt;a href="https://www.w3.org/WAI/standards-guidelines/wcag/"&gt;Web Content Accessibility Guidelines&lt;/a&gt; (WCAG) helps designers and developers make accessible UI/UX. But the same rules work for Mobile/Desktop development.&lt;br&gt;
Good practice of writing guides is base a guide on four principles, that WCAG provides: perceivable, operable, understandable, and robust. Let’s talk a little more about these principles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Perceivable
&lt;/h2&gt;

&lt;p&gt;This principle tells us that information of a product should be accessible via any comfortable for user way.&lt;/p&gt;

&lt;p&gt;Of course, we can’t make this for a whole product, for 100% cases. But the interesting part is we don’t really need. Most of our app is a text, so we don’t need to bother with doing something with it - just put it to the proper tag: &lt;code&gt;&amp;lt;h1/&amp;gt; - &amp;lt;h6/&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;p/&amp;gt;&lt;/code&gt;. It is easy with images, just add &lt;code&gt;alt&lt;/code&gt; attribute to the image tag and that’s it. It is harder for tables and graphs, and to be honest, we can bother more with images too, but I will create separate article-helper for these content. &lt;/p&gt;

&lt;p&gt;Next, we need to focus on visual representation of content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For large text, (18px) contrast should be 3:1, other text - 4,5:1.&lt;br&gt;
But sometimes, for example, for disabled state, you can’t continue to use the best contrast and make input looks like disabled one.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--51Y3Hqlj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvdqc9d7dww4vghrsd51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--51Y3Hqlj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvdqc9d7dww4vghrsd51.png" alt="Three inputs, one with good contrast, two with bad" width="880" height="310"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Text and colour should never be the only one source of information for user, add icons to buttons and links, add borders to information statements (pop-ups).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HRTbcKMl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cweghvuwe1snbe4axr1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HRTbcKMl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cweghvuwe1snbe4axr1w.png" alt="Two inputs, one with colour as mark of error, other with icon and error text, besides colour" width="880" height="310"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For form field, as input or textarea, use icons together with colour for validation state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Operable
&lt;/h2&gt;

&lt;p&gt;Users should have the ability to use a product with comfortable input devices. User can use mouse and keyboard, screen-reader or touch-screen and should be able to complete a scenario.&lt;/p&gt;

&lt;p&gt;Make focus state visible is an easy way to support this. Together with keyboard navigation, it is a good start for accessible UI. And, as developer, you don’t really need to do a lot, don’t turn &lt;code&gt;outline&lt;/code&gt; off, use semantic tags: inputs inside forms with labels, hierarchic headers, name parts of layout with &lt;code&gt;&amp;lt;main /&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;article /&amp;gt;&lt;/code&gt; and others. This isn’t asking for additional time in most cases, but you automatically add keyboard navigation, that means screen-readers support 😅&lt;/p&gt;

&lt;p&gt;So, basically you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use HTML tags semantically.&lt;/li&gt;
&lt;li&gt;Add focus, hover, active and visited states for controls, links.&lt;/li&gt;
&lt;li&gt;Check that user can complete scenario with only keyboard: tab, enter, arrows.&lt;/li&gt;
&lt;li&gt;Make focus state be visible.&lt;/li&gt;
&lt;li&gt;Design complex controls using simple built-in ones (and check &lt;a href="https://www.w3.org/WAI/ARIA/apg/patterns/"&gt;the guide&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understandable
&lt;/h2&gt;

&lt;p&gt;“Information and the operation of user interface must be understandable” - quite meaningless definition. But we can find few good thoughts here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Speak in user language. And this is not about English, French or Spain. If your user is not a lawyer - explain complex terms and simplify a text. &lt;/li&gt;
&lt;li&gt;Be consistent in UI - if you are using green button with “OK” text as agree-button, don’t suddenly use orange with “Agree” somewhere.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Robust
&lt;/h2&gt;

&lt;p&gt;Your product should be accessible with assistants. Sounds scary, sounds like a lot of work. Nevertheless, this is pretty simple with few rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;a /&amp;gt;&lt;/code&gt; for links, and &lt;code&gt;&amp;lt;button /&amp;gt;&lt;/code&gt; for interactive elements. If click changes &lt;code&gt;URL&lt;/code&gt; – you need to use &lt;code&gt;&amp;lt;a /&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;role&lt;/code&gt; attributes, for example &lt;code&gt;role="alert"&lt;/code&gt;. This allows to certainly mark HTML element with its role for screen-readers.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;alt&lt;/code&gt; attribute for images. This not only allows reading image content for screen-reader users, but also could show text in case of image loading error.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping this up
&lt;/h2&gt;

&lt;p&gt;These simple rules don’t ask for “let’s plan next sprint for accessibility tasks and forget about it” and sounds easy enough to make your product accessible even without convincing your boss 🙂&lt;/p&gt;

&lt;p&gt;Few additional tools, that can help you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.chrome.com/docs/devtools/#accessibility"&gt;https://developer.chrome.com/docs/devtools/#accessibility&lt;/a&gt; - Chrome developer tools allows testing accessibility right in browser.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.deque.com/axe/"&gt;https://www.deque.com/axe/&lt;/a&gt; - Axe tool has convenient browser extension for accessibility testing (also, you can use Axe with Jest).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/pa11y/pa11y"&gt;https://github.com/pa11y/pa11y&lt;/a&gt; - Tool for testing ally using node.js (it also has integration with Cypress).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/eslint-plugin-jsx-a11y"&gt;https://www.npmjs.com/package/eslint-plugin-jsx-a11y&lt;/a&gt; - ESLint plugin, that shows errors and warnings right in your editor.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>web</category>
      <category>a11y</category>
      <category>html</category>
    </item>
    <item>
      <title>Dependencies hell</title>
      <dc:creator>mighty_peach</dc:creator>
      <pubDate>Sun, 20 Mar 2022 15:18:27 +0000</pubDate>
      <link>https://dev.to/mighty_peach/dependencies-hell-gc5</link>
      <guid>https://dev.to/mighty_peach/dependencies-hell-gc5</guid>
      <description>&lt;p&gt;How does typical frontend project start?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;clone&lt;/span&gt; &lt;span class="nx"&gt;project&lt;/span&gt;

&lt;span class="nx"&gt;cd&lt;/span&gt; &lt;span class="nx"&gt;project&lt;/span&gt;

&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we have received thousands of modules installed in the OS, megabytes (or gigabytes) of files. After installation we try to start a project using &lt;code&gt;npm start&lt;/code&gt;, but we get some &lt;code&gt;node-gyp&lt;/code&gt;, versions errors or vulnerabilities This walls of information, that we can't fix, are really frustrating. I want to talk about some of these problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What’s wrong with deps&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Deps size is so big
&lt;/h3&gt;

&lt;p&gt;Let’s see how much size popular project &lt;code&gt;Create React App&lt;/code&gt; has:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Q2DRn0_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9f4sjvpji8737wfhoaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Q2DRn0_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9f4sjvpji8737wfhoaf.png" alt="The Create React App empty project has around 300mbs of size" width="798" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It has 300mbs that does nothing. After template was created devs can install &lt;code&gt;mobx&lt;/code&gt;, &lt;code&gt;axios&lt;/code&gt;, &lt;code&gt;css-in-js&lt;/code&gt; packages, components library, something like &lt;code&gt;lodash&lt;/code&gt; or &lt;code&gt;rx.js&lt;/code&gt;, some type definitions for typescript, etc. In result we have half of GB space of  empty project without actual code base.&lt;/p&gt;

&lt;p&gt;I want to remind - we are in chip shortage, Apple asks ~200$ for 128GB. These gigabytes of packages, that we transfer back and forth, don’t just disappear — they are stored in our disks (and often this is global npm packages, that we can’t just delete as project dependencies), in DNS servers, in data centres. This is unbelievable how irresponsibly we develop software, without looking into future and software complexity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deps doesn’t update theirs deps
&lt;/h2&gt;

&lt;p&gt;How regularly devs update their package dependencies? During my practice, this doesn’t happen as often as necessary. Let’s look at &lt;code&gt;create-react-app&lt;/code&gt; for example. It has &lt;code&gt;jest&lt;/code&gt; as dependency with version &lt;code&gt;27.4.3&lt;/code&gt;, when I wrote this article actual version was &lt;code&gt;27.5.1&lt;/code&gt;. &lt;br&gt;
Jest has &lt;code&gt;micromatch&lt;/code&gt; package with version &lt;code&gt;4.0.4&lt;/code&gt; (that was actual version for &lt;code&gt;jest@27.4.3&lt;/code&gt;). And &lt;code&gt;micromatch&lt;/code&gt; has &lt;code&gt;minimatch&lt;/code&gt; package with version &lt;code&gt;3.0.4&lt;/code&gt;. But actual version is &lt;code&gt;5.0.1&lt;/code&gt;, that solve, at least one major &lt;a href="https://github.com/isaacs/minimatch/issues/146"&gt;security problem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And this is just five minutes research, &lt;code&gt;Create React App&lt;/code&gt; has dozens of dependencies, which have dozens of dependencies, which have... One of them could be out of date or has vulnerability issues.&lt;/p&gt;

&lt;p&gt;Deps control can be more hard with very popular projects. &lt;code&gt;Cypress&lt;/code&gt; updates its version very often. Sometimes it happens twice a week. When I’ve started to use &lt;code&gt;Cypress&lt;/code&gt; I updated it every two week, but then I just got tire to do this. But this was mistake - Cypress team, probably, fixed some major bugs, solved some vulnerabilities in this updates. But as developer in modern and big project, where you have many deps, you can’t hold dependencies actual every time. &lt;/p&gt;
&lt;h2&gt;
  
  
  Maybe you don’t need these deps
&lt;/h2&gt;

&lt;p&gt;There are many instructions and StackOverflow answers that recommend: “Install &lt;code&gt;this&lt;/code&gt; to solve your problem”. Package distribution systems (&lt;code&gt;npm&lt;/code&gt;, &lt;code&gt;yarn&lt;/code&gt;, &lt;code&gt;pnpm&lt;/code&gt;) are very easy to use, they installed by default in some Unix-system, they installed with &lt;code&gt;Node.js&lt;/code&gt;. And this ease doesn’t good for our industry.&lt;/p&gt;

&lt;p&gt;Because complexity of IT is growing up from year to year, new folks learn only the tip of the iceberg (not all people, of course). Because the main goal of business is getting money, not creating good and robust software, we have no time to control every aspect of development. Open-source folks spend their own time to support projects.&lt;/p&gt;

&lt;p&gt;And because of these points we don’t spend time to check package size, all dependencies (include dependency’s dependencies), vulnerabilities, but much more, we don’t think that this package is necessary. We install &lt;code&gt;Axios&lt;/code&gt; instead of just using &lt;code&gt;fetch api&lt;/code&gt;. We use &lt;code&gt;css-in-js&lt;/code&gt; or &lt;code&gt;css modules&lt;/code&gt; instead of using &lt;code&gt;BEM&lt;/code&gt;. We could use just REST API, instead of &lt;code&gt;GraphQL&lt;/code&gt;. And there is much more examples.&lt;/p&gt;
&lt;h2&gt;
  
  
  What we can do
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Prioritize robustness over development speed and “developer experience”.&lt;/p&gt;

&lt;p&gt;Ask yourself about package necessity, maybe there is standard library method for your problem, or you don’t need full module, just a part, that you can copy-paste to your project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check not only stars and popularity, but also maintenance, update regularity, communication with community&lt;br&gt;
&lt;code&gt;CRA&lt;/code&gt; doesn’t update about year, we don’t have any news from their team. This is red flag not to  use &lt;code&gt;CRA&lt;/code&gt;. Actually, they released new version, but anyway, this was red flag :)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can store node_modules in version control system&lt;/p&gt;

&lt;p&gt;That sound stupid, but this is easy way to maintain dependencies, to ask questions “why do I need this”. This care us from unexpected node_modules extending. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Best practices are propaganda for juniors&lt;/p&gt;

&lt;p&gt;This topic can be disputed, but I think that the Patterns and other best practices, that puts into folks head to use it without thinking about necessity - are propaganda just as is. The Patterns are good, but we need to use it when we really meet a problem in code base. Sounds like I recommend to go to the Assembly and code using it, but no, I just recommend to think twice before doing something.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Solve actual problem, don’t solve future problem&lt;/p&gt;

&lt;p&gt;I have met so many times, when “architect” decided to use something like a store, argued that in future we could have a lot of data which we can share between modules and etc. And in this scenario we could use the react context and change it with store when we actually find a problem with data management. Another problem is technology FOMO - you need to use popular solutions, be in edge of technology. And there is much more examples when we solve problems that doesn’t exist. &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Easy receipts using std
&lt;/h2&gt;

&lt;p&gt;I want to show easy solutions of popular problems using standard library.&lt;/p&gt;

&lt;p&gt;Often we have installed by default &lt;code&gt;Lodash&lt;/code&gt; in our projects. &lt;code&gt;Lodash&lt;/code&gt; give us some handy functions, some syntax sugar. One of the best function is &lt;code&gt;debounce&lt;/code&gt;, that we use when we need to control user input.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YDN8Nz9P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc9z7snhydx33w3k104i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YDN8Nz9P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc9z7snhydx33w3k104i.png" alt="Receipt how to use lodash.debounce() from Lodash docs" width="880" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What’s wrong, you can ask. &lt;a href="https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L10304"&gt;Source code&lt;/a&gt; of function is unreadable. This is little function, but we install a whole &lt;code&gt;Lodash&lt;/code&gt; for this. This is how debounce looks using plain JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&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="nx"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;setTimeout&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="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;timeout&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="c1"&gt;// copy-paste from https://www.freecodecamp.org/news/javascript-debounce-example/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference is dozens of lines of code, is less maintainable, needs more code control.&lt;/p&gt;

&lt;p&gt;We often use &lt;code&gt;css-in-js&lt;/code&gt; or special setup of &lt;code&gt;webpack&lt;/code&gt; to stop class intersection. Really simple solution is &lt;a href="https://en.bem.info/methodology/css/"&gt;BEM&lt;/a&gt; — methodology of a class naming. We need to name every class like block_element-modification. Using React it looks like: &lt;code&gt;componentName_someWord&lt;/code&gt;. This is easy. &lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;When I've written this article I never stood a goal to change your mind, but if you start to think more about dependencies - this would be cool.&lt;/p&gt;

&lt;p&gt;I can recommend you to read or watch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/nikitonsky"&gt;nikitonsky -&lt;/a&gt; &lt;a href="https://tonsky.me/blog/disenchantment/"&gt;Software disenchantment&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Jonathan's Blow - &lt;a href="https://www.youtube.com/watch?v=pW-SOdj4Kkk"&gt;Collapse of Civs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you ❤️&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>development</category>
    </item>
  </channel>
</rss>
