The CSS Selectors 4 Spec provides a syntax for defining the "subject" of a selector by using a !
. As of early-2016, this is not available in any browser. I'm including this because it will be the correct way to do this using pure CSS once browsers implement this syntax.
Given the markup in the question
<label for="username">Username:</label>
<input type="textbox" id="username" />
<label for="password">Password:</label>
<input type="textbox" id="password" />
This CSS would do the trick.
label:has(+ input:focus) {font-weight: bold}
Of course, this assumes browsers actually implement the subject selector and that there are no bugs related to how this syntax works with the :focus
pseudo-class.