title: Designing better target sizes
url: https://ishadeed.com/article/target-size
hash_url: c98206d38897264005bcd5b453d032b1
archive_date: 2024-01-10
og_image: https://ishadeed.com/assets/target-size/twitter-card.jpg
description: An interactive guide on designing better target sizes on the web.
favicon: https://ishadeed.com/assets/favicon-32x32.png
language: en_US

<h2 id="intro">Intro</h2>
<p>As a user, you need to interact with clickable UI elements like buttons, links, cards, and more.</p>
<p>If an action has a small target size, it will be harder for the user to click, or they might click an adjacent action element by mistake.</p>
<p>Let’s take a look at the following example.</p>
<p><astro-island uid="1rP0JF" prefix="r1" component-url="https://ishadeed.com/_astro/Demo1.8eWum0Xi.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true]}' ssr="" client="visible" opts='{"name":"Demo1","value":true}' await-children=""><div><p>Try to hover on an item ☝️ </p></div></astro-island></p>
<p>Notice the small target size? We can address this by increasing the target size.</p>
<p>When the target size is increased, it becomes easier for a user to click and interact with an element.</p>
<p><astro-island uid="3MEby" prefix="r2" component-url="https://ishadeed.com/_astro/Demo1.8eWum0Xi.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"Demo1","value":true}' await-children=""></astro-island></p>
<p><strong>Hover over the menu and toggle the checkbox</strong> to observe the difference between small and large target sizes.</p>
<h2 id="what-is-a-target-size">What is a target size?</h2>
<p><astro-island uid="2131rO" prefix="r71" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"The specific region within a user interface element where a user clicks, touches, or taps to trigger an action."]}' ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>The specific region within a user interface element where a user clicks, touches, or taps to trigger an action.</p></div></blockquote></astro-island></p>
<p>Today, users interact with a UI in various ways; it’s not solely about clicking an element with a mouse.</p>
<p>Below is a table illustrating how multiple input types can function on the same device.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/input-types.TICJ3qfC_26stTG.png" type="image/png"><source srcset="https://ishadeed.com/_astro/input-types.TICJ3qfC_ZHx551.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/input-types.TICJ3qfC_26stTG.png" alt="A visual that shows the different input types for mobile, tablet, and desktop" loading="lazy" decoding="async"> </source></source></picture></p>
<p>That thing caused to have many names for the topic:</p>
<ul>
<li>Apple calls it a <strong>hit target</strong></li>
<li>Google Material calls it a <strong>Touch target</strong></li>
<li>WAI call it a <strong>target size</strong></li>
<li>Google LightSpeed test call it a <strong>Tap target</strong></li>
<li><strong>Clickable area</strong>: used in the design community</li>
</ul>
<p>When talking about this, it’s important to know the context. For example, <strong>on mobile it’s the touch or tap</strong>, but on <strong>a device with a mouse it’s the click target</strong>.</p>
<p>Here is an example of that.</p>
<p><astro-island uid="Z14dVCp" prefix="r3" component-url="https://ishadeed.com/_astro/DemoContext.riEHUkJo.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"DemoContext","value":true}' await-children=""><div><div class="example-wrapper center"><div class="demo-context"><div><svg viewbox="0 0 28 29" fill="none" xmlns="http://www.w3.org/2000/svg"><g opacity="0.5"><path d="M12.3484 12.808C12.3484 14.675 15.1484 14.675 15.1484 12.808C15.1484 10.941 12.3484 10.941 12.3484 12.808Z" fill="black"></path><path d="M17.8914 12.808C17.8914 14.675 20.6914 14.675 20.6914 12.808C20.6914 10.941 17.8914 10.941 17.8914 12.808Z" fill="black"></path><path d="M6.94414 12.808C6.94414 14.675 9.74414 14.675 9.74414 12.808C9.74414 10.941 6.94414 10.941 6.94414 12.808Z" fill="black"></path><path d="M9.51938 3.20386H18.5079C23.6037 3.20386 27.7754 7.34814 27.7754 12.4724C27.7754 17.5967 23.6311 21.741 18.5068 21.741H16.1826L9.26688 26.8653L9.26797 21.7127C4.28369 21.5727 0.252249 17.4841 0.252249 12.4441C0.251156 7.34842 4.42369 3.20414 9.51969 3.20414L9.51938 3.20386ZM9.51938 20.4239H10.5836V24.2596L15.735 20.4239H18.5066C22.9023 20.4239 26.458 16.8681 26.458 12.4724C26.458 8.0767 22.9023 4.52098 18.5066 4.52098L9.51916 4.51988C5.12344 4.51988 1.56771 8.0756 1.56771 12.4713C1.56771 16.8682 5.12366 20.4239 9.51938 20.4239Z" fill="black"></path></g></svg><p>I checked the order page on my <span>phone</span> and tried to <span>tap</span> the order button but it’s not responding.</p></div></div></div></div></astro-island></p>
<p>For clarity purposes, I will refer to the concept as target size for the rest of the guide, even though I wrote about it and called it <a href="https://ishadeed.com/article/clickable-area/">clickable area</a> years ago.</p>
<h2 id="inclusive-target-size">Inclusive target size</h2>
<h3 id="minimum-target-size">Minimum target size</h3>
<p>According to the <a href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html">WCAG 2.5.5</a> guidelines, the target size must at least be 24 by 24 CSS pixels. I want to emphasize that this is about the target size, not the icon size.</p>
<p>Let’s take the following example. We have a mobile menu. The size of the icon is 24 by 24 pixels.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/min-target-size-1.bf6twW3i_1qhhM0.png" type="image/png"><source srcset="https://ishadeed.com/_astro/min-target-size-1.bf6twW3i_ihIre.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/min-target-size-1.bf6twW3i_1qhhM0.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>However, the target size is 44 by 44 pixels. This is the area where the
user can hover or tap.</p>
<p>The recommended size differs from one platform to another. For example, Material for Android recommends a 48 by 48 pixels target size.</p>
<p>As per the <a href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html">WCAG 2.5.8</a>, for a target size to pass, it should have a minimum of 24 by 24-pixel target size and it shouldn’t overlap with other targets.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/min-target-size-2.bCoimqde_Z2staXt.png" type="image/png"><source srcset="https://ishadeed.com/_astro/min-target-size-2.bCoimqde_1tIouG.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/min-target-size-2.bCoimqde_Z2staXt.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Notice when the target size is less than 24 by 24 pixels, the circles overlap.
The target size failed. This is as per the WCAG 2.2 guidelines.</p>
<figure><picture> <source srcset="https://ishadeed.com/_astro/min-target-size-3.6qqxqgwd_Z17Ni1N.png" type="image/png"><source srcset="https://ishadeed.com/_astro/min-target-size-3.6qqxqgwd_Z2fMQmz.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/min-target-size-3.6qqxqgwd_Z17Ni1N.png" alt="" loading="lazy" decoding="async"> </source></source></picture> <figcaption><p>Left: the actions compared to the screen size. Right: the actions
compared to my thumb finger.</p></figcaption></figure>
<figure><picture> <source srcset="https://ishadeed.com/_astro/min-target-size-4.mBikg9wL_ZbVCKT.png" type="image/png"><source srcset="https://ishadeed.com/_astro/min-target-size-4.mBikg9wL_Z1jVc6F.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/min-target-size-4.mBikg9wL_ZbVCKT.png" alt="" loading="lazy" decoding="async"> </source></source></picture> <figcaption><p>A side view of how my thumb covers 2-3 icons at a time.</p></figcaption></figure>
<p>My recommendation is to have a target with a minimum size of 44 by 44 pixels, at least. This is per the WCAG 2.5.5.</p>
<p>As per <a href="https://developers.google.com/cars/design/android-auto/design-system/sizing">Google Design for Driving</a> guidelines, the minimum touch target size is 76dp * 76dp.</p>
<p>While driving a car, you have a very short time to tap something, so it should be large enough. This feels related to Fitt’s Law (below), where the size of a target should be larger if the time to tap is short.</p>
<figure><picture> <source srcset="https://ishadeed.com/_astro/target-size-driving.4vvHpECm_1md4rh.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-size-driving.4vvHpECm_Z2ou8p8.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-size-driving.4vvHpECm_1md4rh.png" alt="" loading="lazy" decoding="async"> </source></source></picture> <figcaption><p>Android Auto UI that shows the target sizes.
<a href="https://www.figma.com/community/file/966820396083110735">Source</a></p></figcaption></figure>
<p>It’s beneficial to have specific rules, but it doesn’t mean they should be followed blindly. It’s crucial to consistently test the UI targets.</p>
<h3 id="applying-fitts-law">Applying Fitt’s Law</h3>
<p><astro-island uid="175nIu" prefix="r72" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{&quot;content&quot;:[0,&quot;It's a principle that says it's faster to click or touch bigger objects that are closer to you.&quot;]}" ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>It's a principle that says it's faster to click or touch bigger objects that are closer to you.</p></div></blockquote></astro-island></p>
<p>From a UI perspective, that means the bigger a call to action, the better for the user.</p>
<p>In the following example, notice how much the distance between the input method and the button.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/fitt-law-1.E_ddOyn4_JNlX3.png" type="image/png"><source srcset="https://ishadeed.com/_astro/fitt-law-1.E_ddOyn4_ZtLPYr.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/fitt-law-1.E_ddOyn4_JNlX3.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>With a larger button, the distance and time required for both the initial and final movements decrease.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/fitt-law-2.JYstwono_Z2olxMJ.png" type="image/png"><source srcset="https://ishadeed.com/_astro/fitt-law-2.JYstwono_1rfn3H.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/fitt-law-2.JYstwono_Z2olxMJ.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>What are the initial and final movements? As per <a href="https://en.wikipedia.org/wiki/Fitts%27s_law">Wikipedia</a>:</p>
<ul>
<li><strong>Initial movement</strong>: a fast but imprecise movement towards the target.</li>
<li><strong>Final movement</strong>: slower but more precise movement to tap or click the target.</li>
</ul>
<p>We can compare this to a real-life case. Imagine a physical keyboard. The
buttons that need to be used the most (Enter, Esc, Space, Shift) are larger
and closer to the user’s fingers than the rest of the buttons.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/fitt-law-3.tRicewH2_rqW8J.png" type="image/png"><source srcset="https://ishadeed.com/_astro/fitt-law-3.tRicewH2_ZM9fNK.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/fitt-law-3.tRicewH2_rqW8J.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Or even better, we can see that in action. In the previous section, I mentioned
how the target sizes should be larger for car UIs, and how how that is
somehow related to Fitt’s law.</p>
<p><astro-island uid="1UNHK0" prefix="r4" component-url="https://ishadeed.com/_astro/CarUI.BOI0hj1P.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,"Toggle between the options and see how the target size changes."]}' ssr="" client="visible" opts='{"name":"CarUI","value":true}' await-children=""><div><p>Toggle between the options and see how the target size changes.</p></div></astro-island></p>
<h3 id="spacing-around-the-targets">Spacing around the targets</h3>
<p><astro-island uid="1pdmST" prefix="r73" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Make sure that the spacing between each target is enough and prevent clicking or tapping a target by mistake."]}' ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>Make sure that the spacing between each target is enough and prevent clicking or tapping a target by mistake.</p></div></blockquote></astro-island></p>
<p>Consider the following example. We have three buttons, and the target size for each of them is 44 by 44 pixels.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-spacing-1.I1X5nan6_1SRiX9.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-spacing-1.I1X5nan6_RBcdo.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-spacing-1.I1X5nan6_1SRiX9.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>When the user tries to tap an action on mobile, the average thumb size
is large, thus might result in tapping an action item by mistake.</p>
<p>In the following figure, the circle represents a thumb. Notice how it touches two target items.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-spacing-2.kfqtbf8K_w16Iz.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-spacing-2.kfqtbf8K_Zuf01b.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-spacing-2.kfqtbf8K_w16Iz.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>According to a <a href="http://touchlab.mit.edu/publications/2003_009.pdf">study</a>
by the MIT Touch Lab of human fingertips, the average size of the index
finger is 1.6 to 2 cm, which translates to a width of 45 - 57 pixels.</p>
<p>To apply that, we need to increase the spacing between the items.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-spacing-3.7pTWY6zY_l5OPl.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-spacing-3.7pTWY6zY_ZFagTp.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-spacing-3.7pTWY6zY_l5OPl.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Now it’s less likely that the user will tap a target by mistake.</p>
<h3 id="visual-target-feedback">Visual target feedback</h3>
<p><astro-island uid="2bhe3X" prefix="r74" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"When hovering over or tapping a target, displaying visual feedback is beneficial, as it enhances the time to action."]}' ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>When hovering over or tapping a target, displaying visual feedback is beneficial, as it enhances the time to action.</p></div></blockquote></astro-island></p>
<p>This is useful for elements without clear boundaries. For example, a link or an icon-only button.</p>
<p>Try to hover over one of the buttons below.</p>
<p><astro-island uid="1Q9JtP" prefix="r75" component-url="https://ishadeed.com/_astro/VisualFeedback.KoO0MgZL.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"VisualFeedback","value":true}' await-children=""></astro-island></p>
<p>Adding visual feedback sets expectations for the user. It’s like a hint that lets them know the target area boundaries.</p>
<p>Here is another example of a menu.</p>
<p><astro-island uid="13Y4L0" prefix="r76" component-url="https://ishadeed.com/_astro/VisualFeedback.KoO0MgZL.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"VisualFeedback","value":true}' await-children=""></astro-island></p>
<h3 id="multi-input-sources">Multi-input sources</h3>
<p><astro-island uid="1l9apY" prefix="r77" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"A target size that works well with a mouse might be hard to tap on mobile. Make sure the target size is big enough."]}' ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>A target size that works well with a mouse might be hard to tap on mobile. Make sure the target size is big enough.</p></div></blockquote></astro-island></p>
<p>An example of that would be to compare how clicking a target with a mouse versus tapping with a finger.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-rwd-1.amrPG9os_1IvNtk.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-rwd-1.amrPG9os_KBtxm.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-rwd-1.amrPG9os_1IvNtk.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In this example, the radio button is small compared to the user’s finger,
but it’s almost the same size as the computer pointer. The idea here is
to make sure a target size works with multiple input sources.</p>
<h2 id="what-to-consider">What to consider</h2>
<h3 id="touch-size-differs-based-on-finger-size">Touch size differs based on finger size</h3>
<p>There is a common term which is ”<strong>fat finger</strong> problem”. It means that the user’s finger is too big to accurately tap on the touch targers. In this case, I can blame the small touch targets only.</p>
<p>To demonstrate that, I made the following interactive playground that helps in visualizing your finger touch size.</p>
<p><strong>Please note that the following demo works on mobile only. Not on mobile, no problem! See the video tab.</strong></p>
<p><astro-island uid="1Wgx9I" prefix="r5" component-url="https://ishadeed.com/_astro/TouchTest.EuL0qnw3.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"TouchTest$1","value":true}' await-children=""><div><p class="_tabsWrapper_3fegj_69"><button class="_button_3fegj_74 _isActive_3fegj_87">Demo</button><button class="_button_3fegj_74">Video</button></p><div id="touchTest" class="example-wrapper center _touchTestwrapper_3fegj_1"><div><div><p>Try to tap any of the following menu items.</p><p class="_box_3fegj_62"></p></div><p>This is an estimation only. It will differ from a device to another.</p></div></div><p><video poster="https://ishadeed.com/assets/target-size/videos/touch-test.png" src="https://ishadeed.com/assets/target-size/videos/touch-test.mp4" controls="" controlslist="nodownload"></video></p></div></astro-island></p>
<p>I used the snippet shown on the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Touch/radiusX">MDN website</a>. While this might not be perfect, at least it’s useful to demonstrate the concept.</p>
<p>We need to get the <code>radiusX</code> and <code>radiusY</code>, then multiply them by 2.</p>
<pre class="language-js"><code is:raw="" class="language-js">box<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">"touchstart"</span><span class="token punctuation">,</span> getTouchSize<span class="token punctuation">)</span>
​
<span class="token keyword">function</span> <span class="token function">getTouchSize</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> touch <span class="token operator">=</span> e<span class="token punctuation">.</span>changedTouches<span class="token punctuation">.</span><span class="token function">item</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
  elm<span class="token punctuation">.</span>style<span class="token punctuation">.</span>width <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>touch<span class="token punctuation">.</span>radiusX <span class="token operator">*</span> <span class="token number">2</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">px</span><span class="token template-punctuation string">`</span></span>
  elm<span class="token punctuation">.</span>style<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>touch<span class="token punctuation">.</span>radiusY <span class="token operator">*</span> <span class="token number">2</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">px</span><span class="token template-punctuation string">`</span></span>
