Skip to content
WordPressRule: label•Reviewed Oct 2026

Associate form inputs with accessible labels in WordPress

Form inputs must have a programmatic `<label>` element connected via `for` and `id` attributes.

What's wrong

Inputs that rely exclusively on `placeholder` attributes lose their label once a user begins typing, leaving screen readers disoriented.

Who it affects

Screen reader users, people with cognitive impairments, and speech-input users cannot reliably fill out newsletter, contact, or checkout forms.

How to fix on WordPress

Ensure all form inputs in theme search forms, comment sections, or form plugins have a matching `<label for="field-id">` paired with `<input id="field-id">`.

Code example

Problematic Code
PHP
<input type="search" class="search-field" name="s" placeholder="Search products...">
Recommended Accessible Code
PHP
<label for="search-field-<?php echo esc_attr( uniqid() ); ?>" class="screen-reader-text">
  <?php esc_html_e( 'Search products', 'textdomain' ); ?>
</label>
<input
  id="search-field-<?php echo esc_attr( uniqid() ); ?>"
  type="search"
  class="search-field"
  name="s"
  placeholder="<?php esc_attr_e( 'Search products...', 'textdomain' ); ?>"
>

How to check your fix

Click directly on the text label. The browser should immediately move focus into the corresponding form field.

Check if your site has this issue

Scan any public store page free against WCAG 2.2 AA in 30 seconds.

Your session has ended

Sign in again to carry on. Anything you typed on this page is kept.

Signed in another way? Use another method (opens a new tab)