Sub topic 7
Making tap targets large enough
A tap target is the area of the screen that responds when the user touches it. It is often larger or smaller than what the user sees. This chapter covers the minimum sizes, what Flutter's Material widgets do for you, and where you must add size yourself. It assumes you know the Semantics basics from earlier chapters, can build layouts with Row and Padding, and can run flutter test.
Why size matters
Small targets cause missed taps and accidental taps on a neighbor. They affect many users: people with tremors or limited dexterity, people using one hand on a moving bus, and anyone with large fingers. Switch and screen reader users are affected less, because they activate controls by focus instead of by touch.
The common guidelines are expressed in density-independent units, so they hold across screens.
| Source | Minimum size | Note |
|---|---|---|
| Android / Material | 48 x 48 dp | Flutter exposes this as `kMinInteractiveDimension` |
| iOS Human Interface Guidelines | 44 x 44 pt | Flutter's logical pixel is the same unit |
| WCAG 2.2, criterion 2.5.8 (AA) | 24 x 24 CSS px | Allows smaller targets if spacing prevents overlap |
| WCAG 2.2, criterion 2.5.5 (AAA) | 44 x 44 CSS px | Stricter target |
A practical rule: make every interactive element at least 48 x 48 logical pixels. That satisfies all four rows.
Visual size and hit area are separate
A 24-pixel icon can sit inside a 48-pixel hit area. The user sees the small icon, and the larger area catches the tap.
Padding is the usual way to get there. The catch is that the hit area must actually be part of the widget that listens for the tap. Padding placed outside the listener does nothing for touch.
What Material widgets already do
Most Material buttons are padded to 48 dp by default on mobile, even when they look smaller.
IconButtonhas a 48 x 48 minimum. The icon is 24 dp by default.TextButton,ElevatedButtonandOutlinedButtonare about 40 dp tall visually, but their tap target is padded to 48 dp.Checkbox,RadioandSwitchuse the same padding.
Two settings shrink these targets, and both are easy to apply by accident:
ThemeData.materialTapTargetSizeset toMaterialTapTargetSize.shrinkWrapremoves the padding. Flutter's own default ispaddedon mobile andshrinkWrapon desktop platforms.VisualDensity.compact(also a desktop default) reduces the size of many controls.
You can also opt out for a single widget with style: ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap). Do that only where another mechanism guarantees spacing, and keep it off mobile screens.
Custom tappable widgets get no minimum
GestureDetector and InkWell hit-test only the area of their child. A bare 24 dp icon inside a GestureDetector has a 24 dp target. You must supply the size.
The widget below enforces the minimum for any child. It can be dropped into a project as lib/tap_targets.dart.
import 'package:flutter/material.dart';
class MinTapTarget extends StatelessWidget {
const MinTapTarget({
super.key,
required this.label,
required this.onTap,
required this.child,
});
final String label;
final VoidCallback onTap;
final Widget child;
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: const BoxConstraints(
minWidth: kMinInteractiveDimension,
minHeight: kMinInteractiveDimension,
),
child: Semantics(
button: true,
label: label,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: Center(
widthFactor: 1,
heightFactor: 1,
child: child,
),
),
),
);
}
}
class TagRow extends StatelessWidget {
const TagRow({super.key});
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('flutter'),
MinTapTarget(
label: 'Remove tag flutter',
onTap: () {},
child: const Icon(Icons.close, size: 20),
),
],
);
}
}Three details matter here:
ConstrainedBoxraises the size to 48 dp but never shrinks a larger child, so a big button stays big.CenterwithwidthFactorandheightFactorof 1 sizes itself to the child first, then the constraint enlarges it. Without the factors,Centerwould expand to fill any bounded width, for example inside aColumn.HitTestBehavior.opaquemakes the whole 48 dp box respond. With the defaultdeferToChild, only the pixels that belong to the child count, and the empty area around the icon ignores touches.
Often the simplest option is to use IconButton and style it. The earlier example in this tutorial shows that approach with a tooltip, which also provides the accessibility label.
Spacing and other gotchas
- Adjacent targets: two 48 dp buttons with no gap are fine. Two 24 dp targets side by side are not, because a tap between them is ambiguous. Keep targets from overlapping, and leave a few pixels between them when you can.
- Overlapping hit areas: if padded boxes overlap, the widget painted on top wins. Check the order in a
Stack. - Text links: an inline link in a paragraph is usually shorter than 48 dp. WCAG 2.2 exempts inline text, but a standalone link such as "Forgot password?" should be wrapped in a padded
TextButton. - Large text: when the user raises the text scale, a button grows with its label. Use minimum constraints, never a fixed
height: 48, so growth is not clipped. A later chapter covers this in detail. - Dense lists: a
ListTileis tappable across its whole row, so it is rarely a problem. Trailing icons inside it are the usual offenders. - Tooltips and labels: a bigger target helps touch users only. Every target still needs a label for screen readers.
Checking with a widget test
Manual inspection misses things, so let the test framework measure. flutter_test ships guidelines that walk the semantics tree and measure each tappable node. Semantics must be switched on first, which is what ensureSemantics does.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:a11y_demo/tap_targets.dart';
void main() {
testWidgets('tag row has large enough targets', (tester) async {
final handle = tester.ensureSemantics();
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: Center(child: TagRow()))),
);
await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
await expectLater(tester, meetsGuideline(iOSTapTargetGuideline));
await expectLater(tester, meetsGuideline(labeledTapTargetGuideline));
handle.dispose();
});
}Replace a11y_demo with your package name. If you swap MinTapTarget for a bare GestureDetector around the 20 dp icon, the Android and iOS guidelines fail and the message names the offending node with its measured size.
Keep in mind what these guidelines do not cover:
- They test the semantics node's rectangle, so a target that looks large but has
deferToChildhit testing still passes. Verify real hit areas by tapping in the test:await tester.tapAt(...)on the padded edge. - They check only widgets that expose a tap or long-press action. A control built from raw
Listenerwidgets with no semantics is invisible to them. - Tests run at the default 800 x 600 test surface and 1.0 text scale. Set
tester.view.physicalSizeandtester.platformDispatcher.textScaleFactorTestValueto exercise other conditions.
Exercise
A teammate wraps a 24 dp Icon in Padding(padding: EdgeInsets.all(12)) and then in a GestureDetector with the default behavior. The padded box measures 48 x 48, but users report that taps near the edge of the box do nothing. Why, and how do you fix it?
Show answer
The GestureDetector is the outer widget, but with the default HitTestBehavior.deferToChild it responds only where its child is hit. Padding has no hit-testable area of its own, so the 12 dp ring is ignored. Set behavior: HitTestBehavior.opaque on the GestureDetector so its whole 48 x 48 box responds, or use IconButton, which handles this for you. The tap target guideline would still pass in this case because it measures the semantics rectangle, so confirm the fix with a tester.tapAt on the padding.