<span class="token punctuation">}</span></code></pre>
<p>We can take this further and show what the target size looks like on your phone. Once you tap on the cross area, the UI will get your finger size and append it to the question.</p>
<p>Notice how the target size is compared to the radio button.</p>
<p><astro-island uid="Z1d9DfT" prefix="r6" component-url="https://ishadeed.com/_astro/TouchTestDemo.63BHA1EC.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"TouchTest","value":true}' await-children=""><div><p class="_tabsWrapper_1yyl2_82"><button class="_button_1yyl2_87 _isActive_1yyl2_100">Demo</button><button class="_button_1yyl2_87">Video</button></p><div class="demo-content"><div><div id="touchTesDemo" class="example-wrapper center _touchTestwrapperDemo_1yyl2_1"><div><div class="_touchResult_1yyl2_21"><p>W: 32, H: 32</p><p class="_cross_1yyl2_33"></p><p>👋 Tap here to get your finger size</p></div></div></div></div><p><video poster="https://ishadeed.com/assets/target-size/videos/touch-demo.png" src="https://ishadeed.com/assets/target-size/videos/touch-demo.mp4" controls="" controlslist="nodownload"></video></p></div></div></astro-island></p>
<p>Interesting, right?</p>
<h3 id="touch-size-differs-based-on-the-touch-angle">Touch size differs based on the touch angle</h3>
<p>It’s important to keep in mind that the user might use the touch in two different ways:</p>
<ul>
<li>Touch with fingertip</li>
<li>Touch with the finger pad</li>
</ul>
<h4 id="fingertip">Fingertip</h4>
<p>When using the fingertip, the finger is titled with an angle.</p>
<h4 id="finger-pad">Finger pad</h4>
<p>When using the finger pad, the finger isn’t tilted, but this can increase the issue of the target being hidden while the user’s finger is above it.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/finger-tip-1.Dxt6CXvq_Z187QcV.png" type="image/png"><source srcset="https://ishadeed.com/_astro/finger-tip-1.Dxt6CXvq_Z262b8T.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/finger-tip-1.Dxt6CXvq_Z187QcV.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In the following illustration, notice how the search icon is still visible
when the user is using their fingertip.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/finger-tip-2.mERclBS9_2hs6Rl.png" type="image/png"><source srcset="https://ishadeed.com/_astro/finger-tip-2.mERclBS9_1jxLVn.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/finger-tip-2.mERclBS9_2hs6Rl.png" alt="" loading="lazy" decoding="async"> </source></source></picture>
<astro-island uid="2fkQFq" prefix="r78" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{&quot;content&quot;:[0,&quot;Small touch targets make users work harder because they require more accuracy to hit. Users need to reorient their finger, from finger pad to fingertip, to hit the target with clear visual feedback. Using the finger pad would cover the entire target, making it impossible for users to see the target they're trying to hit.&quot;],&quot;source&quot;:[0,&quot;UX movement&quot;],&quot;link&quot;:[0,&quot;https://uxmovement.com/mobile/finger-friendly-design-ideal-mobile-touch-target-sizes/&quot;]}" ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>Small touch targets make users work harder because they require more accuracy to hit. Users need to reorient their finger, from finger pad to fingertip, to hit the target with clear visual feedback. Using the finger pad would cover the entire target, making it impossible for users to see the target they're trying to hit.</p><p>- <a href="https://uxmovement.com/mobile/finger-friendly-design-ideal-mobile-touch-target-sizes/">UX movement</a></p></div></blockquote></astro-island></p>
<p>The touch with the finger pad is often at an angle, which makes it shape like an oval. The touch with the finger pad is larger but often hides the target you’re tapping.</p>
<p>Here is a figure that shows a comparison.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/finger-tip-3.xY66qdf2_Z12Ps9n.png" type="image/png"><source srcset="https://ishadeed.com/_astro/finger-tip-3.xY66qdf2_ZsKIbK.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/finger-tip-3.xY66qdf2_Z12Ps9n.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h3 id="small-touch-sizes-are-hard-to-use-in-shaking-environments">Small touch sizes are hard to use in shaking environments</h3>
<p>When a user is trying to tap a small target size, it isn’t that they are sitting in a perfect environment and just staring at the screen. People are busy and they want to achieve their goals fast.</p>
<p>In the following interactive demo, I tried to simulate how a shaking environment makes using a small target much harder.</p>
<ul>
<li>Turn on the “Stimulate shaking” toggle.</li>
<li>Try to select one of the icons.</li>
</ul>
<p><astro-island uid="ZHilQs" prefix="r7" component-url="https://ishadeed.com/_astro/ShakingPhone.9bY4X2KJ.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ShakingPhone$1","value":true}' await-children=""><div><div class="shaking-test"><p><strong>⚠️ Motion warning:</strong> this example may affect people with visual sensitivities.</p><div class="box"><div class="content"><h3>Try to tap on one of the navigation items</h3><p>This is how it feels to navigate small target areas with a shaking device. Not cool, right?</p></div><p class="touch"></p></div><div class="info"><p>A simulation of how a mobile can shake in situation like being in public transportation, or driving on bumpy roads.</p></div></div></div></astro-island></p>
<p>It’s annoying, isn’t it? I hope the demo gave you the vibes of when you tap something by mistake.</p>
<h3 id="using-touch-with-the-fingers-covered">Using touch with the fingers covered</h3>
<p>A user might wear a glove in the winter and is trying to tab on a UI. This is a common and expected thing. In this case, if the target sizes are small and close to each other, the user will find a hard time trying to tap on an item.</p>
<p>Here is a mocked comparison between the natural touch and the touch with gloves. Notice that it got slightly bigger with gloves. This is important to take into consideration.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/fingers-covered-1.gzu_BN_n_2qOi6k.png" type="image/png"><source srcset="https://ishadeed.com/_astro/fingers-covered-1.gzu_BN_n_1iOIKy.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/fingers-covered-1.gzu_BN_n_2qOi6k.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p><strong>In the following example</strong>, try to switch the context between “Natural
touch” or “Touch with gloves” and notice how it becomes harder to select
a target.</p>
<p>This is similar to what a user with gloves on experience.</p>
<p><astro-island uid="1OXYxj" prefix="r8" component-url="https://ishadeed.com/_astro/HandGloves.61JqWuZ9.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ShakingPhone","value":true}' await-children=""><div class="hand-gloves"><div class="box"><div class="content"><h3>Try to tap on one of the navigation items</h3><p>This is a demo that shows the size of your finger when wearing a glove.</p></div><p class="touch"></p></div><div class="info"><p>The touch size interferes with the two actions.</p></div></div></astro-island></p>
<h3 id="spacing">Spacing</h3>
<p>There are exceptions for a target size like inline elements or when there is a small target but it has a large spacing around it.</p>
<p>According to the <a href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html#dfn-pointer-input">WCAG 2.58</a>:</p>
<p><astro-island uid="Z1728rp" prefix="r79" component-url="https://ishadeed.com/_astro/Quote.7SNL3D4W.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Undersized targets (those less than 24 by 24 CSS pixels) are positioned so that if a 24 CSS pixel diameter circle is centered on the bounding box of each, the circles do not intersect another target or the circle for another undersized target;"]}' ssr="" client="visible" opts='{"name":"Quote","value":true}' await-children=""><blockquote class="_quote_1a1hc_1"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 32 33"><g><rect y="0.527" fill="#D9BAF7" rx="16"></rect><g stroke="#7D45A7" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M16.25 9.527c-3.5 0-5.25 2.75-5.25 5.25 0 4 3 4.5 3 6v2.25a1 1 0 001 1h2.5a1 1 0 001-1v-2.25c0-1.5 3-2 3-6 0-2.5-1.75-5.25-5.25-5.25z"></path><path d="M14.25 21.527h4"></path></g></g></svg><div><p>Undersized targets (those less than 24 by 24 CSS pixels) are positioned so that if a 24 CSS pixel diameter circle is centered on the bounding box of each, the circles do not intersect another target or the circle for another undersized target;</p></div></blockquote></astro-island></p>
<h4 id="links">Links</h4>
<p>For example, a link that is part of a paragraph is excluded from the target size recommendations.</p>
<p>See the following example.</p>
<p><astro-island uid="Z2heG9M" prefix="r80" component-url="https://ishadeed.com/_astro/Links.o41XTd_H.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"Links","value":true}' await-children=""><div class="_links_65166_1 example-wrapper center"><p>As per <a href="#">this article</a>, it's recommended to stay calm at all times.</p></div></astro-island></p>
<p>The target size for the link is the same as the line height. No need to make it larger.</p>
<p>However, that doesn’t mean we shouldn’t care about links. It’s equally important to a regular target area.</p>
<p><astro-island uid="171Aws" prefix="r81" component-url="https://ishadeed.com/_astro/Links.o41XTd_H.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"Links","value":true}' await-children=""><div class="_links_65166_1 example-wrapper center"><div><p class="_desc_65166_5"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 17 17"><g clip-path="url(#clip0_2216_428)"><path fill="#E73C65" d="M8.5.928C4.31.928.9 4.336.9 8.528s3.409 7.6 7.6 7.6c4.192 0 7.6-3.408 7.6-7.6s-3.408-7.6-7.6-7.6zm2.512 9.103a.705.705 0 01-.496 1.2.664.664 0 01-.496-.208L8.5 9.52l-1.503 1.503a.692.692 0 01-.497.208.664.664 0 01-.496-.208.705.705 0 010-.992l1.504-1.503-1.504-1.504a.705.705 0 010-.992.705.705 0 01.992 0L8.5 7.536l1.503-1.504a.705.705 0 01.992 0 .705.705 0 010 .992L9.492 8.528l1.52 1.503z"></path></g><defs><clippath id="clip0_2216_428"><path fill="#fff" d="M0 0H16V16H0z" transform="translate(.5 .527)"></path></clippath></defs></svg>Don’t do this. The line height is too small.</p><p>As per this article, it’s recommended to keep calm at all times. If you need help, feel free to <a href="#">get in touch</a> for an appointment.</p></div></div></astro-island></p>
<p>It can get worse if there are multiple links in the same paragraph:</p>
<p><astro-island uid="4pPB7" prefix="r82" component-url="https://ishadeed.com/_astro/Links.o41XTd_H.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"3"]}' ssr="" client="visible" opts='{"name":"Links","value":true}' await-children=""><div class="_links_65166_1 example-wrapper center"><div><p class="_desc_65166_5"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 17 17"><g clip-path="url(#clip0_2216_428)"><path fill="#E73C65" d="M8.5.928C4.31.928.9 4.336.9 8.528s3.409 7.6 7.6 7.6c4.192 0 7.6-3.408 7.6-7.6s-3.408-7.6-7.6-7.6zm2.512 9.103a.705.705 0 01-.496 1.2.664.664 0 01-.496-.208L8.5 9.52l-1.503 1.503a.692.692 0 01-.497.208.664.664 0 01-.496-.208.705.705 0 010-.992l1.504-1.503-1.504-1.504a.705.705 0 010-.992.705.705 0 01.992 0L8.5 7.536l1.503-1.504a.705.705 0 01.992 0 .705.705 0 010 .992L9.492 8.528l1.52 1.503z"></path></g><defs><clippath id="clip0_2216_428"><path fill="#fff" d="M0 0H16V16H0z" transform="translate(.5 .527)"></path></clippath></defs></svg>Don’t do this. The line height is too small.</p><p>As per this article, it’s recommended to <a href="#">keep calm</a> at all times. If you need help, feel free to <a href="#">get in touch</a> for an appointment.</p></div></div></astro-island></p>
<p>Instead, we should increase the line height in CSS:</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">p</span> <span class="token punctuation">{</span>
  <span class="token property">line-height</span><span class="token punctuation">:</span> 1.4<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="1DIU91" prefix="r83" component-url="https://ishadeed.com/_astro/Links.o41XTd_H.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"4"]}' ssr="" client="visible" opts='{"name":"Links","value":true}' await-children=""><div class="_links_65166_1 example-wrapper center"><div><p>As per this article, it’s recommended to <a href="#">keep calm</a> at all times. If you need help, feel free to <a href="#">get in touch</a> for an appointment.</p></div></div></astro-island></p>
