I’m trying to make a settings page with HTML and CSS. The single settings have a label on the left side and an interactive element / multiple interactive elements on the right side.
I don’t know which HTML tag is best for the single settings with the label on the left and the interactive elements on the right.
I also don’t know how I can semantically correct group and label the interactive counter element (plus and minus button and span for current value).
I don’t want to use only divs for grouping elements, but I’m not sure what the correct HTML tags for this use case are.
My HTML written:
<section>
<h1>Settings</h1>
<div>
<span>Automation</span>
<button>Start automation</button>
</div>
<div>
<span>Number of votes</span>
<div>
<button>-</button>
<span>5</span>
<button>+</button>
</div>
</div>
<div>
<span>Max votes on card</span>
<div>
<button>-</button>
<span>3</span>
<button>+</button>
</div>
</div>
</section>
I tried to write semantically correct HTML for my settings but I’m struggling to find the correct tags etc.
2
Answers
There are multiple semantic improvements to raise accessibility.
First of all, you should use a semantic list for settings or options:
<menu>
.Then wrap all "rows" into
<li>
list items which will create rows by default.If you have a
<button>
then you also should use alabel
connected to it so that screen readers know what the button is for. A<span>
is not an appropriate replacement.If you have 2 buttons for incrementing and decrementing, then you should use the
role="spinbutton
which exists for exactly the case. The official documentation that I linked also states that aninput type="number"
could be used but does not specifically say that it should be favored. For further explanations about the other attributes such asaria-labelledby
,tabindex
, andaria-valuenow
you should read the same documentation. Note that the documentation also specifically states that thearia-valuenow
needs to be updated with JS.The reason why
input type="number"
does not specifically raise accessibility even though being a semantic tag is the usage of screen readers and how those users use those inputs. The advantage ofinput type="number"
is that they have a default incremation and decremation button. However users that abuse assistive technology do not use mcies but the keyboard to navigate. They do not increment or decrement by clicking those buttons but by updating the value with a keyboard input such as typing the number in it directly. Also note, that you need thearia-valuemin
andaria-valuemax
to set limits to that "input" element.Consider using
<fieldset>
and<legend>
elements to group input elements and provide those groups with captions. Note that fieldset elements need to belong to a<form>
, so you’ll need to include that as well, along with an appropriatemethod
attribute (which I’ve omitted).Without knowing more context, I’d recommend replacing the plus/minus buttons and numbers with a native
<input type="number>
element. It will make it easier for users to input a number directly (rather than having to increment or decrement repetitively to it), can be displayed in different ways by user agents to better suit the user’s input method, has built-in logic for controlling min and max values, and will likely be more quickly understood by users of assistive tech.Your markup could look something like the below. CSS can be added to make it look more like the screenshot you shared, if desired.