惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
W
WeLiveSecurity
B
Blog RSS Feed
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
S
Security @ Cisco Blogs
博客园 - 叶小钗
月光博客
月光博客
Webroot Blog
Webroot Blog
H
Hacker News: Front Page
N
News and Events Feed by Topic
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Help Net Security
Help Net Security
S
Secure Thoughts
SecWiki News
SecWiki News
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
S
Schneier on Security
A
Arctic Wolf
博客园 - 司徒正美
T
Tor Project blog
T
Tenable Blog
量子位
D
DataBreaches.Net
PCI Perspectives
PCI Perspectives
T
The Exploit Database - CXSecurity.com
T
Threatpost
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Cloudbric
Cloudbric
T
The Blog of Author Tim Ferriss
N
News | PayPal Newsroom
Project Zero
Project Zero
S
Securelist
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
L
LINUX DO - 热门话题
Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
C
Cisco Blogs
V
V2EX
P
Privacy & Cybersecurity Law Blog
Cisco Talos Blog
Cisco Talos Blog

Ahmad Shadeed

Better fluid sizing with round() Use Cases for Field Sizing The Basics of Anchor Positioning Item Flow CSS Relative Colors Balancing Text In CSS Should masonry be part of CSS grid? CSS display contents CSS Grid Areas CSS Cap Unit An Interactive Guide to CSS Container Queries CSS :has() Interactive Guide CSS Nesting UX in DevTools CSS Nesting Future CSS: State Container Queries Rebuilding a comment component with modern CSS Conditional CSS with :has and :nth-last-child CSS Text balancing with text-wrap:balance CSS Masking Do we need CSS flex-wrap detection? My CSS Wishlist Conditional CSS CSS Style Queries Inside the mind of a frontend developer: Article layout Inside the mind of a frontend developer: Hero section CSS container queries are finally here The CSS behind Figma First Look At The CSS object-view-box Property Learn CSS Subgrid CSS :has Parent Selector Aligning Content In Different Wrappers Flexbox Dynamic Line Separator Hello, CSS Cascade Layers Building UI Components With SVG and CSS A Deep CSS Dive Into Radial And Conic Gradients Defensive CSS Building Real-life Components: Facebook Messenger Conditional Border Radius In CSS CSS Container Query Units Less Absolute Positioning With Modern CSS Aligning a Button Label Vertically Comparing Design Mockups To Code Result Using HSL Colors In CSS Custom Scrollbars In CSS Let CSS Container Queries For Designers The State of CSS Cross-Browser Development Overflow Issues In CSS Inspect Element As A Way To Increase Your Curiosity Handling Text Over Images in CSS Digging Into CSS Logical Properties Clipping Scrollable Areas On The inline-start Side Understanding Clip Path in CSS The Art of Building Real-life Components Handling Short And Long Content In CSS CSS Scroll Snap A Deep Dive Into CSS Grid minmax() CSS Variables 101 Finding The Root Cause of a CSS Bug Learn CSS centering How to detect browser support for Flexbox Gap CSS Mistakes While On Autopilot Digging Into the Flex Property Understanding CSS Multiple Backgrounds Aligning Logo Images in CSS Grid for layout, Flexbox for components Colors in CSS Thinking About The In-between Design Cases min(), max(), and clamp() CSS Functions Image Techniques On The Web Everything About Auto in CSS Learn Box Alignment Let Learn CSS Positioning Intrinsic Sizing In CSS CSS Grid Template Areas In Action Hiding Elements On The Web Creating a Variable Color Font From Scratch Building a Football Ticket With CSS and SVG Blending Modes in CSS CSS Variables With Inline Styles Implementing Dark Mode For My Website Rebuilding Apple Music Header in HTML & CSS Accessible Checkbox Layout Flickering On Browser Resize Custom Underlines with SVG Part 3: The Process of Implementing A UI Design From Scratch Part 2: The Process of Implementing A UI Design From Scratch Building An Old Nav Design CSS Flexbox: 5 Real World Use Cases I Used CSS Inline Flex For The First Time The Process of Implementing A UI Design From Scratch Common CSS Issues For Front-End Projects Handling Long and Unexpected Content in CSS How to Build Web Form Layouts With CSS Grid Grid Layout Ah-ha Moment Enhancing Our Components with CSS :empty Building Resizeable Components with Relative CSS Units CSS Writing Mode The Journey of Learning Front End Web Development on a Daily Basis
Enhancing The Clickable Area Size
Ahmad Shadeed · 2019-08-13 · via Ahmad Shadeed

The Layout Maestro

I spent years teaching CSS layout on this blog. I put everything I know into The Layout Maestro course: 70+ lessons and 150+ interactive examples that teach you how to think CSS layouts, not just memorize syntax.

Get the course

Have you ever tried to click or tap on an element (e.g.: button, link) and you realize that it doesn’t respond until you click on a specific area of it?

This happens because the clickable area is not applied to the whole element. To make it more clear, see the below figure. I made some examples of how the clickable area should and shouldn’t be.

For this article, I will go through different examples that I notice a lot and show how to solve them properly.

UX Considerations

WCAG Guidelines

