title: Add required asterisk to label before required form input with CSS
body: <p>I attempted to do this with a CSS selector like <code>label::after + input:required</code> but the asterisk doesn't show up. Here's a full example:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div {
    margin: 10px;
  }
  
  label,
  input {
    display: inline-block;
    width: 100px;
  }
  
  label::after+input:required {
    content: "*";
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    &lt;div&gt;
      &lt;label for="name"&gt;First name&lt;/label&gt;
      &lt;input id="name" name="name" type="text" required&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;label for="email"&gt;Email&lt;/label&gt;
      &lt;input id="email" name="email" type="email"&gt;
    &lt;/div&gt;
    &lt;button&gt;Submit&lt;/button&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Also, I did some research and all the reasonable solutions I found involve adding a &quot;required&quot; class to the label. This works but it violates DRY and adds additional potential for error since I could forget to add the class to a required field's label.</p>
  <p>Is there a way to do this without any changes to the HTML?</p>