Theming two instances of an input field in one form I have two instances of the Search form in one page. The search field needs to have different CSS classes in each instance.

Instance 1:

&lt;input type="text" class="form-control input-foo" placeholder="Search"&gt;


Instance 2:

&lt;input type="text" class="form-control input-bar" placeholder="Search"&gt;


All the relevant theme templates and preprocess functions that I can find to edit the classes output on the field, apply to both instances. E.g. input--search.html.twig.

For the time being I have instead applied a class on the block that each of these forms is contained in, but I'd like to know if there's another solution.
Is there a reason having the class on the input would be better than having it on the block? e.g. does it make some CSS/JS awkward by not being able to target the input directly? 

If not, having the class on the block seems like the ideal solution both in terms of ease-of-development and semantics...you want the search input to be styled based on where it is. That feels like a natural separation for a hierarchy of selectors: .block .input

If the blocks are in different regions, you could use the region class instead, which is there by default in most themes; that would avoid even having to alter the blocks themselves.