<h4 id="more-spacing-for-small-targets">More spacing for small targets</h4>
<p>If there are multiple actions on mobile and their size is 48px or less, then it makes sense to have more spacing between them.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/small-target-spacing-1.cMIi5iEz_1xqhax.png" type="image/png"><source srcset="https://ishadeed.com/_astro/small-target-spacing-1.cMIi5iEz_2wprtu.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/small-target-spacing-1.cMIi5iEz_1xqhax.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>If the spacing is small, then the small targets will fail. Here is a figure
on how they will look like.</p>
<figure><picture> <source srcset="https://ishadeed.com/_astro/small-target-spacing-2.1zPSdkr3_3YhVL.png" type="image/png"><source srcset="https://ishadeed.com/_astro/small-target-spacing-2.1zPSdkr3_12XsfI.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/small-target-spacing-2.1zPSdkr3_3YhVL.png" alt="" loading="lazy" decoding="async"> </source></source></picture> <figcaption>❌ Small targets need more spacing</figcaption></figure>
<p>I have a real-life example that is very convincing. In Instagram, the comment’s like button is very small, but it works well because the spacing around it is large enough.</p>
<p>See the following figure:</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/small-target-spacing-3.alOpO9pm_AloCY.png" type="image/png"><source srcset="https://ishadeed.com/_astro/small-target-spacing-3.alOpO9pm_1zkyVV.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/small-target-spacing-3.alOpO9pm_AloCY.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>The target sizes are below the minimum, but they work very well because
the surrounding space is large enough.</p>
<p>See the following figure for the highlighted space. The green highlight is just the space around the target.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/small-target-spacing-4.gRQhUEl5_3GE4h.png" type="image/png"><source srcset="https://ishadeed.com/_astro/small-target-spacing-4.gRQhUEl5_12FOne.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/small-target-spacing-4.gRQhUEl5_3GE4h.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="less-spacing-for-large-targets">Less spacing for large targets</h4>
<p>In the following examples, the spacing between the targets is zero, but due to their large size, it’s fine to have less or no spacing at all.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/large-target-spacing-1.V6iUc4le_ZKHYWq.png" type="image/png"><source srcset="https://ishadeed.com/_astro/large-target-spacing-1.V6iUc4le_dgalw.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/large-target-spacing-1.V6iUc4le_ZKHYWq.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="target-size-that-grows-with-the-system-font-size">Target size that grows with the system font size</h4>
<p>I did a test on Apple iOS to see if the system icons grow when I change the font size from the accessibility settings, and it did. If the user wants a bigger font, then the target size should grow proportionally for that.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/large-target-spacing-2.iiO6ATQo_Z1Kl4JP.png" type="image/png"><source srcset="https://ishadeed.com/_astro/large-target-spacing-2.iiO6ATQo_ZLlTqS.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/large-target-spacing-2.iiO6ATQo_Z1Kl4JP.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>It’s not like we should do that for all apps, but it makes sense to think
about it.</p>
<h2 id="target-size-examples">Target size examples</h2>
<p>As a front-end developer, it’s important to know the techniques to build an accessible target size.</p>
<p>Let’s explore that in the following examples.</p>
<h3 id="website-navigation">Website navigation</h3>
<p>In this example, try to hover over a navigation item.</p>
<p><astro-island uid="EoInw" prefix="r9" component-url="https://ishadeed.com/_astro/WebsiteNav.YZ97Zit8.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"WebsiteNav","value":true}' await-children=""><div><p>Try to hover on an item ☝️</p><p></p></div></astro-island></p>
<p>Notice how the clickable area is small? That happened because that spacing is added to the outer container, not the link itself.</p>
<p><astro-island uid="40L80" prefix="r10" component-url="https://ishadeed.com/_astro/WebsiteNav.YZ97Zit8.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Try to toggle the outline spacing, target area, or both!"],"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"WebsiteNav","value":true}' await-children=""><div><p>Try to toggle the outline spacing, target area, or both!</p></div></astro-island></p>
<p>Let’s take a look at the CSS.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 1.5rem<span class="token punctuation">;</span>
  <span class="token property">padding-top</span><span class="token punctuation">:</span> 0.75rem<span class="token punctuation">;</span>
  <span class="token property">padding-bottom</span><span class="token punctuation">:</span> 0.75rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Notice that there is a:</p>
