mozilla

Revision 293089 of :required

  • Revision slug: CSS/:required
  • Revision title: :required
  • Revision id: 293089
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The :required CSS pseudo-class represents any {{ HTMLElement("input") }} element that has the {{ htmlattrxref("required", "input") }} attribute set on it. This allows forms to easily indicate which fields must have valid data before the form can be submitted.

The {{ cssxref(":optional") }} pseudo-class may be used to provide an appearance for optional form fields.

Examples

See {{ cssxref(":invalid") }} for an example.

Specifications

Specification Status Comment
{{ SpecName('HTML WHATWG', '#selector-required', ':required') }} {{ Spec2('HTML WHATWG') }} No change.
{{ SpecName('HTML5 W3C', '#selector-required', ':required') }} {{ Spec2('HTML5 W3C') }} Defines the semantic regarding HTML and constraint validation.
{{ SpecName('CSS4 Selectors', '#opt-pseudos', ':required') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 UI', '#pseudo-required-value', ':required') }} {{ Spec2('CSS3 UI') }} Defines the pseudo-class, but not the associated semantic.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 10.0 {{ CompatGeckoDesktop("2") }} 10 10.0 5.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatGeckoMobile("2") }} {{ CompatNo() }} 10.0 5.0

See also

  • {{ cssxref(":optional") }}, {{ cssxref(":invalid") }}, {{ cssxref(":valid") }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>:required</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents any {{ HTMLElement("input") }}&nbsp;element that has the {{ htmlattrxref("required", "input") }} attribute set on it. This allows forms to easily indicate which fields must have valid data before the form can be submitted.</p>
<p>The {{ cssxref(":optional") }} pseudo-class may be used to provide an appearance for optional form fields.</p>
<h2 id="Examples">Examples</h2>
<p>See {{ cssxref(":invalid") }} for an example.</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('HTML WHATWG', '#selector-required', ':required') }}</td>
      <td>{{ Spec2('HTML WHATWG') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML5 W3C', '#selector-required', ':required') }}</td>
      <td>{{ Spec2('HTML5 W3C') }}</td>
      <td>Defines the semantic regarding HTML and constraint validation.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS4 Selectors', '#opt-pseudos', ':required') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 UI', '#pseudo-required-value', ':required') }}</td>
      <td>{{ Spec2('CSS3 UI') }}</td>
      <td>Defines the pseudo-class, but not the associated semantic.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>10.0</td>
        <td>{{ CompatGeckoDesktop("2") }}</td>
        <td>10</td>
        <td>10.0</td>
        <td>5.0</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatGeckoMobile("2") }}</td>
        <td>{{ CompatNo() }}</td>
        <td>10.0</td>
        <td>5.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ cssxref(":optional") }}, {{ cssxref(":invalid") }}, {{ cssxref(":valid") }}</li>
</ul>
Revert to this revision