{"id":994,"date":"2026-12-02T15:01:04","date_gmt":"2026-12-02T15:01:04","guid":{"rendered":"https:\/\/html-editor-online.com\/blog?p=994"},"modified":"2026-12-02T15:01:04","modified_gmt":"2026-12-02T15:01:04","slug":"css-selector-first-child-last-of-type","status":"publish","type":"post","link":"https:\/\/html-editor-online.com\/blog\/css-selector-first-child-last-of-type\/","title":{"rendered":"CSS Selector First Child, Last of Type, Even\/Odd and :not() Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A css selector first child rule, written as <code>li:first-child<\/code>, matches an <code>li<\/code> only when it is the first element child of its parent. Use <code>:last-of-type<\/code> for the last element of one tag among its siblings, <code>:nth-child(even)<\/code> and <code>:nth-child(odd)<\/code> for striping, and <code>:not()<\/code> to skip items such as a disabled one. The input is a small HTML list or table, and the output is a set of styled rows that you can predict before you test them. I build the markup in the HTML Code Editor and draft the rules in the <a href=\"https:\/\/html-editor-online.com\/editors\/css\" title=\"CSS Editor\">CSS Editor<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I also compare each selector with jQuery&#8217;s zero-based <code>eq()<\/code>, because that is where many readers arrive from. This is an evergreen tutorial: the selector behavior below follows the Selectors Level 4 Working Draft dated January 22, 2026, and the one newer syntax I show is flagged so you can check it against the browsers you target.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li class=\"\"><a href=\"#what-a-css-selector-first-child-rule-actually-tests-1\">What a CSS selector first child rule actually tests<\/a><\/li><li class=\"\"><a href=\"#build-the-test-list-in-the-html-code-editor-2\">Build the test list in the HTML Code Editor<\/a><\/li><li class=\"\"><a href=\"#predict-first-then-test-first-child-odd-even-and-not-3\">Predict first, then test :first-child, odd, even and :not()<\/a><\/li><li class=\"\"><a href=\"#css-selectors-last-of-type-versus-last-child-4\">CSS selectors last of type versus :last-child<\/a><\/li><li class=\"\"><a href=\"#the-not-selector-css-rule-and-its-specificity-5\">The not selector css rule and its specificity<\/a><\/li><li class=\"\"><a href=\"#table-rows-even-stripes-and-the-hidden-row-pitfall-6\">Table rows, even stripes and the hidden-row pitfall<\/a><\/li><li class=\"\"><a href=\"#pick-the-nth-item-the-way-jquerys-eq-does-7\">Pick the nth item the way jQuery&#039;s eq() does<\/a><\/li><li class=\"\"><a href=\"#which-selector-fits-css-selector-first-child-and-its-relatives-8\">Which selector fits: css selector first child and its relatives<\/a><\/li><li class=\"\"><a href=\"#frequently-asked-questions\">Frequently asked questions<\/a><\/li><li class=\"\"><a href=\"#next-steps\">Next steps<\/a><\/li><li class=\"\"><a href=\"#sources\">Sources and further reading<\/a><\/li><\/ul><\/nav><\/div>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-1-942-1-dc5af5f1ad909a85-1024x576.jpg\" alt=\"Illustration of sibling blocks in a row with the first one highlighted, representing a first-child selector\" class=\"wp-image-997\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-1-942-1-dc5af5f1ad909a85-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-1-942-1-dc5af5f1ad909a85-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-1-942-1-dc5af5f1ad909a85-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-1-942-1-dc5af5f1ad909a85.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"what-a-css-selector-first-child-rule-actually-tests-1\">What a CSS selector first child rule actually tests<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Structural selectors test an element&#8217;s position among its siblings in the document tree, not where it ends up on screen. Counting starts at 1, and only elements are counted, so whitespace between tags and text nodes never shift the numbers. Reordering items visually with CSS does not change their position in the tree either, so the selectors keep matching the source order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The detail that causes most mistakes is that <code>li:first-child<\/code> does not mean the first <code>li<\/code>, whatever comes before it. It matches an <code>li<\/code> only when that <code>li<\/code> is the first element child of its parent. If a heading sits before the first list item inside the same parent, no <code>li<\/code> in that parent is a first child.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The second common mistake is a stray space. Compare these two selectors:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">li:first-child { font-weight: 700; }\nli :first-child { font-weight: 700; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first targets the <code>li<\/code> itself. The second, with a space, targets any first-child element that is a descendant of an <code>li<\/code>, such as a <code>span<\/code> inside it. Omit the space when you mean the <code>li<\/code>. A related whitespace trap appears in my guide on <a href=\"https:\/\/html-editor-online.com\/blog\/css-minifier-removes-space-before-focus\/\" title=\"CSS Minifier Removes Space Before Focus\">why a CSS minifier removes the space before :focus<\/a>, which is a good reason to keep your readable source file after minifying.<\/p>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-2-942-2-db74ad33deaf5115-1024x576.jpg\" alt=\"Two-screen workspace illustrating markup in one editor and style rules in another\" class=\"wp-image-999\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-2-942-2-db74ad33deaf5115-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-2-942-2-db74ad33deaf5115-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-2-942-2-db74ad33deaf5115-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-2-942-2-db74ad33deaf5115.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"build-the-test-list-in-the-html-code-editor-2\">Build the test list in the HTML Code Editor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open the <a href=\"https:\/\/html-editor-online.com\/editors\/html\" title=\"HTML Code Editor\">HTML Code Editor<\/a> and paste the markup below. The editor offers syntax highlighting, auto-closing tags and a sandboxed live preview. It does not validate, so I check by eye that every tag is closed. The style element sits above the list so a single document holds both markup and rules.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;style&gt;\n  .list { max-width: 16rem; padding: 0; list-style: none; }\n  .list &gt; li { padding: 0.4rem 0.6rem; }\n&lt;\/style&gt;\n&lt;ul class=&quot;list&quot;&gt;\n  &lt;li&gt;One&lt;\/li&gt;\n  &lt;li&gt;Two&lt;\/li&gt;\n  &lt;li&gt;Three&lt;\/li&gt;\n  &lt;li class=&quot;disabled&quot;&gt;Four&lt;\/li&gt;\n&lt;\/ul&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Four items with one marked as disabled is enough to separate every selector in this article. The base rules only add spacing, so the preview should show four plain rows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The CSS Editor gives you syntax highlighting, property auto-completion and a live preview, but that preview uses a fixed sample page, so it will not show your list. The two editors do not share a live document. I draft rules in the CSS Editor, then paste the tested rules into the style element in the HTML Code Editor to compare them against the same markup. My guide to a <a href=\"https:\/\/html-editor-online.com\/blog\/visual-css-editor-browser-live-preview\/\" title=\"Visual CSS Editor Browser Live Preview\">visual CSS editor with a live preview and its limits<\/a> goes further into what that sample page can and cannot show.<\/p>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure class=\"alignright size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"169\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-3-942-3-3b182a6b4e656e49-300x169.jpg\" alt=\"Stack of four bars with alternating shades, one dimmed, illustrating odd, even and excluded list items\" class=\"wp-image-1001\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-3-942-3-3b182a6b4e656e49-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-3-942-3-3b182a6b4e656e49-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-3-942-3-3b182a6b4e656e49-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-first-child-image-3-942-3-3b182a6b4e656e49.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"predict-first-then-test-first-child-odd-even-and-not-3\">Predict first, then test :first-child, odd, even and :not()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the rules one at a time and say out loud which items you expect to change before you look at the preview. That habit is what makes the positions stick.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.list &gt; li:first-child { font-weight: 700; }\n.list &gt; li:nth-child(odd) { background: #e8f0fe; }\n.list &gt; li:nth-child(even) { background: #fdecea; }\n.list &gt; li:not(.disabled) { border-left: 4px solid #2563eb; }<\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>:first-child<\/strong> matches only One, because it is the first element child of the list.<\/li>\n\n\n\n<li><strong>:nth-child(odd)<\/strong> matches positions 1, 3, 5 and so on, so One and Three. It is the same as <code>2n+1<\/code>.<\/li>\n\n\n\n<li><strong>:nth-child(even)<\/strong> matches positions 2, 4, 6, so Two and Four. It is the same as <code>2n<\/code>.<\/li>\n\n\n\n<li><strong>:not(.disabled)<\/strong> matches every <code>li<\/code> without that class, so One, Two and Three. Four is excluded.<\/li>\n\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This css even odd selector pair covers every child exactly once, which is why it is the standard way to stripe rows. Rules can overlap: One is both first and odd. Different properties simply combine. If two matching rules set the same property, the one with higher specificity wins, and a tie goes to the later rule in the source.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"css-selectors-last-of-type-versus-last-child-4\">CSS selectors last of type versus :last-child<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The type-based pseudo-classes count only siblings with the same element name. That makes <code>:last-of-type<\/code> the right choice when different element types are mixed in one parent. Use this separate, valid example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;div class=&quot;post&quot;&gt;\n  &lt;p&gt;First&lt;\/p&gt;\n  &lt;p&gt;Second&lt;\/p&gt;\n  &lt;small&gt;Note&lt;\/small&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.post &gt; p:last-of-type { color: #b00020; }\n.post &gt; p:last-child { text-decoration: underline; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Second turns red, because it is the last <code>p<\/code> among the siblings, even though a <code>small<\/code> follows it. Nothing is underlined, because the last child of the div is the <code>small<\/code>, and the selector requires a <code>p<\/code> in that spot. Delete the <code>small<\/code> line and Second gets both styles, since the two selectors then agree.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same logic applies to <code>:first-of-type<\/code>. When your rules grow beyond a few lines, the <a href=\"https:\/\/html-editor-online.com\/tools\/css_beautifier\" title=\"CSS Beautifier\">CSS Beautifier<\/a> formats pasted CSS with clean indentation, which makes it easier to spot where two selectors overlap. It improves layout only, and it will not tell you whether a selector matches.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-not-selector-css-rule-and-its-specificity-5\">The not selector css rule and its specificity<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The not selector css form, <code>:not()<\/code>, excludes elements that match its argument. Scope it to an element type, as in <code>li:not(.disabled)<\/code>. A bare <code>:not(.disabled)<\/code> matches every element in the document that lacks the class, including <code>html<\/code>, <code>body<\/code> and wrappers, which is rarely what you want.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Specificity comes from the most specific argument inside the parentheses, not from an extra weight for the pseudo-class itself. So <code>li:not(.disabled)<\/code> scores 0-1-1: one class from the argument and one type selector. That is the same as <code>li.enabled<\/code>, and a rule such as <code>.list li<\/code> at 0-1-1 ties with it, leaving source order to decide.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a rule matches but still loses, the cause is nearly always the cascade, not the selector. My article on <a href=\"https:\/\/html-editor-online.com\/blog\/css-where-specificity-rule-not-applying\/\" title=\"CSS Where Specificity Rule Not Applying\">why a CSS :where rule loses to footer a<\/a> walks through scoring a matching rule that is outweighed, and the same method works for <code>:not()<\/code>. For an introduction, keep the argument to one simple selector. Complex or comma-separated arguments deserve their own compatibility check against the browsers you support.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"table-rows-even-stripes-and-the-hidden-row-pitfall-6\">Table rows, even stripes and the hidden-row pitfall<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Row striping is the classic use of <code>:nth-child(even)<\/code>. Select rows inside one row group so header rows do not shift the count. The HTML parser wraps loose rows in a <code>tbody<\/code>, so write the <code>tbody<\/code> explicitly and select <code>tbody &gt; tr<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;table&gt;\n  &lt;caption&gt;Team availability&lt;\/caption&gt;\n  &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;\/th&gt;&lt;th&gt;Status&lt;\/th&gt;&lt;\/tr&gt;&lt;\/thead&gt;\n  &lt;tbody&gt;\n    &lt;tr&gt;&lt;td&gt;Ana&lt;\/td&gt;&lt;td&gt;Open&lt;\/td&gt;&lt;\/tr&gt;\n    &lt;tr&gt;&lt;td&gt;Ben&lt;\/td&gt;&lt;td&gt;Busy&lt;\/td&gt;&lt;\/tr&gt;\n    &lt;tr hidden&gt;&lt;td&gt;Cy&lt;\/td&gt;&lt;td&gt;Away&lt;\/td&gt;&lt;\/tr&gt;\n    &lt;tr&gt;&lt;td&gt;Dee&lt;\/td&gt;&lt;td&gt;Open&lt;\/td&gt;&lt;\/tr&gt;\n  &lt;\/tbody&gt;\n&lt;\/table&gt;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tbody &gt; tr:nth-child(even) { background: #f1f5f9; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ben and Dee get the stripe. Cy is hidden but still occupies position 3, so Dee, the third visible row, counts as fourth and is striped as even. The visible stripes now break the alternating pattern. If you need a starting table, the <a href=\"https:\/\/html-editor-online.com\/tools\/html_table_generator\" title=\"HTML Table Generator\">HTML Table Generator<\/a> builds a table in a spreadsheet-style grid and lets you copy the markup. Check the copied output for the row grouping you need and adjust it by hand.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Selectors Level 4 draft shows <code>tr:nth-child(even of :not(&#091;hidden&#093;))<\/code> for exactly this case, counting only rows that are not hidden. MDN documents basic <code>:nth-child()<\/code> as widely available since July 2015 but cautions that support varies for parts of the syntax, so verify the <code>of<\/code> form against your target browsers before relying on it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pick-the-nth-item-the-way-jquerys-eq-does-7\">Pick the nth item the way jQuery&#039;s eq() does<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The jQuery documentation defines <code>.eq(index)<\/code> as an index into the matched set, starting at zero, so <code>.eq(2)<\/code> picks the third element of that set. A negative value such as <code>.eq(-2)<\/code> counts back from the end. CSS counts from one and counts siblings, not a matched set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>li:nth-child(3)<\/code> is therefore an analogue only when the items you care about are siblings under the same parent and their child positions line up with the set. It is not a general replacement for <code>.eq(2)<\/code> across several parents or a filtered set. Likewise <code>:nth-last-child(2)<\/code> is the sibling-based counterpart of <code>.eq(-2)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the set is the siblings that carry a class, the two forms differ. Take this markup:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;ul&gt;\n  &lt;li&gt;Intro&lt;\/li&gt;\n  &lt;li class=&quot;item&quot;&gt;A&lt;\/li&gt;\n  &lt;li class=&quot;item&quot;&gt;B&lt;\/li&gt;\n  &lt;li class=&quot;item&quot;&gt;C&lt;\/li&gt;\n&lt;\/ul&gt;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.item:nth-child(3) { color: #b00020; }\n:nth-child(3 of .item) { outline: 2px solid #2563eb; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>.item:nth-child(3)<\/code> tests whether an <code>.item<\/code> is third among all siblings, so it matches B. <code>:nth-child(3 of .item)<\/code> counts only the siblings that match <code>.item<\/code>, so it matches C, which is the true analogue of <code>.eq(2)<\/code> on that set. Treat the <code>of<\/code> form separately for browser support and check it before you ship it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"which-selector-fits-css-selector-first-child-and-its-relatives-8\">Which selector fits: css selector first child and its relatives<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Selector<\/th><th>Matches<\/th><th>Use it when<\/th><\/tr><\/thead><tbody><tr><td><code>.list &gt; li:first-child<\/code><\/td><td>An <code>li<\/code> that is its parent&#8217;s first element child<\/td><td>You know the first child is the item you want<\/td><\/tr><tr><td><code>.list &gt; li:last-of-type<\/code><\/td><td>The last <code>li<\/code> among siblings, even if another type follows<\/td><td>Different tags are mixed in one parent<\/td><\/tr><tr><td><code>.list &gt; li:nth-child(odd)<\/code><\/td><td>Positions 1, 3, 5<\/td><td>You want alternating stripes<\/td><\/tr><tr><td><code>.list &gt; li:nth-child(even)<\/code><\/td><td>Positions 2, 4, 6<\/td><td>You want the other half of the stripes<\/td><\/tr><tr><td><code>.list &gt; li:not(.disabled)<\/code><\/td><td>List items without that class<\/td><td>You need to skip one state<\/td><\/tr><tr><td><code>:nth-child(3 of .item)<\/code><\/td><td>The third sibling that matches <code>.item<\/code><\/td><td>You want an eq-style pick, after checking support<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A clean preview proves only that the rule matched this markup. To verify a selector properly, change the markup and see what moves:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Write down which items you expect to match before you look.<\/li>\n\n\n\n<li>Insert an extra element before the first item and confirm that <code>:first-child<\/code> stops matching.<\/li>\n\n\n\n<li>Add a different tag at the end and confirm that <code>:last-of-type<\/code> still matches while <code>:last-child<\/code> does not.<\/li>\n\n\n\n<li>Hide a row and check whether your stripes still alternate.<\/li>\n\n\n\n<li>Compare against any competing rule using the three-column specificity score.<\/li>\n\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Before minifying, keep a readable copy of your rules, since minification is a separate step that does not check selector logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-1\">What does the CSS selector first child (:first-child) match?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It matches an element only when that element is the first element child of its parent. Text and whitespace do not count, but an earlier element of any type does. So li:first-child fails if a heading comes before the first li inside the same parent.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-2\">What is the difference between :last-of-type and :last-child?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The :last-child pseudo-class requires the element to be the very last child of its parent. The :last-of-type pseudo-class only requires it to be the last sibling of its own tag. In a div containing two p elements followed by a small element, p:last-of-type matches the second p, while p:last-child matches nothing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-3\">How do I use the CSS even odd selector for striped rows?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use :nth-child(odd) and :nth-child(even) on the rows, for example tbody &gt; tr:nth-child(even). Odd matches positions 1, 3, 5 and even matches 2, 4, 6. Select rows inside one row group so header rows do not shift the count.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-4\">How does the not selector css work with classes?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The :not() pseudo-class matches elements that do not match its argument, so li:not(.disabled) matches every li without the disabled class. Scope it to an element type, because a bare :not(.disabled) matches many unrelated elements. Its specificity comes from its argument, so li:not(.disabled) scores 0-1-1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-5\">Is li:nth-child(3) the same as jQuery&#039;s .eq(2)?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Only in a narrow case. The eq() method indexes the matched set from zero, while nth-child counts sibling positions from one. They line up when the matched items are siblings under one parent and their positions align with the set. For a set of class-matching siblings, :nth-child(3 of .item) is closer, but check its browser support.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-6\">Why is my :first-child rule not applying?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Common causes are an earlier sibling element, an accidental space that turns li:first-child into li :first-child, or another matching rule with higher specificity. Check the markup order first, then the selector spacing, then compare specificity scores.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-7\">Does :nth-child(even) count hidden rows?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Hidden elements keep their positions in the document tree, so ordinary :nth-child(even) still counts them and can break visible stripes. The Selectors Level 4 draft shows tr:nth-child(even of :not(&#091;hidden&#093;)) for this case, but verify support for the of syntax in your target browsers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"next-steps\">Next steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The css selector first child rule, along with <code>:last-of-type<\/code>, <code>:nth-child(even)<\/code>, <code>:nth-child(odd)<\/code> and <code>:not()<\/code>, always asks a question about sibling position or class, never about what you see on screen. Pick <code>:first-child<\/code> when position among all siblings is the point, a type-based selector when tags are mixed, <code>nth-child<\/code> for stripes, and a scoped <code>:not()<\/code> to exclude a state. Your next step: paste the list from this article into the HTML Code Editor, add one rule at a time, then insert a stray element and a hidden row to see exactly which selectors break.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Related tools and resources on HTML Editor Online:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/css\">CSS Editor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/blog\/css-minifier-removes-space-before-focus\/\">CSS Minifier Removes Space Before Focus<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/html\">HTML Code Editor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/blog\/visual-css-editor-browser-live-preview\/\">Visual CSS Editor Browser Live Preview<\/a><\/li>\n\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sources\">Sources and further reading<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.jquery.com\/eq\/\" target=\"_blank\" rel=\"noopener\">.eq() | jQuery API Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Guides\/Cascade\/Specificity\" target=\"_blank\" rel=\"noopener\">Specificity &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.w3.org\/TR\/selectors\/\" target=\"_blank\" rel=\"noopener\">Selectors Level 4<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn_web_development\/Core\/Styling_basics\/Basic_selectors\" target=\"_blank\" rel=\"noopener\">Basic CSS selectors &#8211; Learn web development | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/html\">HTML Code Editor<\/a><\/li>\n\n\n<\/ul>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Use a CSS selector first child rule, last-of-type, even and odd striping and :not() correctly by testing each one on a real list and table.<\/p>\n","protected":false},"author":1,"featured_media":995,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[69,332,337,333,335,334,336],"class_list":["post-994","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css-editor","tag-css-selectors","tag-first-child","tag-jquery-eq-equivalent","tag-last-of-type","tag-not-selector","tag-nth-child","tag-table-row-striping"],"_links":{"self":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/comments?post=994"}],"version-history":[{"count":4,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":1002,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/994\/revisions\/1002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media\/995"}],"wp:attachment":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}