:last-child

  • Revision slug: CSS/:last-child
  • Revision title: :last-child
  • Revision id: 308809
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The :last-child CSS pseudo-class represents any element that is the last child element of its parent.

Syntax

element:last-child { style properties }

Examples

span:last-child {
    background-color: lime;
}

...where...

<div>
  <span>This span is not limed.</span>
  <span>This span is! :)</span>
</div>

... should look like ...
This span is not limed. This span is! :)

Specifications

Specification Status Comment
{{ SpecName('CSS4 Selectors', '#last-child', ':last-child') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 Selectors', '#last-child', ':last-child') }} {{ Spec2('CSS3 Selectors') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 9.0 9.5 3.2
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{ CompatGeckoMobile("1") }} 9.0 10.0 3.2

See also

  • {{cssxref(":first-child")}}
  • {{cssxref(":nth-child()")}}

Revision Source

<div>{{ CSSRef() }}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>:last-child</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents any element that is the last child element of its parent.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="syntaxbox">element:last-child { <em>style properties</em> }</pre>

<h2 id="Examples">Examples</h2>
<pre class="brush: css">
span:last-child {
    background-color: lime;
}
</pre>
<p>...where...</p>
<pre class="brush: html">
&lt;div&gt;
  &lt;span&gt;This span is not limed.&lt;/span&gt;
  &lt;span&gt;This span is!&nbsp;:)&lt;/span&gt;
&lt;/div&gt;</pre>

<p>... should look like ...<br />
  <span>This span is not limed.</span> <span style="background-color: lime;">This span is!&nbsp;:)</span></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('CSS4 Selectors', '#last-child', ':last-child') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 Selectors', '#last-child', ':last-child') }}</td>
      <td>{{ Spec2('CSS3 Selectors') }}</td>
      <td>Initial definition.</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>1.0</td>
        <td>{{ CompatGeckoDesktop("1") }}</td>
        <td>9.0</td>
        <td>9.5</td>
        <td>3.2</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>2.1</td>
        <td>{{ CompatGeckoMobile("1") }}</td>
        <td>9.0</td>
        <td>10.0</td>
        <td>3.2</td>
      </tr>
    </tbody>
  </table>
</div>

<h2 id="See_also" name="See_also">See also</h2>
<ul>
<li>{{cssxref(":first-child")}}</li>
<li>{{cssxref(":nth-child()")}}</li>
</ul>
Revert to this revision