<ul>
<li>Gap between each nav item</li>
<li>Vertical padding on the parent</li>
</ul>
<p>This isn’t good. We need to remove both and use padding on the individual navigation item.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .nav__item a</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 0.75rem 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="rWMHG" prefix="r11" component-url="https://ishadeed.com/_astro/WebsiteNav.YZ97Zit8.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Better now."],"variation":[0,"3"]}' ssr="" client="visible" opts='{"name":"WebsiteNav","value":true}' await-children=""></astro-island></p>
<p>Hover over a navigation item to see the difference.</p>
<h3 id="dropdown-toggle">Dropdown toggle</h3>
<p>In this example, the target size is only on the label, not the whole menu container.</p>
<p><astro-island uid="pgavt" prefix="r12" component-url="https://ishadeed.com/_astro/DropdownToggle.v46l7Fin.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Try to hover on a menu ☝️"],"helper":[0,true],"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"DropdownToggle","value":true}' await-children=""><div><div class="example-wrapper center"><p class="_dropdown_ixlv5_1"><label for=":r12R0:">Category</label><select name="" id=":r12R0:"><option value="">Web development</option><option value="">Web design</option><option value="">CSS</option></select></p></div><p>Try to hover on a menu ☝️</p></div></astro-island></p>
<p>The target area is only on the text, and it’s trimmed. To fix that, we need to expand the target area of the whole container.</p>
<p>I added the padding to the <code>&lt;select&gt;</code> menu itself, instead of the outer wrapper.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.dropdown__content</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 1.5rem 0.5rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Here is the <strong>enhanced</strong> example.</p>
<p><astro-island uid="zgecT" prefix="r13" component-url="https://ishadeed.com/_astro/DropdownToggle.v46l7Fin.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"content":[0,"Better, right?"],"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"DropdownToggle","value":true}' await-children=""><div><div class="example-wrapper center"><p class="_dropdown_ixlv5_1 _dropdownEnhanced_ixlv5_39"><label for=":r13R0:">Category</label><select name="" id=":r13R0:"><option value="">Web development</option><option value="">Web design</option><option value="">CSS</option></select></p></div><p>Better, right?</p></div></astro-island></p>
<p>It’s just about adding the padding to the appropriate HTML element.</p>
<h3 id="navigation-bar">Navigation bar</h3>
<p>Here is an example where we have a bottom navigation for a website. Try to hover over an item to see its boundaries.</p>
<p><astro-island uid="Zs8KPB" prefix="r84" component-url="https://ishadeed.com/_astro/BottomNavigation.wKeBXBWw.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true]}' ssr="" client="visible" opts='{"name":"BottomNavigation","value":true}' await-children=""><div><div class="example-wrapper center"><div class="_box_myits_1"><div class="_content_myits_89"><h3>Try to tap on one of the navigation items</h3><p>This is a demo that shows the size of your finger when wearing a glove.</p></div></div></div><p>Try to hover on an item ☝️</p><p></p></div></astro-island></p>
<p>Notice how the boundaries are small, compared to the space around the item itself.</p>
<p>We can fix that in CSS by forcing each navigation item to fill the available width. To do that, we need to apply <code>flex: 1</code> on the navigation item.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .nav__item</span> <span class="token punctuation">{</span>
  <span class="token property">flex</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z2ww7XC" prefix="r85" component-url="https://ishadeed.com/_astro/BottomNavigation.wKeBXBWw.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"BottomNavigation","value":true}' await-children=""><div><div class="example-wrapper center"><div class="_box_myits_1"><div class="_content_myits_89"><h3>Try to tap on one of the navigation items</h3><p>This is a demo that shows the size of your finger when wearing a glove.</p></div></div></div><p></p></div></astro-island></p>
<p>Much better now.</p>
<h3 id="icon-buttons">Icon buttons</h3>
<p>Another example where having a large target size is important is an icon button.</p>
<p>As a designer, you might need to use an icon only due to cases like not having enough space, for example, or if the icon is too common.</p>
<p>In the following demo, try to hover over one of the icons and notice how the thumb size overlaps between them. For larger thumbs, the probability of tapping by mistake is high.</p>
<p><astro-island uid="1FAgGj" prefix="r14" component-url="https://ishadeed.com/_astro/IconButtons.qKnNiHGe.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"IconButtons","value":true}' await-children=""></astro-island></p>
<p>To fix that, we need to do the following:</p>
<ul>
<li>Increase the spacing between the two buttons</li>
<li>Increase the target size area</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.header-actions</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .action__item</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z6kBwC" prefix="r15" component-url="https://ishadeed.com/_astro/IconButtons.qKnNiHGe.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"IconButtons","value":true}' await-children=""></astro-island></p>
<h3 id="safe-triangle-target-areas">Safe triangle target areas</h3>
<p>It’s common to find multi-level menus on large websites like e-commerce apps, for example. Oftentimes, I find it hard to select an item from a multi-level menu, because the target area for the secondary menu is small.</p>
<p>Let’s take the following example.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-1.gWdKi3yE_Z18UI7y.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-1.gWdKi3yE_2gbY1b.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-1.gWdKi3yE_Z18UI7y.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Try to hover over any of the menu items with an arrow. Notice how the secondary
menu appears only when you hover on its parent. If the mouse goes out of
that area, the secondary menu will disappear.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-2.83z9uuii_ZXtSqJ.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-2.83z9uuii_2qCNH0.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-2.83z9uuii_ZXtSqJ.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>To fix that, we need to follow the safe triangle method that was seen <a href="https://height.app/blog/guide-to-build-context-menus">first
on Amazon</a>.</p>
<p>The idea is that instead of the highlighted target area, there will be a triangle attached to the sub-menu that will create a larger target size.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-3.KwHHoU15_1ATFa3.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-3.KwHHoU15_Z49Kv9.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-3.KwHHoU15_1ATFa3.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>How does that work in code? Let’s break this down.</p>
<ul>
<li>The submenu has a rectangle that is attached to it.</li>
<li>That rectangle has clip-path, and the visible part of it is the triangle.</li>
<li>Any area outside the triangle won’t receive pointer events due to its being clipped.</li>
</ul>
<h4 id="the-problem">The problem</h4>
<p>We will use <code>clip-path</code> to create a triangle from the safe area element. That means we will need <strong>three points</strong>.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-4.VxSWoCWW_nAveQ.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-4.VxSWoCWW_Z1hsUql.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-4.VxSWoCWW_nAveQ.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p><strong>The point that is close to the hand cursor is the dynamic one</strong> that
we need to get. The other two points are static.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.safeAreaElement</span> <span class="token punctuation">{</span>
  <span class="token property">clip-path</span><span class="token punctuation">:</span> <span class="token function">polygon</span><span class="token punctuation">(</span><span class="token function">var</span><span class="token punctuation">(</span>--safe-start<span class="token punctuation">)</span><span class="token punctuation">,</span> 100% 100%<span class="token punctuation">,</span> 100% 0<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h4 id="the-solution">The solution</h4>
<p>The markup for this UI is as follows. We have a list item that contains a secondary menu. I wrote this in React, that’s why there are <code>className</code> and <code>ref={}</code>.</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hasSub<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  Sort by
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>subMenu<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>Default<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>Name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>Type<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">&gt;</span></span>Status<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>safeAreaElement<span class="token punctuation">"</span></span> <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>{submenuSafeAreaRef}<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">&gt;</span></span></code></pre>
<p>In CSS, I did the following:</p>
<ul>
<li>Added <code>position: absolute</code> to position the secondary menu to the right of its parent <code>&lt;li&gt;</code> item.</li>
<li>Positioned the safe area element on the opposite side of the secondary menu.</li>
<li>Added a default value of <code>clip-path</code>.</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.hasSub</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .subMenu</span> <span class="token punctuation">{</span>
  <span class="token property">--safe-start</span><span class="token punctuation">:</span> 0% 0%<span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">left</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>100% - 8px<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">top</span><span class="token punctuation">:</span> -2px<span class="token punctuation">;</span>
  <span class="token property">z-index</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .safeAreaElement</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">top</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">bottom</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">right</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>100% - 8px<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">clip-path</span><span class="token punctuation">:</span> <span class="token function">polygon</span><span class="token punctuation">(</span><span class="token function">var</span><span class="token punctuation">(</span>--safe-start<span class="token punctuation">)</span><span class="token punctuation">,</span> 100% 100%<span class="token punctuation">,</span> 100% 0<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>To make sure we’re on the same page, here is the annotation of the HTML parts.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-5.ybtFLCHC_ZMUuo2.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-5.ybtFLCHC_Z2sYV4e.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-5.ybtFLCHC_ZMUuo2.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Also, here is what the default clipped area looks like.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-6.I2btTKYg_1DzkWG.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-6.I2btTKYg_Z1u5Hv.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-6.I2btTKYg_1DzkWG.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="the-safe-triangle-area">The safe triangle area</h4>
<p>The safe area is positioned relative to the secondary menu. It’s like an extension to the menu.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-7.2qp5GWHQ_Z13SblS.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-7.2qp5GWHQ_2levLQ.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-7.2qp5GWHQ_Z13SblS.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="get-the-mouse-x--y-coordinates">Get the mouse X &amp; Y coordinates</h4>
<p>When the user hovers in the safe area, we need to get the mouse X &amp; Y coordinates. In Javascript, we get the X &amp; Y values for the whole page, so we need to scope them for the safe area element only.</p>
<pre class="language-js"><code is:raw="" class="language-js">


<span class="token keyword">const</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">width</span><span class="token operator">:</span> menuItemWidth<span class="token punctuation">,</span>
  <span class="token literal-property property">height</span><span class="token operator">:</span> menuItemHeight<span class="token punctuation">,</span>
<span class="token punctuation">}</span> <span class="token operator">=</span> hasSubRef<span class="token punctuation">.</span>current<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
​

<span class="token keyword">const</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">left</span><span class="token operator">:</span> safeAreaLeftPos<span class="token punctuation">,</span>
  <span class="token literal-property property">top</span><span class="token operator">:</span> safeAreaTopPos<span class="token punctuation">,</span>
  <span class="token literal-property property">width</span><span class="token operator">:</span> safeAreaWidth<span class="token punctuation">,</span>
  <span class="token literal-property property">height</span><span class="token operator">:</span> safeAreaHeight<span class="token punctuation">,</span>
<span class="token punctuation">}</span> <span class="token operator">=</span> submenuSafeAreaRef<span class="token punctuation">.</span>current<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
​

<span class="token keyword">const</span> localX <span class="token operator">=</span> mouseX <span class="token operator">-</span> safeAreaLeftPos
<span class="token keyword">const</span> localY <span class="token operator">=</span> mouseY <span class="token operator">-</span> safeAreaTopPos</code></pre>
<p>In the code, we got:</p>
<ul>
<li>Width and height of the <code>&lt;li&gt;</code></li>
<li>Left and top position of the safe area relative to the page</li>
<li>The mouse X and Y then subtract the safe area left and top from each, respectively.</li>
</ul>
<p>This will give us the local coordinates scoped to the safe area.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-8.vEvvLEEa_17eNqj.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-8.vEvvLEEa_ZxOCeS.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-8.vEvvLEEa_17eNqj.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Given the data we have now, we need to do a few more steps to get the X
and Y percentage values to use in the <code>clip-path</code>.</p>
<ul>
<li>Any X value that is larger than the safe area element width isn’t needed</li>
<li>Any Y value below the main <code>&lt;li&gt;</code> isn’t needed (the black line)</li>
<li>Convert those X and Y values into percentages by dividing them with the width and height of the safe area element, respectively.</li>
</ul>
<p><picture> <source srcset="https://ishadeed.com/_astro/safe-triangle-9.bgggmP8x_201eKf.png" type="image/png"><source srcset="https://ishadeed.com/_astro/safe-triangle-9.bgggmP8x_jVN53.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/safe-triangle-9.bgggmP8x_201eKf.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Take a look at the Javascript.</p>
<pre class="language-js"><code is:raw="" class="language-js">
<span class="token keyword">if</span> <span class="token punctuation">(</span>
  localX <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span>
  localX <span class="token operator">&lt;</span> menuItemWidth <span class="token operator">&amp;&amp;</span>
  localY <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span>
  localY <span class="token operator">&lt;</span> menuItemHeight
<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> percentageX <span class="token operator">=</span> <span class="token punctuation">(</span>localX <span class="token operator">/</span> safeAreaWidth<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">100</span><span class="token punctuation">;</span>
  <span class="token keyword">const</span> percentageY <span class="token operator">=</span> <span class="token punctuation">(</span>localY <span class="token operator">/</span> safeAreaHeight<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">100</span><span class="token punctuation">;</span>
​
  submenuRef<span class="token punctuation">.</span>current<span class="token punctuation">.</span>style<span class="token punctuation">.</span><span class="token function">setProperty</span><span class="token punctuation">(</span>
    <span class="token string">"--safe-start"</span><span class="token punctuation">,</span>
    <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>percentageX<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">% </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>percentageY<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">%</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>The magic here happens because <code>clip-path</code> disables pointer events for clipped areas. When we hover under the menu, it disappears as expected.</p>
<p>Explore the interactive demo below and try to move the dynamic path point.</p>
<p><astro-island uid="1pnaJG" prefix="r16" component-url="https://ishadeed.com/_astro/SafeTrianglePlay.JCL8WTQn.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"SafeTrianglePlay","value":true}' await-children=""><div><p class="_tabsWrapper_14lhn_134"><button class="_button_14lhn_139 _isActive_14lhn_152">Demo</button><button class="_button_14lhn_139">Video</button></p><div><div><div class="_safeTestPlay_14lhn_1"><ul><li>New project</li><li class="has-sub">Change workflow<span>➡️</span></li><li>Sort by</li><li>Filter by</li><li>Another item</li></ul><p class="_pathResult_14lhn_123">clip-path: polygon(<code>0% 0%</code>, <code>100% 100%</code>,<code>100% 0</code>);</p></div></div><p><video poster="https://ishadeed.com/assets/target-size/videos/safe-tri-1.png" src="https://ishadeed.com/assets/target-size/videos/safe-tri-1.mp4" controls="" controlslist="nodownload"></video></p></div></div></astro-island></p>
<p>Let’s explore a demo that uses the safe triangle method. First, try to hover with the default state, then change it to the safe area.</p>
<p><astro-island uid="1YW1aH" prefix="r17" component-url="https://ishadeed.com/_astro/SafeTriangle.nCpnxMOa.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"name":[0,"wrapper 2"]}' ssr="" client="visible" opts='{"name":"SafeTriangle","value":true}' await-children=""><div><p class="_tabsWrapper_18mju_113"><button class="_button_18mju_118 _isActive_18mju_131">Demo</button><button class="_button_18mju_118">Video</button></p><div><div><div class="_safeTest_18mju_1"><ul><li>New project</li><li class="_hasSub_18mju_94 _hasSubActive_18mju_97">Change workflow<span>➡️</span></li><li>Sort by</li><li>Filter by</li><li>Another item</li></ul></div></div><p><video poster="https://ishadeed.com/assets/target-size/videos/safe-tri-2.png" src="https://ishadeed.com/assets/target-size/videos/safe-tri-2.mp4" controls="" controlslist="nodownload"></video></p></div></div></astro-island></p>
<h3 id="mobile-search">Mobile search</h3>
<p>While researching, I found an interesting target size issue in a couple of websites. When the search is active, there are no clear boundaries for it. That causes the user to guess where to tab.</p>
<p>In the following example, the search is shown once the mobile menu is toggled. However, it’s not clear where the boundaries of the search are.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/mobile-search-1.lhfbhihy_d0grH.png" type="image/png"><source srcset="https://ishadeed.com/_astro/mobile-search-1.lhfbhihy_Z1s4adu.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/mobile-search-1.lhfbhihy_d0grH.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>It’s not a good idea to let the user “guess” where the target area is.
In this design, here is a comparison <strong>between my expectation and the actual
target size</strong>.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/mobile-search-2.6fdQVi3Q_1aSf9Q.png" type="image/png"><source srcset="https://ishadeed.com/_astro/mobile-search-2.6fdQVi3Q_Zubbvl.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/mobile-search-2.6fdQVi3Q_1aSf9Q.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>See the following demo. It’s confusing.</p>
<p><astro-island uid="rTo2R" prefix="r18" component-url="https://ishadeed.com/_astro/MobileSearch.ntbnwgyB.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"content":[0,"Toggle the checkbox and see how the search makes you think that it spans to the far right."]}' ssr="" client="visible" opts='{"name":"MobileSearch","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_hbbaq_1"><p class="checkbox"><input id=":r18R5:" type="checkbox" class="sr-only _input_3qp17_1" checked><label class="_label_3qp17_16" for=":r18R5:">Toggle highlight</label></p><div class="_page_hbbaq_7 false"><div><p>Random title</p><p> This is a sample text. CSS is awesome.</p></div></div></div><p>Toggle the checkbox and see how the search makes you think that it spans to the far right.</p></div></astro-island></p>
<p>To solve that, we need to expand the target area and make it fill the rest of the space.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.search-form</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">top</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">bottom</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">right</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.search-form input</span> <span class="token punctuation">{</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> 100%<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="ZwgKg2" prefix="r19" component-url="https://ishadeed.com/_astro/MobileSearch.ntbnwgyB.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"content":[0,"The search is positioned absolutely to the header with a limited width."],"variation":[0,"enhanced"]}' ssr="" client="visible" opts='{"name":"MobileSearch","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_hbbaq_1"><p class="checkbox"><input id=":r19R5:" type="checkbox" class="sr-only _input_3qp17_1" checked><label class="_label_3qp17_16" for=":r19R5:">Toggle highlight</label></p><div class="_page_hbbaq_7 _enhanced_hbbaq_109"><div><p>Random title</p><p> This is a sample text. CSS is awesome.</p></div></div></div><p>The search is positioned absolutely to the header with a limited width.</p></div></astro-island></p>
<h3 id="active-navigation-border">Active Navigation border</h3>
<p>This is an example of a navigation where the hovered item shows a bottom border. When you see that, you assume that the whole area is clickable.</p>
<p><astro-island uid="1SK72H" prefix="r20" component-url="https://ishadeed.com/_astro/NavBottomBorder.rxRKGiDC.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"NavBottomBorder","value":true}' await-children=""><div><p>Try to hover on an item ☝️</p></div></astro-island></p>
<p>However, when you try to hover over another item, you will discover that the target area is only for the text. The border is just for visual purposes. Notice the outline around the inner item.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/nav-bottom-border.oj4vN2U9_1WWwv8.png" type="image/png"><source srcset="https://ishadeed.com/_astro/nav-bottom-border.oj4vN2U9_OWXam.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/nav-bottom-border.oj4vN2U9_1WWwv8.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>The problem is that there is horizontal padding on the <code>&lt;li&gt;</code> element, and the <code>&lt;a&gt;</code> has vertical padding only.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav-item</span> <span class="token punctuation">{</span>
  <span class="token property">padding-left</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
  <span class="token property">padding-right</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
  <span class="token property">border-bottom</span><span class="token punctuation">:</span> 4px solid transparent<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">​ .nav-item a</span> <span class="token punctuation">{</span>
  <span class="token property">padding-top</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
  <span class="token property">padding-bottom</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">​ .nav-item:hover</span> <span class="token punctuation">{</span>
  <span class="token property">border-bottom-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>To fix that, we need to add all the padding to the <code>&lt;a&gt;</code> element.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav-item</span> <span class="token punctuation">{</span>
  <span class="token property">border-bottom</span><span class="token punctuation">:</span> 4px solid transparent<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .nav-item a</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .nav-item:hover</span> <span class="token punctuation">{</span>
  <span class="token property">border-bottom-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>See it yourself in the following demo.</p>
<p><astro-island uid="EyAQd" prefix="r21" component-url="https://ishadeed.com/_astro/NavBottomBorder.rxRKGiDC.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true],"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"NavBottomBorder","value":true}' await-children=""><div><p>Try to hover on an item ☝️</p></div></astro-island></p>
<p>Much better. Now the whole link is interacive.</p>
<h3 id="player-ui">Player UI</h3>
<p>In this example, we have an audio player UI.</p>
<p>The target area is limited to the bar height only.</p>
<p>We need to fix that by extending the target size to cover at least the playhead (the little circle) height. In the following figure, the target size should be within the top and bottom red lines.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/player-ui-1.Xn-WLRZ-_1luvnd.png" type="image/png"><source srcset="https://ishadeed.com/_astro/player-ui-1.Xn-WLRZ-_Z1sv3Bu.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/player-ui-1.Xn-WLRZ-_1luvnd.png" alt="" loading="lazy" decoding="async"> </source></source></picture>A simple
thing to do is to wrap the progress in a container and extend the
height of it. That way, the progress height will remain the same, but
the clickable area will get bigger.</p>
<p>See the following HTML:</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>progress<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>progressBar<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></code></pre>
<p>Please note this HTML is just for demo purposes. There are a lot of things missing like the current progress bar value.</p>
<p>Here is the CSS:</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.progress</span> <span class="token punctuation">{</span>
  <span class="token property">flex</span><span class="token punctuation">:</span> auto<span class="token punctuation">;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> 16px<span class="token punctuation">;</span>
  <span class="token property">cursor</span><span class="token punctuation">:</span> pointer<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.progressBar</span> <span class="token punctuation">{</span>
  <span class="token property">flex</span><span class="token punctuation">:</span> auto<span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> 4px<span class="token punctuation">;</span>
  <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token function">color-mix</span><span class="token punctuation">(</span>in srgb<span class="token punctuation">,</span> #9c3ce7<span class="token punctuation">,</span> white 70%<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>It’s much better now. Try to click anywhere on the progress bar. Play with the checkbox to see the before &amp; after.</p>
<p><astro-island uid="Z1P9OSf" prefix="r22" component-url="https://ishadeed.com/_astro/PlayerUI.ZnDFoBQF.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"PlayerUI","value":true}' await-children=""></astro-island></p>
<h3 id="avoid-dead-target-areas">Avoid dead target areas</h3>
<p>A dead area is when there are multiple ways to do the same action. This can apply to a label and an icon.</p>
<p>In the following example, there are two target areas (label + icon). Between them, there is a dead target area; when clicked or tapped, the action won’t be triggered.</p>
<p><astro-island uid="ma1lq" prefix="r23" component-url="https://ishadeed.com/_astro/DeadAreas.ovHoBlHE.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,true]}' ssr="" client="visible" opts='{"name":"DeadArea","value":true}' await-children=""><div><p class="example-wrapper center _wrapper_1e53f_1"></p><p>Try to hover between the label and icon</p></div></astro-island></p>
<p>When the same target areas refer to the same action, it’s good to keep them as one target, or at least to remove the gap between them.</p>
<p>In the following demo, I just removed the gap and the issue is fixed. Unless there is no real need for that, I would recommend combining them as one action.</p>
<p><astro-island uid="Z1KwDX7" prefix="r24" component-url="https://ishadeed.com/_astro/DeadAreas.ovHoBlHE.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"enhanced"]}' ssr="" client="visible" opts='{"name":"DeadArea","value":true}' await-children=""></astro-island></p>
<h3 id="extend-target-size-with-pseudo-elements">Extend target size with pseudo-elements</h3>
<p>This is a useful technique that can increase the target size without changing the object size or padding. Here is a summary:</p>
<ul>
<li>Add a pseudo-element to the target</li>
<li>Make it size larger than the target</li>
<li>Done! 🥳</li>
</ul>
<p>In the following example, we have a simple link. Notice that the target area is highlighted.</p>
<p><astro-island uid="ZpaUjB" prefix="r25" component-url="https://ishadeed.com/_astro/ExpandTarget.UVLz_TuK.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"],"helper":[0,true]}' ssr="" client="visible" opts='{"name":"ExpandTarget","value":true}' await-children=""></astro-island></p>
<p>The hover effect is simple. Try to hover and see it.</p>
<p>When we add a pseudo-element to the link, it will take the same target area as its parent. That means we can extend the target area in a very dynamic way.</p>
<p>Try to hover over the purple square, and notice how it will trigger the hover effect on the link (its parent).</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.link</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.link a:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">left</span><span class="token punctuation">:</span> 160%<span class="token punctuation">;</span>
  <span class="token property">top</span><span class="token punctuation">:</span> -40px<span class="token punctuation">;</span>
  <span class="token property">--size</span><span class="token punctuation">:</span> 3rem<span class="token punctuation">;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> <span class="token function">var</span><span class="token punctuation">(</span>--size<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> <span class="token function">var</span><span class="token punctuation">(</span>--size<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token function">rgb</span><span class="token punctuation">(</span>194<span class="token punctuation">,</span> 170<span class="token punctuation">,</span> 216<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">border-radius</span><span class="token punctuation">:</span> 15px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="1WDIR5" prefix="r26" component-url="https://ishadeed.com/_astro/ExpandTarget.UVLz_TuK.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"content":[0,"Try to hover on the purple square. It will trigger the link."],"variation":[0,"2"],"helper":[0,true]}' ssr="" client="visible" opts='{"name":"ExpandTarget","value":true}' await-children=""><div><p>Try to hover on the purple square. It will trigger the link.</p></div></astro-island></p>
<p>Interesting, right? We can take this even further and have two pseudo-elements (<code>:before</code> and <code>:after</code>).</p>
<p>This technique can be extended to create more interesting interactions. See the following example.</p>
<p><astro-island uid="Zm2kOJ" prefix="r27" component-url="https://ishadeed.com/_astro/ExpandTargetExample.TjNPOfag.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ExpandTargetExample","value":true}' await-children=""></astro-island></p>
<p>When you hover over one of the links, its thumbnail will be triggered. Interesting, right? I used my <a href="https://debuggingcss.com/">Debugging CSS</a> book and <a href="https://defensivecss.dev/">Defensive CSS</a> as an example.</p>
<p>Here is how I did it:</p>
<ul>
<li>There is a <code>&lt;p&gt;</code> element with two links.</li>
<li>Each link has a thumb that is positioned to the right side.</li>
<li>There is a large padding on the right to accommodate the thumbs.</li>
<li>When the link is hovered, its pseudo-element will be scaled and positioned on top.</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">p a:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">--size</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
  <span class="token property">right</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> <span class="token function">var</span><span class="token punctuation">(</span>--size<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> <span class="token function">var</span><span class="token punctuation">(</span>--size<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
  <span class="token property">transition</span><span class="token punctuation">:</span> 0.3s ease-out<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">p a:hover:after</span> <span class="token punctuation">{</span>
  <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">scale</span><span class="token punctuation">(</span>1.3<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">p .debugging:after</span> <span class="token punctuation">{</span>
  <span class="token property">right</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">p .defensive:after</span> <span class="token punctuation">{</span>
  <span class="token property">right</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>With that in mind, let’s explore a few examples of using pseudo-elements to increase the target size.</p>
<h4 id="card-block-link">Card block link</h4>
<p>A common confusion that happens on the web is that you have a certain expectation for where the target area for a card is, and when you try to interact with it, it’s not as per your expectations.</p>
<p>Using this solution will make the text hard to select. Use with caution and when necessary only.</p>
<p>Consider the following example. Try to hover on the card and notice that only the title is clickable.</p>
<p><astro-island uid="alkhL" prefix="r28" component-url="https://ishadeed.com/_astro/Card.HXVEtCTV.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"Card","value":true}' await-children=""></astro-island></p>
<p>The clickable area is only in the title.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/expand-target-card-2.PTN6qcho_ZvQD7A.png" type="image/png"><source srcset="https://ishadeed.com/_astro/expand-target-card-2.PTN6qcho_ZiePUN.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/expand-target-card-2.PTN6qcho_ZvQD7A.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Here is the card’s HTML markup.</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>article</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>card<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>cookies.jpg<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h3</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>How I made cookies<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h3</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>time</span><span class="token punctuation">&gt;</span></span>2 Dec 2023<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>time</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>article</span><span class="token punctuation">&gt;</span></span></code></pre>
<p>Notice that the link is inside the <code>&lt;h3&gt;</code> element, so that’s why the target area is there only.</p>
<p>We can add a pseudo-element to the <code>&lt;a&gt;</code> element, and position it to cover the card. Try to hover over the card, now all the cards are clickable.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.card</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .card h3 a::after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z1W7Ryd" prefix="r29" component-url="https://ishadeed.com/_astro/Card.HXVEtCTV.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"Card","value":true}' await-children=""></astro-island></p>
<p>In this example, there is not much text, so the accessibility concern of text being not selectable might not be valid.</p>
<p>However, I would be careful to use this solution if there is too much text in the card (e.g.: title, description, author name.. etc).</p>

<p>Another use case for increasing the target size via pseudo-element is a mobile menu. I already showed a similar example but solved it via padding.</p>
<p>See the following demo.</p>
<p><astro-island uid="ZFnSBW" prefix="r30" component-url="https://ishadeed.com/_astro/MobileMenu.jhXdaTWo.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"MobileMenu","value":true}' await-children=""></astro-island></p>
<p>The target size is small. You need to point the cursor or your finger exactly at the menu. We can add a pseudo-element that is larger than the menu, and it will solve the problem.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.menu:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">z-index</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
  <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">scale</span><span class="token punctuation">(</span>1.5<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Easy and straightforward, right? Play with the demo below and see the difference.</p>
<p><astro-island uid="ZOL472" prefix="r31" component-url="https://ishadeed.com/_astro/MobileMenu.jhXdaTWo.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"MobileMenu","value":true}' await-children=""></astro-island></p>
<h4 id="modal-dismiss-button">Modal dismiss button</h4>
<p>A model dismiss button is an important action that needs to be considered while building the UI.</p>
<p>If the target size is too small, it will be hard to dismiss the modal, especially on touch devices.</p>
<p><astro-island uid="12Mzfu" prefix="r32" component-url="https://ishadeed.com/_astro/ModalDismiss.F2g45n_x.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ModalDismiss","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1juvx_1"><div class="_modal_1juvx_7"><div class="_modalContent_1juvx_58"><p>title in here</p><p>a few description text just for the demo purpose.</p></div></div></div></div></astro-island></p>
<p>What are the solutions that we can do?</p>
<ul>
<li>Increase the size of the dismiss button.</li>
<li>Increase the target area only by adding a pseudo-element</li>
</ul>
<p><picture> <source srcset="https://ishadeed.com/_astro/modal-1.-bVW1gH8_ZqytJw.png" type="image/png"><source srcset="https://ishadeed.com/_astro/modal-1.-bVW1gH8_22t23P.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/modal-1.-bVW1gH8_ZqytJw.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>The first solution works, but it increases the size of the header, which
isn’t needed. Also, designers won’t like that 😉.</p>
<p>Instead, we can add a pseudo-element to the dismiss button and it will increase the size without affecting the modal header.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.button:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">z-index</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
  <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">scale</span><span class="token punctuation">(</span>1.5<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z1ibAYg" prefix="r33" component-url="https://ishadeed.com/_astro/ModalDismiss.F2g45n_x.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"ModalDismiss","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1juvx_1"><div class="_modal_1juvx_7"><div class="_modalContent_1juvx_58"><p>title in here</p><p>a few description text just for the demo purpose.</p></div></div><p class="checkbox"><input id=":r33R2:" type="checkbox" class="sr-only _input_3qp17_1"><label class="_label_3qp17_16" for=":r33R2:">Enhance target size</label></p></div></div></astro-island></p>
<p>Fixed 🥳</p>

<p>An example of having a large target size is a section header. There is a link that redirects the user to the full content.</p>
<p>At first glance, the arrow looks fine. Try to hover on the arrow link. Notice how the target area is small.</p>
<p><astro-island uid="1xYYb7" prefix="r34" component-url="https://ishadeed.com/_astro/SectionHeader.IaPXyJUt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"SectionHeader","value":true}' await-children=""></astro-island></p>
<p>The spacing around the arrow is padding for the section header.</p>
<p><astro-island uid="LOF9P" prefix="r35" component-url="https://ishadeed.com/_astro/SectionHeader.IaPXyJUt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"SectionHeader","value":true}' await-children=""></astro-island></p>
<p>To fix that, we have two options:</p>
<ul>
<li>Remove padding from the header and add it to the arrow button.</li>
<li>Keep the padding on the header and use a pseudo-element to increase the target size.</li>
</ul>
<p>I will opt-in for the pseudo solution. Feel free to do the solution that works best for your use-case.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.section__more:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">z-index</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
  <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">scale</span><span class="token punctuation">(</span>1.5<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="1JmVfE" prefix="r36" component-url="https://ishadeed.com/_astro/SectionHeader.IaPXyJUt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"],"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"SectionHeader","value":true}' await-children=""></astro-island></p>
<h4 id="search-component">Search component</h4>
<p>Oftentimes, we add an icon to the search component. It’s recommended to give it a enough target size.</p>
<p><astro-island uid="Xnm4j" prefix="r37" component-url="https://ishadeed.com/_astro/SearchFilter.DBhRpvXm.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"SearchFilter","value":true}' await-children=""></astro-island></p>
<p>In the above example, the filter button size is constrained to the icon only. We can increase the size via padding, sizing the icon, or expanding the target area with an additional element.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.search__filter:after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">z-index</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
  <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">scale</span><span class="token punctuation">(</span>2<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z6GnhQ" prefix="r38" component-url="https://ishadeed.com/_astro/SearchFilter.DBhRpvXm.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"],"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"SearchFilter","value":true}' await-children=""></astro-island></p>
<p>Much better.</p>

<p>In a profile menu toggle, having the action only on the arrow icon isn’t a good practice. It forces the user to laser-point their mouse to open the menu.</p>
<p><astro-island uid="Z2i5n2K" prefix="r39" component-url="https://ishadeed.com/_astro/ProfileMenu.NcPq9QU7.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ProfileMenu","value":true}' await-children=""></astro-island></p>
<p>Instead, the target size should be on the whole block (name, avatar, and icon). To do that, we can use a pseudo-element to extend the target size.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.siteHeaderActions</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.button:after</span> <span class="token punctuation">{</span>
  <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
  <span class="token property">inset</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="219Gx6" prefix="r40" component-url="https://ishadeed.com/_astro/ProfileMenu.NcPq9QU7.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"ProfileMenu","value":true}' await-children=""></astro-island></p>
<p>Even better, we can add a background and make it more clear that all of
the block is clickable.</p>
<p><astro-island uid="ZTA6BG" prefix="r41" component-url="https://ishadeed.com/_astro/ProfileMenu.NcPq9QU7.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"toggleEnhance":[0,true],"boxed":[0,true]}' ssr="" client="visible" opts='{"name":"ProfileMenu","value":true}' await-children=""></astro-island></p>
<h3 id="checkboxes-and-radio-buttons">Checkboxes and radio buttons</h3>
<p>Let’s highlight something here. The default styling for checkboxes and radio buttons on the web isn’t accessible for touch users. I guess the reason is because these controls weren’t designed for touch in the first place.</p>
<p><astro-island uid="Z1NAlBu" prefix="r42" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<p>I experimented to validate that. In the following photo, see how the tip of my thumb is almost the size of three checkboxes. It’s very hard to choose an option. This is the default style for checkboxes.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/example-checkbox-1.QtNLxMH4_175es6.png" type="image/png"><source srcset="https://ishadeed.com/_astro/example-checkbox-1.QtNLxMH4_1DGMCK.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/example-checkbox-1.QtNLxMH4_175es6.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Let’s explore how to make this much better.</p>
<h4 id="link-the-input-with-the-label">Link the input with the label</h4>
<p>Before diving into this solution, let’s highlight the issue it prevents.</p>
<p>Say that we have the following HTML: an input and a label.</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback1<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span><span class="token punctuation">&gt;</span></span>Social media<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span></code></pre>
<p>The target area will be only on the checkbox (the highlighted area).</p>
<p><astro-island uid="TLr98" prefix="r43" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<p>To fix that, the input ID must be used in the <code>for</code> attribute of the label. Such a quick fix with a big impact on the user experience and accessibility.</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback1<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Social media<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span></code></pre>
<p><astro-island uid="RIQtj" prefix="r44" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<h4 id="make-the-checkbox-bigger">Make the checkbox bigger</h4>
<p>The next step is to increase the checkbox size. To make things easier, I will do a custom checkbox and hide the default one. This is better to have a consistent experience across different browsers and devices.</p>
<ul>
<li>Hide the default input. I used the <code>sr-only</code> solution to hide it only visually.</li>
<li>Styled a custom element for the label.</li>
</ul>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span>
  <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>”sr-only”<span class="token punctuation">"</span></span>
  <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span>
  <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback<span class="token punctuation">"</span></span>
  <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback1<span class="token punctuation">"</span></span>
<span class="token punctuation">/&gt;</span></span>
Social media
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>feedback1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span></code></pre>
<p><astro-island uid="2nCbld" prefix="r45" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"3"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<h4 id="add-padding">Add padding</h4>
<p>Increasing the padding around the checkbox will make the target area even larger.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">label</span> <span class="token punctuation">{</span>
  <span class="token property">padding-block</span><span class="token punctuation">:</span> 3px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z2cPodr" prefix="r46" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"4"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<h4 id="increase-spacing-between-each-row">Increase spacing between each row</h4>
<p>You might be wondering, the article is about increasing the target size, but the checkboxes are too close to each other. Let’s fix that.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.form-group</span> <span class="token punctuation">{</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 8px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="s6o8o" prefix="r47" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"5"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<h4 id="make-the-labels-equal-to-the-largest-one">Make the labels equal to the largest one</h4>
<p>Currently, the width of each option is equal to its container. This is a large target area that can get even larger if the container is taking the full width.</p>
<p>See the following example.</p>
<p><astro-island uid="Z1i3zVB" prefix="r48" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"6"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<p>This is a very large target area that isn’t needed in my opinion. What we can do instead is to limit the width of all options to the largest of them.</p>
<p>We can get the benefit of <code>max-content</code> in CSS. When we add it to the options container, its width will be equal to the longest option.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.form-group</span> <span class="token punctuation">{</span>
  <span class="token property">width</span><span class="token punctuation">:</span> max-content<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="ZBIeVa" prefix="r49" component-url="https://ishadeed.com/_astro/CheckboxExample.8UrfXGPq.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"7"]}' ssr="" client="visible" opts='{"name":"CheckboxExample","value":true}' await-children=""></astro-island></p>
<p>On mobile, we can increase the spacing between the checkbox items. We might not need that. Please make sure to test them.</p>
<p>I made a final demo that show the process of enhancing the UI. Move the slider to see the gradual enhancement.</p>
<p><astro-island uid="ZGMdKl" prefix="r50" component-url="https://ishadeed.com/_astro/DemoCheckbox.AEQa6zTC.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"DemoCheckbox","value":true}' await-children=""></astro-island></p>
<p>With that, here is the enhanced target size with an actual larger thumb using them (Hey there!).</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/example-checkbox-2.s6ysUW0v_1a10bj.png" type="image/png"><source srcset="https://ishadeed.com/_astro/example-checkbox-2.s6ysUW0v_1GCylX.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/example-checkbox-2.s6ysUW0v_1a10bj.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>From the photo, I can see that my thumb tip is being able to tap a specific
checkbox without worrying about checking one by mistake.</p>
<p>Since humans like visuals more, here is a side-by-side comparison of the before and after.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/example-checkbox-3.VXbf8iIk_Z14ocTL.png" type="image/png"><source srcset="https://ishadeed.com/_astro/example-checkbox-3.VXbf8iIk_ZwLDJ7.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/example-checkbox-3.VXbf8iIk_Z14ocTL.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Notice how the difference is clear. Always make sure to have a large target
size. See the following video for me trying to use the checkboxes.</p>
<video poster="https://ishadeed.com/assets/target-size/videos/test-poster.png" src="https://ishadeed.com/assets/target-size/videos/test-video.mp4" controls controlslist="nodownload"></video>
<h3 id="action-buttons">Action buttons</h3>
<p>Buttons are a foundational component of the web. On every website you visit, you might need to interact with a button. When built right, they can be effective and easy to use for the user.</p>
<p>In the given example, two buttons are present. It’s possible to tap the wrong button due to their small size and minimal spacing.</p>
<p>Try to change the thumb size and notice how the touch indicator can easily overlap the buttons at once. This isn’t good.</p>
<p><astro-island uid="Z1IVVvi" prefix="r51" component-url="https://ishadeed.com/_astro/TouchIndicator.8MUI1jDX.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"TouchIndicator","value":true}' await-children=""><div class="touch-test"><div class="box"><div class="content undefined"><h3>Please review changes</h3><p>All changes will be saved upon confirming.</p></div><p class="touch"></p></div></div></astro-island></p>
<p>We have two options to fix that:</p>
<ul>
<li>Increase button size and spacing</li>
<li>Display each button it a new line with full width</li>
</ul>
<p><picture> <source srcset="https://ishadeed.com/_astro/example-buttons-1._JwUmOce_1UYccD.png" type="image/png"><source srcset="https://ishadeed.com/_astro/example-buttons-1._JwUmOce_MYCQR.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/example-buttons-1._JwUmOce_1UYccD.png" alt="" loading="lazy" decoding="async"> </source></source></picture>I won’t
discuss which solution is the best, but the idea is that we want to
increase the target size. In both solutions, it’s harder to overlap or
tap a button my mistake.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.button-group</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 0.5rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .button</span> <span class="token punctuation">{</span>

  <span class="token property">padding</span><span class="token punctuation">:</span> 0.5rem 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Or..</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.button-group</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">flex-direction</span><span class="token punctuation">:</span> column<span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 0.5rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">​ .button</span> <span class="token punctuation">{</span>

  <span class="token property">padding</span><span class="token punctuation">:</span> 0.5rem 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>For the sake of this example, I will go with the first solution.</p>
<p><astro-island uid="2en9q5" prefix="r52" component-url="https://ishadeed.com/_astro/TouchIndicator.8MUI1jDX.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"TouchIndicator","value":true}' await-children=""><div class="touch-test"><div class="box"><div class="content enhanced"><h3>Please review changes</h3><p>All changes will be saved upon confirming.</p></div><p class="touch"></p></div></div></astro-island></p>
<h3 id="text-buttons">Text buttons</h3>
<p>Text buttons are often used to give more focus to the surrounding content, or to use them as a secondary button.</p>
<p>In the following demo, the text button “learn more” looks like it has a good target size. Toggle the outline and see it.</p>
<p><astro-island uid="268TaJ" prefix="r53" component-url="https://ishadeed.com/_astro/TextButton.Gu2escNA.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"showOutline":[0,true]}' ssr="" client="visible" opts='{"name":"TextButton","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1hqq0_1"><article class="_card_1hqq0_7"><img src="https://ishadeed.com/assets/target-size/cookies.jpg" alt=""><div><h3>Yummy cookies</h3><p>Learn how to make great cookies at home.</p></div></article></div></div></astro-island></p>
<p>The simplest fix is to add <code>padding</code> around the button itself.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.button</span> <span class="token punctuation">{</span>

  <span class="token property">padding</span><span class="token punctuation">:</span> 8px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z12Ob50" prefix="r54" component-url="https://ishadeed.com/_astro/TextButton.Gu2escNA.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"showOutline":[0,true],"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"TextButton","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1hqq0_1"><article class="_card_1hqq0_7"><img src="https://ishadeed.com/assets/target-size/cookies.jpg" alt=""><div><h3>Yummy cookies</h3><p>Learn how to make great cookies at home.</p></div></article></div></div></astro-island></p>
<p>Better, right?</p>
<p>Another example where text buttons can be used is in a group of buttons. Say we have a modal with a confirm and cancel button.</p>
<p><astro-island uid="1iLYfO" prefix="r55" component-url="https://ishadeed.com/_astro/ConfirmSection.7blkEYyt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"showOutline":[0,true]}' ssr="" client="visible" opts='{"name":"ConfirmSection","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1dai1_1"><article class="_card_1dai1_7"><div><div><h3>Are you sure?</h3><p>You are about to change nothing since this is just a UI example.</p></div></div></article></div></div></astro-island></p>
<p>To fix that, we need to make sure that the text button has padding around it.</p>
<p><astro-island uid="Z253uYi" prefix="r56" component-url="https://ishadeed.com/_astro/ConfirmSection.7blkEYyt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"showOutline":[0,true],"enhanced":[0,true]}' ssr="" client="visible" opts='{"name":"ConfirmSection","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_1dai1_1"><article class="_card_1dai1_7"><div><div><h3>Are you sure?</h3><p>You are about to change nothing since this is just a UI example.</p></div></div></article></div></div></astro-island></p>
<p>The pagination is often used to organize large amounts of content so the user can access them easily.</p>
<p>Let’s explore a pagination example that looks fine from a visual perspective, but raises important questions when it comes to the target area size.</p>
<p><astro-island uid="Z1MgAO6" prefix="r57" component-url="https://ishadeed.com/_astro/Pagination.GQenUq0_.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"Pagination","value":true}' await-children=""></astro-island></p>
<p>Notice the target area when it’s highlighted.</p>
<ul>
<li>Target size is small</li>
<li>Spacing is large</li>
</ul>
<p>The spacing made look like the target size is large.</p>
<p><astro-island uid="6P1w3" prefix="r58" component-url="https://ishadeed.com/_astro/Pagination.GQenUq0_.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"],"spacingIndicator":[0,true]}' ssr="" client="visible" opts='{"name":"Pagination","value":true}' await-children=""></astro-island></p>
<p>To fix that, we need to:</p>
<ul>
<li>Reduce the spacing</li>
<li>Add more horizontal (inline) padding to each pagination item</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.pagination</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> 4px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.pagination__item</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 0.5rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="ZqBHF2" prefix="r59" component-url="https://ishadeed.com/_astro/Pagination.GQenUq0_.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"3"],"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"Pagination","value":true}' await-children=""></astro-island></p>
<h3 id="vertical-navigation">Vertical navigation</h3>
<p>In a previous Twitter design, the navigation was as follows. Each nav item size depends on its content.</p>
<p><astro-island uid="UgDd3" prefix="r60" component-url="https://ishadeed.com/_astro/VerticalNav.rwmZXwOt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"],"Indicator":[0,"Non-clickable area"]}' ssr="" client="visible" opts='{"name":"VerticalNav$1","value":true}' await-children=""></astro-island></p>
<p>This is a confusing behavior as the user might expect the full navigation element to be clickable.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/vertical-nav-1.enZO-EDj_13yyaV.png" type="image/png"><source srcset="https://ishadeed.com/_astro/vertical-nav-1.enZO-EDj_Z1rOaiu.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/vertical-nav-1.enZO-EDj_13yyaV.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Here is a version with each navigation item taking the full width. Much
better.</p>
<p><astro-island uid="R3q9F" prefix="r61" component-url="https://ishadeed.com/_astro/VerticalNav.rwmZXwOt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"],"toggleEnhance":[0,true],"helper":[0,"Toggle the checkbox to see the larger targets"]}' ssr="" client="visible" opts='{"name":"VerticalNav$1","value":true}' await-children=""><div><p>Toggle the checkbox to see the larger targets</p></div></astro-island></p>
<h3 id="category-list">Category list</h3>
<p>In the following example, the target size is on the label only. The spacing around the labels is padding added to the <code>&lt;li&gt;</code> element, not the <code>&lt;a&gt;</code> element.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/category-list-1.84dVSplc_P5nbq.png" type="image/png"><source srcset="https://ishadeed.com/_astro/category-list-1.84dVSplc_ZOY3tL.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/category-list-1.84dVSplc_P5nbq.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>To fix that:</p>
<ul>
<li>Move the icon inside the <code>&lt;a&gt;</code> element.</li>
<li>We need to remove the padding from the <code>&lt;li&gt;</code> and add it to the <code>&lt;a&gt;</code> element, and force them to take the full width.</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.nav-item a</span> <span class="token punctuation">{</span>

  <span class="token property">padding</span><span class="token punctuation">:</span> 0.8rem 1rem<span class="token punctuation">;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="ZyUqp1" prefix="r62" component-url="https://ishadeed.com/_astro/CategoryList.AMHssFfm.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,"Toggle the checkbox. This demo is using a pseudo-element for interactivity purposes."],"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"VerticalNav","value":true}' await-children=""><div><p>Toggle the checkbox. This demo is using a pseudo-element for interactivity purposes.</p></div></astro-island></p>
<p>On mobile, having a great scrolling experience is crucial to let the user explore more content. The other day, I was browsing Amazon on my mobile and noticed an interesting behavior.</p>
<p>In the following figure, the scrollable section “You might also like” isn’t only on the cards, but also on the highlighted area underneath.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/scrolling-container-1.j0KqkTzR_oi5Tc.png" type="image/png"><source srcset="https://ishadeed.com/_astro/scrolling-container-1.j0KqkTzR_1nhgd9.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/scrolling-container-1.j0KqkTzR_oi5Tc.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In CSS, we can do such a thing by extending the bottom spacing. If we’re
using CSS Scroll Snap, we need to add <code>padding-bottom</code> only.</p>
<p>See the following demo.</p>
<p><astro-island uid="QnnGW" prefix="r63" component-url="https://ishadeed.com/_astro/ScrollingContainer.J0ZtNdDg.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"ScrollingContainer","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_8ctok_1 undefined"><div><h3>You might also like</h3><section class="_section_8ctok_12 false"><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Chocolate Cake</h4><p class="_desc_8ctok_43">Rich and moist chocolate cake with a velvety smooth ganache.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Strawberry Cheesecake</h4><p class="_desc_8ctok_43">Creamy cheesecake topped with fresh strawberries and a sweet glaze.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Apple Pie</h4><p class="_desc_8ctok_43">Flaky crust filled with cinnamon-spiced apples, baked to golden perfection.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Tiramisu</h4><p class="_desc_8ctok_43">Classic Italian dessert with layers of coffee-soaked ladyfingers and mascarpone cream.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Mango Sorbet</h4><p class="_desc_8ctok_43">Refreshing sorbet made with ripe mangoes, perfect for a tropical treat.</p></div></div></section></div><div><h3>Another section in here</h3><p>This is a random desc in here, just to show that there is another section under the scrollable one.</p></div></div></div></astro-island></p>
<p>Try to scroll the section on mobile, and you will notice that the scrollable area is within the content only.</p>
<p>We can extend that by increasing the bottom padding.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.section</span> <span class="token punctuation">{</span>

  <span class="token property">padding-bottom</span><span class="token punctuation">:</span> 4rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="aC2t" prefix="r64" component-url="https://ishadeed.com/_astro/ScrollingContainer.J0ZtNdDg.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,"Try to scroll the container on mobile."],"toggleEnhance":[0,true]}' ssr="" client="visible" opts='{"name":"ScrollingContainer","value":true}' await-children=""><div><div class="example-wrapper center _wrapper_8ctok_1 _enhanced_8ctok_8"><div><h3>You might also like</h3><section class="_section_8ctok_12 false"><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Chocolate Cake</h4><p class="_desc_8ctok_43">Rich and moist chocolate cake with a velvety smooth ganache.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Strawberry Cheesecake</h4><p class="_desc_8ctok_43">Creamy cheesecake topped with fresh strawberries and a sweet glaze.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Apple Pie</h4><p class="_desc_8ctok_43">Flaky crust filled with cinnamon-spiced apples, baked to golden perfection.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Tiramisu</h4><p class="_desc_8ctok_43">Classic Italian dessert with layers of coffee-soaked ladyfingers and mascarpone cream.</p></div></div><div class="_sectionItem_8ctok_31"><p class="_sectionItemThumb_8ctok_47"></p><div><h4 class="_title_8ctok_39">Mango Sorbet</h4><p class="_desc_8ctok_43">Refreshing sorbet made with ripe mangoes, perfect for a tropical treat.</p></div></div></section></div><div><h3>Another section in here</h3><p>This is a random desc in here, just to show that there is another section under the scrollable one.</p></div></div><p>Try to scroll the container on mobile.</p></div></astro-island></p>
<p>This is better. Some may say there’s a big spacing under the section, and I agree. However, sometimes it’s okay because the benefits outweigh the drawbacks.</p>
<h3 id="placement-of-target-items">Placement of target items</h3>
<p>In cases where there is an action item at the top and a result at the bottom, the user’s finger on mobile might cover the result, making it annoying to see the change when for example, changing tabs, or toggling an option from a list.</p>
<p>This example is from this article.</p>
<p><astro-island uid="ZCkO4u" prefix="r65" component-url="https://ishadeed.com/_astro/DemoContext.riEHUkJo.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"DemoContext","value":true}' await-children=""><div><div class="example-wrapper center"><div class="demo-context"><div><svg viewbox="0 0 28 29" fill="none" xmlns="http://www.w3.org/2000/svg"><g opacity="0.5"><path d="M12.3484 12.808C12.3484 14.675 15.1484 14.675 15.1484 12.808C15.1484 10.941 12.3484 10.941 12.3484 12.808Z" fill="black"></path><path d="M17.8914 12.808C17.8914 14.675 20.6914 14.675 20.6914 12.808C20.6914 10.941 17.8914 10.941 17.8914 12.808Z" fill="black"></path><path d="M6.94414 12.808C6.94414 14.675 9.74414 14.675 9.74414 12.808C9.74414 10.941 6.94414 10.941 6.94414 12.808Z" fill="black"></path><path d="M9.51938 3.20386H18.5079C23.6037 3.20386 27.7754 7.34814 27.7754 12.4724C27.7754 17.5967 23.6311 21.741 18.5068 21.741H16.1826L9.26688 26.8653L9.26797 21.7127C4.28369 21.5727 0.252249 17.4841 0.252249 12.4441C0.251156 7.34842 4.42369 3.20414 9.51969 3.20414L9.51938 3.20386ZM9.51938 20.4239H10.5836V24.2596L15.735 20.4239H18.5066C22.9023 20.4239 26.458 16.8681 26.458 12.4724C26.458 8.0767 22.9023 4.52098 18.5066 4.52098L9.51916 4.51988C5.12344 4.51988 1.56771 8.0756 1.56771 12.4713C1.56771 16.8682 5.12366 20.4239 9.51938 20.4239Z" fill="black"></path></g></svg><p>I checked the order page on my <span>phone</span> and tried to <span>tap</span> the order button but it’s not responding.</p></div></div></div></div></astro-island></p>
<p>At first glance, the positioning of the radio buttons might seem okay. On mobile, it’s something different.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/placement-target-1.3wmZOrJa_Z1XLOjh.png" type="image/png"><source srcset="https://ishadeed.com/_astro/placement-target-1.3wmZOrJa_Z1rag8C.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/placement-target-1.3wmZOrJa_Z1XLOjh.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Notice how my thumb is covering the result. It’s hard to see the changes
while my thumb is choosing an option.</p>
<p>The fix is simple. The placement of the options should be at the bottom.</p>
<p><astro-island uid="vmLPo" prefix="r66" component-url="https://ishadeed.com/_astro/DemoContext.riEHUkJo.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"DemoContext","value":true}' await-children=""><div><div class="example-wrapper center"><div class="demo-context"><div><svg viewbox="0 0 28 29" fill="none" xmlns="http://www.w3.org/2000/svg"><g opacity="0.5"><path d="M12.3484 12.808C12.3484 14.675 15.1484 14.675 15.1484 12.808C15.1484 10.941 12.3484 10.941 12.3484 12.808Z" fill="black"></path><path d="M17.8914 12.808C17.8914 14.675 20.6914 14.675 20.6914 12.808C20.6914 10.941 17.8914 10.941 17.8914 12.808Z" fill="black"></path><path d="M6.94414 12.808C6.94414 14.675 9.74414 14.675 9.74414 12.808C9.74414 10.941 6.94414 10.941 6.94414 12.808Z" fill="black"></path><path d="M9.51938 3.20386H18.5079C23.6037 3.20386 27.7754 7.34814 27.7754 12.4724C27.7754 17.5967 23.6311 21.741 18.5068 21.741H16.1826L9.26688 26.8653L9.26797 21.7127C4.28369 21.5727 0.252249 17.4841 0.252249 12.4441C0.251156 7.34842 4.42369 3.20414 9.51969 3.20414L9.51938 3.20386ZM9.51938 20.4239H10.5836V24.2596L15.735 20.4239H18.5066C22.9023 20.4239 26.458 16.8681 26.458 12.4724C26.458 8.0767 22.9023 4.52098 18.5066 4.52098L9.51916 4.51988C5.12344 4.51988 1.56771 8.0756 1.56771 12.4713C1.56771 16.8682 5.12366 20.4239 9.51938 20.4239Z" fill="black"></path></g></svg><p>I checked the order page on my <span>phone</span> and tried to <span>tap</span> the order button but it’s not responding.</p></div></div></div></div></astro-island>
<picture> <source srcset="https://ishadeed.com/_astro/placement-target-2.LwjLzU3l_1UBqaJ.png" type="image/png"><source srcset="https://ishadeed.com/_astro/placement-target-2.LwjLzU3l_2sdYlo.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/placement-target-2.LwjLzU3l_1UBqaJ.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>A real-life example of this is a UX detail I like on TikTok. When you tab the
progress bar of the video, the timing will be shown above in a large
size.</p>
<p>This is a great UX detail, as it doesn’t show the timing under my finger or next to it. See the following figure:</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/placement-target-vs-result.j7Un2NEp_Z2dUT9I.png" type="image/png"><source srcset="https://ishadeed.com/_astro/placement-target-vs-result.j7Un2NEp_1qGa52.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/placement-target-vs-result.j7Un2NEp_Z2dUT9I.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>If the time were displayed on the progress bar itself, it would be harder
for the user to spot it. Placing it at the top is better.</p>
<p>On Instagram, it’s similar, but they also add a preview of the video.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/placement-target-vs-result-2.SK-0Rka5_ZAWA4X.png" type="image/png"><source srcset="https://ishadeed.com/_astro/placement-target-vs-result-2.SK-0Rka5_Z1FaVUP.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/placement-target-vs-result-2.SK-0Rka5_ZAWA4X.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h3 id="dominant-hand-of-the-user">Dominant hand of the user</h3>
<p>Making it easy for the user to tap a target is not only about its size, but also it’s location. The following is an experiment based on a React hook by <a href="https://github.com/KittyGiraudel/dhand">Kitty Giraudel</a> called “dhand”.</p>
<p>The idea is to guess what’s the dominant hand for the user and update the UI based on it.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/dominant-hand-1.wzgmkaOW_hGm1B.png" type="image/png"><source srcset="https://ishadeed.com/_astro/dominant-hand-1.wzgmkaOW_Z1nn4DA.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/dominant-hand-1.wzgmkaOW_hGm1B.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>The assumption that this experience is based on is that a left-handed user
will more likely tap on the far right of the UI. On the other hand, a right-handed
will tap on the left side.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/dominant-hand-2.dp3ednDd_ZdLRWK.png" type="image/png"><source srcset="https://ishadeed.com/_astro/dominant-hand-2.dp3ednDd_Z1SQjCW.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/dominant-hand-2.dp3ednDd_ZdLRWK.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>With that info in mind, we can make decisions about what’s the dominant
hand. It’s an interesting experience. If I can learn one thing from this,
it’s that target area isn’t only about size, but also the location.</p>
<h2 id="testing-target-sizes">Testing target sizes</h2>
<p>Spending time on a UI without testing it is a waste of time and effort. We should test the target sizes early on and keep an eye on them throughout the product building.</p>
<p>To achieve that, we need to do testing in both the design and development. Let’s start with the design aspect first.</p>
<h3 id="for-designers-delivering-a-clear-target-size-spec">For designers: delivering a clear target size spec</h3>
<p>As a designer, it’s important to have clear documentation or a spec that explains the target size throughout the system.</p>
<p>While this might not be needed for elements like buttons, it’s important for stuff like icon buttons, cards, tabs, mobile menus, you name it!</p>
<h4 id="tabs-component">Tabs component</h4>
<p>In a tabs component, the spacing should be around the tab item itself, not built from the outer padding of the parent.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-1.pFkXV2JK_2iawU4.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-1.pFkXV2JK_1gTqaj.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-1.pFkXV2JK_2iawU4.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="slider-navigation">Slider navigation</h4>
<p>This is a great example of keeping the UI as is, but expanding the target size to make it easier for the user to control the slider.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-2.j5oDanki_1uKRsc.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-2.j5oDanki_mLj7q.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-2.j5oDanki_1uKRsc.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>As a designer, thinking about those UI decisions upfront is important to
deliver a great UX.</p>
<h4 id="icon-buttons-1">Icon buttons</h4>
<p>This applies to different cases and examples. Here is one for a modal dismiss button.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-3._YGew-vA_FfQCk.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-3._YGew-vA_Zl0f7q.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-3._YGew-vA_FfQCk.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>And this is for a close pattern that is placed at the top-right corner.
Generally speaking, this pattern isn’t recommended.</p>
<p>I spotted this in the tags menu in Threads by Meta.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-4.3Jkk6XZv_Z1DDesl.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-4.3Jkk6XZv_2phMAP.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-4.3Jkk6XZv_Z1DDesl.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Here is my recommendation.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-5.KR37WxIr_10hWCt.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-5.KR37WxIr_ZX97h.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-5.KR37WxIr_10hWCt.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="website-navigation-1">Website navigation</h4>
<p>In a design tool like Figma, we sometimes forget the touch size details when we quickly mock up a UI. In this example, it’s a website header.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-6.Vajf4ul-_Z29J3LM.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-6.Vajf4ul-_1fnDlW.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-6.Vajf4ul-_Z29J3LM.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In this design, the navigation items target size is only on the text. This
isn’t good. Don’t make the developer think twice like:</p>
<ul>
<li>Did the designer mean to have them like this?</li>
<li>What if the user clicked <code>3px</code> above a navigation item?</li>
</ul>
<p>An experienced developer will fix that themselves, or ask the designer first. But we can’t assume that all developers are aware of this as people have different levels of knowledge, which is fine.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/test-designers-7.osLbV_Y9_1sfSGD.png" type="image/png"><source srcset="https://ishadeed.com/_astro/test-designers-7.osLbV_Y9_qYLVS.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/test-designers-7.osLbV_Y9_1sfSGD.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h4 id="provide-a-target-size-component">Provide a target size component</h4>
<p>Let’s suppose that you worked on a modal design and used an icon for a close button.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-size-component-1.VM9rVhCi_Z2iFmYe.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-size-component-1.VM9rVhCi_Z2ki0gm.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-size-component-1.VM9rVhCi_Z2iFmYe.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In Figma, the close icon doesn’t have any boundaries other than the icon
itself, thus indicating to the developer that it should be that way.</p>
<p>In the following example, I placed the icon within a Target component. I can use this component anywhere in the design.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/target-size-component-2.BK1i_Aqk_y6EA1.png" type="image/png"><source srcset="https://ishadeed.com/_astro/target-size-component-2.BK1i_Aqk_wu2iS.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/target-size-component-2.BK1i_Aqk_y6EA1.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Making this clear in the design is important for both the designer and
the developer. If they know it, it’s a friendly reminder. If not, then
they’ve learned something new!</p>
<h3 id="for-developers-testing-target-sizes">For developers: testing target sizes</h3>
<p>Once the design we have is well documented for target size rules, it’s time to test the UI for any small target sizes.</p>

<p>The browser DevTools is a powerful way to detect and spot target size issues. The simplest thing you can do is to check the width of a target size by inspecting the element.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/developers-test-1.iJ5AJveK_2lN9xh.png" type="image/png"><source srcset="https://ishadeed.com/_astro/developers-test-1.iJ5AJveK_1dNAcv.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/developers-test-1.iJ5AJveK_2lN9xh.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>This is good for testing a simple UI, but for a UI with lots of details,
you will need to automate that somehow.</p>
<h4 id="use-css-outline-to-have-a-look-at-the-target-size">Use CSS outline to have a look at the target size</h4>
<p>Applying a CSS outline to every link and button on the page is a good mechanism. It helps you to see the outer box for every interactive element on the page.</p>
<p>I worked on a proof of concept snippet that adds an outline to every button and link on the page plus showing the size of each.</p>
<p>See it in the demo below:</p>
<p class="codepen" data-height="504.97265625" data-theme-id="light" data-slug-hash="wvOWLQw" data-user="shadeed"></p>

<p><a href="https://polypane.app/">Polypane browser</a> by Kilian Valkhof is a great browser for testing and debugging websites. There is a “Target size” debug feature that lets you pick a size for the cursor.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/developers-test-3.AfckxL0L_ZWiBSm.png" type="image/png"><source srcset="https://ishadeed.com/_astro/developers-test-3.AfckxL0L_Z25ibe8.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/developers-test-3.AfckxL0L_ZWiBSm.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Once you pick the target size (48, 44, or 24), the cursor will become the
size of the selected option. It’s useful to spot UI elements that will
interfere with each other.</p>
<p>Here is an example in testing my headers-css project, the search and menu buttons should have more spacing between each other.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/developers-test-4.jiYYm-Pw_ZrpaQ1.png" type="image/png"><source srcset="https://ishadeed.com/_astro/developers-test-4.jiYYm-Pw_Z1zoJbM.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/developers-test-4.jiYYm-Pw_ZrpaQ1.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Another detail that I liked in Polypane is highlighting small target areas
and how they interfere with each other. Here is an example of the default
HTML checkboxes:</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/developers-test-5.EVJscJ5s_ZCyg9D.png" type="image/png"><source srcset="https://ishadeed.com/_astro/developers-test-5.EVJscJ5s_Z1KxOup.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/developers-test-5.EVJscJ5s_ZCyg9D.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h2 id="real-life-examples">Real-life examples</h2>
<p>You can’t make an article on a UX topic without showcasing a practical example. Let’s explore examples that I spotted on the web and how to fix them.</p>

<p>The other day, I was listenting to a Twitter space, and I was about to leave the space by mistake because the “Leave” button is overlapping with the context menu (AKA the dots icon).</p>
<p><astro-island uid="ZDDoJP" prefix="r67" component-url="https://ishadeed.com/_astro/TwitterSpaces.U4-9hhPt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,"Try to hover on the Leave button or the dots menu."],"variation":[0,"1"]}' ssr="" client="visible" opts='{"name":"TwitterSpaces","value":true}' await-children=""><div><p>Try to hover on the Leave button or the dots menu.</p></div></astro-island></p>
<p>Did you notice that the dots and “leave” buttons overlap? Let me make it more clear.</p>
<p><astro-island uid="2cur99" prefix="r68" component-url="https://ishadeed.com/_astro/TwitterSpaces.U4-9hhPt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"variation":[0,"2"]}' ssr="" client="visible" opts='{"name":"TwitterSpaces","value":true}' await-children=""></astro-island></p>
<p>This isn’t good. To fix it, we simply need to add spacing between the icons buttons and the “leave” button.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.header</span> <span class="token punctuation">{</span>

  <span class="token property">gap</span><span class="token punctuation">:</span> 1rem<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><astro-island uid="Z15cCbU" prefix="r69" component-url="https://ishadeed.com/_astro/TwitterSpaces.U4-9hhPt.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props='{"helper":[0,"Much better."],"variation":[0,"3"]}' ssr="" client="visible" opts='{"name":"TwitterSpaces","value":true}' await-children=""></astro-island></p>
<p>While looking at a font in Adobe Fonts, I noticed an issue in the target size of the tag component.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/adobe-fonts-tag-1.z4SgZnZ5_1Y2tLM.png" type="image/png"><source srcset="https://ishadeed.com/_astro/adobe-fonts-tag-1.z4SgZnZ5_Q2Ur1.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/adobe-fonts-tag-1.z4SgZnZ5_1Y2tLM.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>The target size of the tag is on the text only. As a user, you will expect
that all of the tags is clickable. This is not good. I’m surprised to see
that by Adobe.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/adobe-fonts-tag-2.jlkOF7Ey_Z10pLdC.png" type="image/png"><source srcset="https://ishadeed.com/_astro/adobe-fonts-tag-2.jlkOF7Ey_Z28pkyo.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/adobe-fonts-tag-2.jlkOF7Ey_Z10pLdC.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Here is the CSS for the component:</p>
<pre class="language-html"><code is:raw="" class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>spectrum-Tags-item<span class="token punctuation">"</span></span> <span class="token attr-name">role</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>listitem<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>English<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></code></pre>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.spectrum-Tags-item</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> inline-flex<span class="token punctuation">;</span>
  <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 0 9px<span class="token punctuation">;</span>
  <span class="token property">height</span><span class="token punctuation">:</span> 24px<span class="token punctuation">;</span>
  <span class="token property">border</span><span class="token punctuation">:</span> 1px solid<span class="token punctuation">;</span>
  <span class="token property">border-radius</span><span class="token punctuation">:</span> 4px<span class="token punctuation">;</span>

<span class="token punctuation">}</span></code></pre>
<p>To fix that, we need to:</p>
<ul>
<li>The padding should be added to the <code>&lt;a&gt;</code> instead.</li>
<li>Remove the fixed height Using a fixed height isn’t recommended. See <a href="https://defensivecss.dev/tip/fixed-sizes/">Fixed sizes on Defensive CSS</a>.</li>
</ul>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.spectrum-Tags-item a</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> inline-flex<span class="token punctuation">;</span>
  <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 4px 12px<span class="token punctuation">;</span>
  <span class="token property">border</span><span class="token punctuation">:</span> 1px solid<span class="token punctuation">;</span>
  <span class="token property">border-radius</span><span class="token punctuation">:</span> 4px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Here is a video that compares the before and after change:</p>
<video poster="https://ishadeed.com/assets/target-size/videos/adobe-fonts-poster.png" src="https://ishadeed.com/assets/target-size/videos/adobe-fonts-tag.mp4" controls controlslist="nodownload"></video>
<h3 id="backblaze-navigation">Backblaze navigation</h3>
<p>I use Backblaze to back up my data and noticed something on the login page. The target size for the menu items is only on the text.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/backblaze-nav-1._NyIwUt3_1CKatB.png" type="image/png"><source srcset="https://ishadeed.com/_astro/backblaze-nav-1._NyIwUt3_Z2jgbA.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/backblaze-nav-1._NyIwUt3_1CKatB.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>In the UI, it indicates that the whole item is clickable because there
are top and bottom borders.</p>
<p>Again, the fix is similar to the previous Adobe example. We need to add the padding to the <code>&lt;a&gt;</code> element.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/backblaze-nav-2.sVNwrzNN_YTu6d.png" type="image/png"><source srcset="https://ishadeed.com/_astro/backblaze-nav-2.sVNwrzNN_ZF9VyY.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/backblaze-nav-2.sVNwrzNN_YTu6d.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<h3 id="dribbble-navigation">Dribbble navigation</h3>
<p>Yes, Dribbble! I found lots of interesting target size issues, so why not fix them? Even though Dribbble is full of beautiful but useless UIs with lots of shadows and trendy gradients.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-1.l5TbdF-8_Z2iSl9l.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-1.l5TbdF-8_Z25gxWy.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-1.l5TbdF-8_Z2iSl9l.png" alt="" loading="lazy" decoding="async"> </source></source></picture>I added a
CSS outline and noticed the following issues:</p>
<ul>
<li>Navigation item target size is too small</li>
<li>There is zero spacing between the navigation items. This isn’t good.</li>
<li>The search button is very small &amp; inconsistent with the messages and profile size.</li>
</ul>
<p>On mobile, it’s even worse. The width of each navigation item is dependent on the content length.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-2.jMb3iBtB_Z1ft6yV.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-2.jMb3iBtB_Z11Qjn9.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-2.jMb3iBtB_Z1ft6yV.png" alt="" loading="lazy" decoding="async"> </source></source></picture>I took it
further and mocked up how this UI can be viewed compared to human
fingers.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-3.FyLgrdba_c8rEM.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-3.FyLgrdba_pKeQz.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-3.FyLgrdba_c8rEM.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Since the CSS is written via Flexbox, I was able to increase the CSS <code>gap</code>
and force the flex items to align normally.</p>
<p>The web version:</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-4.fg_d5aRG_mNNVS.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-4.fg_d5aRG_AqB8F.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-4.fg_d5aRG_mNNVS.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>And the mobile version:</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-5.m05M50JQ_Z1cU5R6.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-5.m05M50JQ_C5fim.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-5.m05M50JQ_Z1cU5R6.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>But wait… why the “Go Pro” item doesn’t have a padding from the bottom?
It’s because of this CSS:</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token atrule"><span class="token rule">@media</span> <span class="token punctuation">(</span><span class="token property">max-width</span><span class="token punctuation">:</span> 949px<span class="token punctuation">)</span></span> <span class="token punctuation">{</span>
  <span class="token selector">.nav-v2-main__item:last-child a</span> <span class="token punctuation">{</span>
    <span class="token property">padding-bottom</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
<p>This is not good. It’s a bad practice. Just keep the padding, please.</p>
<h3 id="dribbble-checkbox-component">Dribbble checkbox component</h3>
<p>Another example of Dribbble is the checkbox component. The target size is limited to the checkbox height only, while its container is large and is indicated with a border.</p>
<p>You might argue that this is just a container. For me, as a user, I assumed that the whole area was clickable.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-6.Z8j5Mmi__2tNkAn.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-6.Z8j5Mmi__Z2mL11L.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-6.Z8j5Mmi__2tNkAn.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>What I did is that I removed the padding from the outer container and added
it instead to the checkbox itself.</p>
<pre class="language-css"><code is:raw="" class="language-css"><span class="token selector">.checkbox-toggle-content</span> <span class="token punctuation">{</span>

<span class="token punctuation">}</span>
<span class="token selector">​ .checkbox-radio-label</span> <span class="token punctuation">{</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> 24px<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><picture> <source srcset="https://ishadeed.com/_astro/real-life-examples-7.SIWrOZU2_ZdG2qR.png" type="image/png"><source srcset="https://ishadeed.com/_astro/real-life-examples-7.SIWrOZU2_Z4ff5.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/real-life-examples-7.SIWrOZU2_ZdG2qR.png" alt="" loading="lazy" decoding="async"> </source></source></picture></p>
<p>Much better.</p>
<h2 id="target-size-cheatsheet">Target size cheatsheet</h2>
<p>I worked on a simple A4 cheatsheet that summarize the most important points in the article. It’s only for 7.00 USD and you can purchase it as a support for this guide.</p>
<p><picture> <source srcset="https://ishadeed.com/_astro/poster.XewPyGAC_ZKt6B2.jpg" type="image/jpg"><source srcset="https://ishadeed.com/_astro/poster.XewPyGAC_ZORkpD.webp" type="image/webp"> <img src="https://ishadeed.com/_astro/poster.XewPyGAC_ZKt6B2.jpg" alt="" loading="lazy" decoding="async"> </source></source></picture>
<astro-island uid="ZrxhmJ" prefix="r70" component-url="https://ishadeed.com/_astro/CheatSheetButton.Zrqypjtr.js" component-export="default" renderer-url="https://ishadeed.com/_astro/client.2wOxL1Aq.js" props="{}" ssr="" client="visible" opts='{"name":"CheatSheetButton","value":true}' await-children=""></astro-island></p>
<h2 id="outro">Outro</h2>
<p>When I started working on this article, I hadn’t expected it to grow that large. I initially wanted to make an interactive guide about the clickable area, but after a lot of research, I decided to call it “Target size”.</p>
<p>I already published about <a href="https://ishadeed.com/article/clickable-area/">this topic</a> five years ago, but felt the need to do it again, and I’m glad for that.</p>
<h3 id="thank-you">Thank you</h3>
<p>Thanks to my wife and partner, Kholoud, for her great support throughout the creation of this guide. I asked her about it every day for the past 6 weeks, and she didn’t kick me out of our home.</p>
<h3 id="resources">Resources</h3>
<ul>
<li><a href="https://craftcms.com/blog/accessible-target-sizes">Accessible Target Sizes</a></li>
<li><a href="https://adrianroselli.com/2019/06/target-size-and-2-5-5.html">Target Size and 2.5.5</a></li>
<li><a href="https://tetralogical.com/blog/2022/12/20/foundations-target-size">Foundations: target sizes</a></li>
<li><a href="https://www.nngroup.com/articles/touch-target-size/">Touch Targets on Touchscreens</a></li>
<li><a href="https://www.smashingmagazine.com/2012/02/finger-friendly-design-ideal-mobile-touchscreen-target-sizes/">Finger-Friendly Design: Ideal Mobile Touchscreen Target Sizes</a></li>
</ul>
<h3 id="thanks-to">Thanks to</h3>
<ul>
<li><a href="https://twitter.com/fvsch">Florens Verschelde</a> for shedding the light on the initial and fast movement of Fitt’ law.</li>
<li>The <a href="https://www.joshwcomeau.com/snippets/react-hooks/use-mouse-position/">useMousePosition</a> hook by Joshua Comeau</li>
<li><a href="https://kld.dev/building-table-of-contents/">Astro table of contents</a> by Kevin Drum</li>
<li>This <a href="https://www.smashingmagazine.com/2023/08/better-context-menus-safe-triangles/">article</a> by Costa Alexoglou on Smashing Magazine inspired me to the solution of safe triangles, but I used a clip-path instead.</li>
</ul>