As per WCAG 2.1, the minimum target size for touch or mouse should be 44×44 pixel. The size is not fixed and it could change depending on the use case. However, 44×44 pixel is a good starting point.

Fitts’ law

An important law to be followed in UX design. In simple words, the larger and closer the touch or click target is, the less time it will require the user to interact with it.

In the below figure, I mocked two different cases for a primary button. On the left side, the button is smaller and farther which will require more time for the user to interact with it. On the right side, the button size is larger and closer to its sibling input element, which will make it easier and faster to interact with.

Let’s get to actual examples and keep WCAG 2.5.5 Target Size and Fitts’ law in mind.

Buttons

It’s very important to use an actual <button> when you need it. The example below is from an online banking system I use:

<div class="navig next" onclick="validateLogin()">Next</div>

Here is a GIF image for the above button’s HTML. I’m hovering on the button and the cursor is still a pointer, which is fine. However, I can also select the text and when hovering, there is a text cursor! This won’t happen if the correct element were used.

When using the HTML <button> element, you will gain the below for free:

  • Accessible via mouse, keyboard or touch
  • Can be selected by keyboard
  • Javascript free

Once the correct element is used, you need to add enough padding for two reasons:

  • Let the button breath!
  • Make it larger so it can be easy to be noticed (Fitts’ law).

I made this mistake in the past and I see it in the wild. When there is a navigation menu, the padding should be given to the <a> element and not the <li>.

<nav>
  <ul>
    <li class="nav-item"><a href="#">Home</a></li>
    <li class="nav-item"><nav href="#">Products</nav></li>
    <li class="nav-item"><a href="#">Store</a></li>
    <li class="nav-item"><a href="#">Team</a></li>
  </ul>
</nav>
.nav-item {
  padding: 12px 16px;
}

Based on the above HTML and CSS, the clickable area will be the text only. Check the below figure:

The correct way to do this is to add the padding on the link itself. Notice that the top and bottom padding won’t work by default since it’s an inline element. It can be block or inline-element or flex, whatever works for your case.

.nav-item a {
  display: block;
  padding: 12px 16px;
}

As a result, the whole link is now clickable/tappable. Here is a figure that shows the difference:

Or Kebab? whatever you call it. It’s important to increase the clickable area for them as mostly they will be used on touch devices.

Let’s suppose that the clickable area is as below:

This is not good and will make it hard to point the mouse or finger at such a small target on the screen. While in the below figure, it’s larger and much easier to interact with.

Check out this demo on CodePen.

Checkboxes and Radio Buttons

When there is a checkbox or a radio button element, I expect that I can click on it or the associated label to activate/inactivate it.

In the below figure, the clickable area is tied to the checkbox or radio elements only. In other words, you cannot click on the label to active/inactivate it.

This is inaccessible and bad from a user experience perspective. In HTML, you can tie the label with an input using the for attribute.

<input type="checkbox" id="option1" />
<label for="option1">Option 1</label>

or you can place the input inside the label:

<label for="option1">
  Option 1
  <input type="checkbox" id="option1" />
</label>

Then, you will need to add padding on the <label> element so the clickable area become larger. That way, the issue is solved and the whole checkbox or radio button is clickable such as the below figure:

For a page with categories, sometimes I notice that the list links doesn’t expand to the full width of its parent. That means, the clickable area is on the text only.

The below figure shows that:

The fix for this is to:

  • Remove the padding from the <li> element and instead, move it to the <a> element (Discussed this in the links point).
  • Make the link take the full width of its parent by adding display: block.
.nav-item a {
  /*Other styles*/
  padding: 12px 16px;
  display: block;
}

Curious to see how it looks after the above little CSS addition?

Real-life example

In a recent Twitter update, the navigation design has an issue in the clickable area size. At first, it was tied to the text only, as in the below screenshot, but they got it fixed after receiving feedback.

In some cases, there is a need to add a “See more” button or arrow on the far side of a section header. In the below example, I placed the arrow in a fake circle so I can center the arrow correctly.

Typically, the spacing around the arrow can be done in CSS using padding, or a width and height.. Whatever work for your case.

Using Pseudo Elements to Increase The Clickable Area

It’s not always possible to make the clickable area larger by just changing the width and height of an element or using padding. Well, pseudo elements to the rescue!

How it works?

The idea is that a pseudo element belongs to its parent, so when we create one with a specific width and height, it will act as a click/touch/hover area of its parent.

In the below figure, I added an :after pseudo element to the menu button. Here is the CSS used:

.menu-2:after {
  content: "";
  position: absolute;
  left: 55px;
  top: 0;
  width: 50px;
  height: 50px;
  background: #e83474;
  /*Other styles*/
}

Notice that I intentionally positioned the square 55px to the left of its parent for explaining purposes. When that square is positioned in the center of its parent, it will increase the touch target. Goal achieved!!

See the below GIF or check out the demo on Codepen.

The clickable area and target sizes guide

A screenshot of the target sizes interactive guide

On 10 January 2024, I published a complete guide on designing better clickable areas and target sizes. It explains everything you need with lots of examples and interactive demos. See the interactive guide about target sizes

The End

And that’s a wrap. I wrote down most of the examples I know. Do you have a comment or a suggestion? Please feel free to ping me on @shadeed9.

Thank you for reading.