:optional

  • Revision slug: Web/CSS/:optional
  • Revision title: :optional
  • Revision id: 394609
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Moved From CSS/:optional to Web/CSS/:optional

Revision Content

{{ CSSRef() }}

Summary

The :optional CSS pseudo-class represents any {{ HTMLElement("input") }} element that does not have the {{ htmlattrxref("required","input") }} attribute set on it. This allows forms to easily indicate optional fields, and to style them accordingly.

To provide an appearance for required form fields, the {{ cssxref(":required") }} pseudo-class may be used.

Examples

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

Specifications

Specification Status Comment
{{ SpecName('HTML WHATWG', '#selector-optional', ':optional') }} {{ Spec2('HTML WHATWG') }} No change.
{{ SpecName('HTML5 W3C', '#selector-optional', ':optional') }} {{ Spec2('HTML5 W3C') }} Defines the semantic regarding HTML and constraint validation.
{{ SpecName('CSS4 Selectors', '#opt-pseudos', ':optional') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 UI', '#pseudo-required-value', ':optional') }} {{ 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(":required") }}
  • {{ cssxref(":invalid") }}
  • {{ cssxref(":valid") }}

{{ languages( { "fr": "fr/CSS/:optional" }) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>:optional</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents any {{ HTMLElement("input") }}&nbsp;element that does not have the {{ htmlattrxref("required","input") }} attribute set on it. This allows forms to easily indicate optional fields, and to style them accordingly.</p>
<p>To provide an appearance for required form fields, the {{ cssxref(":required") }} pseudo-class may be used.</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-optional', ':optional') }}</td>
      <td>{{ Spec2('HTML WHATWG') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML5 W3C', '#selector-optional', ':optional') }}</td>
      <td>{{ Spec2('HTML5 W3C') }}</td>
      <td>Defines the semantic regarding HTML and constraint validation.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS4 Selectors', '#opt-pseudos', ':optional') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 UI', '#pseudo-required-value', ':optional') }}</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(":required") }}</li>
  <li>{{ cssxref(":invalid") }}</li>
  <li>{{ cssxref(":valid") }}</li>
</ul>
<p>{{ languages( { "fr": "fr/CSS/:optional" }) }}</p>
Revert to this revision