{"id":982,"date":"2026-12-01T15:00:02","date_gmt":"2026-12-01T15:00:02","guid":{"rendered":"https:\/\/html-editor-online.com\/blog?p=982"},"modified":"2026-12-01T15:00:02","modified_gmt":"2026-12-01T15:00:02","slug":"css-descendant-selector-sibling","status":"publish","type":"post","link":"https:\/\/html-editor-online.com\/blog\/css-descendant-selector-sibling\/","title":{"rendered":"CSS Descendant Selector and Sibling Selectors: Target Nested Elements Without Extra Classes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A css descendant selector is two selectors separated by whitespace, such as <code>.container p<\/code>. It matches every <code>p<\/code> element at any depth inside an element with the class <code>container<\/code>, so you can style nested content without adding a class to each node. The child combinator (<code>&gt;<\/code>), the adjacent sibling combinator (<code>+<\/code>) and the general sibling combinator (<code>~<\/code>) narrow that relationship.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The input here is plain CSS and the output is a visual change in a preview. You can paste the sample rules into the <a href=\"https:\/\/html-editor-online.com\/editors\/css\" title=\"CSS Editor\">CSS Editor<\/a>, which previews CSS against a fixed sample page. Because you cannot paste your own HTML into that preview, I also show how to test a custom markup structure and when a long chain of combinators becomes a maintenance problem.<\/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=\"#how-a-css-descendant-selector-relates-elements-in-the-document-tree-1\">How a CSS descendant selector relates elements in the document tree<\/a><\/li><li class=\"\"><a href=\"#descendant-versus-child-combinator-2\">Descendant versus child combinator<\/a><\/li><li class=\"\"><a href=\"#sibling-selector-css-adjacent-and-general-3\">Sibling selector CSS: adjacent (+) and general (~)<\/a><\/li><li class=\"\"><a href=\"#paste-ready-rules-to-test-in-the-css-editor-4\">Paste-ready rules to test in the CSS Editor<\/a><\/li><li class=\"\"><a href=\"#test-your-own-markup-with-the-html-code-editor-and-html-beautifier-5\">Test your own markup with the HTML Code Editor and HTML Beautifier<\/a><\/li><li class=\"\"><a href=\"#specificity-and-the-difference-from-css-nesting-6\">Specificity and the difference from CSS nesting<\/a><\/li><li class=\"\"><a href=\"#when-a-css-descendant-selector-helps-and-when-it-hurts-maintenance-7\">When a CSS descendant selector helps and when it hurts maintenance<\/a><\/li><li class=\"\"><a href=\"#checks-when-a-combinator-does-not-match-8\">Checks when a combinator does not match<\/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-descendant-selector-image-1-941-1-7f492bb51aa58402-1024x576.jpg\" alt=\"Branching tree of nodes illustrating how a css descendant selector reaches elements at any depth\" class=\"wp-image-985\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-1-941-1-7f492bb51aa58402-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-1-941-1-7f492bb51aa58402-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-1-941-1-7f492bb51aa58402-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-1-941-1-7f492bb51aa58402.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"how-a-css-descendant-selector-relates-elements-in-the-document-tree-1\">How a CSS descendant selector relates elements in the document tree<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A combinator is the part of a selector that states how two elements relate in the document tree. Browsers parse HTML into a tree of parents, children and siblings, and combinators let a rule follow those relationships instead of depending on a class for every element. MDN documents the four combinators on its <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Guides\/Selectors\/Selectors_and_combinators\" title=\"CSS selectors and combinators - CSS | MDN\" target=\"_blank\" rel=\"noopener\">selectors and combinators<\/a> page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The descendant combinator is a single space. In <code>.container p<\/code>, the left side finds elements with the class <code>container<\/code>, and the right side keeps only the <code>p<\/code> elements that sit anywhere below them. A paragraph that is a direct child matches. A paragraph inside a <code>div<\/code> inside the container matches too. The depth does not matter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That tolerance is the main strength of a descendant css selector. If a developer later wraps part of the content in an extra <code>div<\/code> for layout, the rule keeps working. The same tolerance is also the main risk, because it can reach elements you did not plan to style, such as a paragraph inside a nested widget.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The space matters. <code>.container p<\/code> means a paragraph inside the container. <code>.container.p<\/code> would mean one element that has both classes, which is a different selector. Reading a selector from right to left helps: the rightmost part is the element that gets styled, and everything to its left is a condition on its ancestors or siblings.<\/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-descendant-selector-image-2-941-2-af75ea39065accf9-1024x576.jpg\" alt=\"Two node trees comparing descendant matching at every depth with child matching one level down\" class=\"wp-image-987\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-2-941-2-af75ea39065accf9-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-2-941-2-af75ea39065accf9-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-2-941-2-af75ea39065accf9-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-2-941-2-af75ea39065accf9.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"descendant-versus-child-combinator-2\">Descendant versus child combinator<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The child combinator <code>&gt;<\/code> is the strict version. <code>.container &gt; p<\/code> matches only paragraphs whose parent is the container itself. A paragraph wrapped in another element no longer matches, even though it is still inside the container.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Selector<\/th><th>Matches<\/th><\/tr><\/thead><tbody><tr><td><code>.container p<\/code><\/td><td>Paragraphs at any depth inside the container<\/td><\/tr><tr><td><code>.container &gt; p<\/code><\/td><td>Paragraphs that are direct children of the container<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Both selectors have the same specificity, 0-1-1, because combinators add no weight. The difference is only in which elements they select. Use the child combinator when the relationship is part of the design, for example a list where only the top-level items get a border. Use the descendant form when you want a rule to apply to a kind of content regardless of wrappers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A practical habit: start with the descendant form, then switch to <code>&gt;<\/code> only when a rule leaks into nested content that should look different. That keeps selectors short and gives you a clear reason for the stricter version.<\/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-descendant-selector-image-3-941-3-569485acf39b9a7b-1024x576.jpg\" alt=\"Row of blocks showing an adjacent sibling highlighted next to a sibling selector css target\" class=\"wp-image-989\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-3-941-3-569485acf39b9a7b-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-3-941-3-569485acf39b9a7b-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-3-941-3-569485acf39b9a7b-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-descendant-selector-image-3-941-3-569485acf39b9a7b.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sibling-selector-css-adjacent-and-general-3\">Sibling selector CSS: adjacent (+) and general (~)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sibling combinators relate elements that share the same parent. They look only forward in the source order, so the element on the right must come after the element on the left.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>h2 + p<\/code> is the adjacent sibling combinator. It matches a paragraph that comes immediately after an <code>h2<\/code> with the same parent. MDN describes it on its <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Next-sibling_combinator\" title=\"Next-sibling combinator - CSS | MDN\" target=\"_blank\" rel=\"noopener\">next-sibling combinator<\/a> page.<\/li>\n\n\n\n<li><code>h2 ~ p<\/code> is the general sibling combinator. It matches every following paragraph that shares the parent with the heading, whether or not another element sits in between.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Whitespace and comments between the two elements in the HTML do not break an adjacent match. What breaks it is another element in between, or a different parent. A paragraph nested inside a <code>div<\/code> is not a sibling of a heading that sits outside that <code>div<\/code>, so neither <code>+<\/code> nor <code>~<\/code> reaches it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The sibling selector css pattern suits content flows: a lead paragraph after a heading, spacing between a heading and the text that follows, or a rule that applies to everything after a divider. It is fragile when authors can insert elements freely, because adding one element between the heading and its paragraph stops <code>+<\/code> from matching. There is no backward-looking sibling combinator in this group, so you cannot select the element before another one with <code>+<\/code> or <code>~<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"paste-ready-rules-to-test-in-the-css-editor-4\">Paste-ready rules to test in the CSS Editor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are four rules that each use a different relationship. They use plain CSS, so no preprocessor is involved.<\/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=\"\">.container p a { color: teal; }\n.container &gt; p { border-left: 3px solid teal; }\n.container h2 + p { background: #eee; }\n.container h2 ~ p { line-height: 2; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">What each rule does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.container p a<\/code> colors links that sit inside a paragraph inside the container. It chains two descendant relationships.<\/li>\n\n\n\n<li><code>.container &gt; p<\/code> adds a left border to direct child paragraphs only.<\/li>\n\n\n\n<li><code>.container h2 + p<\/code> gives a gray background to the paragraph right after a heading.<\/li>\n\n\n\n<li><code>.container h2 ~ p<\/code> increases line height for every later paragraph that shares the heading&#8217;s parent.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To try them, paste the rules into the CSS Editor and watch the live preview. The preview uses a fixed sample page, and I cannot promise which classes that page contains. If a rule changes nothing, the sample markup may simply have no <code>.container<\/code>. Replace <code>.container<\/code> with an element that exists on the page, then remove or swap one combinator at a time and compare which elements change. The editor offers syntax highlighting and property auto-completion but no linting, so a typo in a selector will not be flagged: it just matches nothing. The <a href=\"https:\/\/html-editor-online.com\/blog\/visual-css-editor-browser-live-preview\/\" title=\"Visual CSS Editor Browser Live Preview\">visual CSS editor guide<\/a> explains what the live preview can and cannot show.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"test-your-own-markup-with-the-html-code-editor-and-html-beautifier-5\">Test your own markup with the HTML Code Editor and HTML Beautifier<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you need your own structure, use the <a href=\"https:\/\/html-editor-online.com\/editors\/html\" title=\"HTML Code Editor\">HTML Code Editor<\/a>. It has a sandboxed live preview, so you can put the CSS in a <code>style<\/code> element in the same file. Here is a small fictitious page that makes each combinator visible:<\/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;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n  &lt;meta charset=&quot;utf-8&quot;&gt;\n  &lt;title&gt;Combinator test&lt;\/title&gt;\n  &lt;style&gt;\n    .container p a { color: teal; }\n    .container &gt; p { border-left: 3px solid teal; }\n    .container h2 + p { background: #eee; }\n    .container h2 ~ p { line-height: 2; }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=&quot;container&quot;&gt;\n    &lt;h2&gt;First heading&lt;\/h2&gt;\n    &lt;p&gt;Paragraph A with &lt;a href=&quot;#a&quot;&gt;a link&lt;\/a&gt;.&lt;\/p&gt;\n    &lt;p&gt;Paragraph B.&lt;\/p&gt;\n    &lt;div class=&quot;note&quot;&gt;\n      &lt;p&gt;Paragraph C with &lt;a href=&quot;#c&quot;&gt;a link&lt;\/a&gt;.&lt;\/p&gt;\n    &lt;\/div&gt;\n    &lt;h2&gt;Second heading&lt;\/h2&gt;\n    &lt;p&gt;Paragraph D.&lt;\/p&gt;\n  &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Work out the expected result before looking at the preview:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.container p a<\/code> colors the links in paragraphs A and C.<\/li>\n\n\n\n<li><code>.container &gt; p<\/code> borders A, B and D. Paragraph C is not a direct child because it sits inside <code>.note<\/code>.<\/li>\n\n\n\n<li><code>.container h2 + p<\/code> shades A and D, the paragraphs immediately after a heading.<\/li>\n\n\n\n<li><code>.container h2 ~ p<\/code> reaches A, B and D. Paragraph C has a different parent, so it is not a sibling of either heading.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If the preview disagrees with your prediction, the markup is usually nested differently than you think. Paste the HTML into the <a href=\"https:\/\/html-editor-online.com\/tools\/html_beautifier\" title=\"HTML Beautifier\">HTML Beautifier<\/a> to re-indent it so the parent and child levels are easy to read. Beautifying only changes layout. It does not validate or repair the markup, and the HTML Code Editor has no validator either, so an unclosed element can still change the tree without any warning.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"specificity-and-the-difference-from-css-nesting-6\">Specificity and the difference from CSS nesting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Combinators add no specificity. Only the simple selectors on either side count. <code>.container p<\/code> and <code>.container &gt; p<\/code> both score 0-1-1: one class and one element. <code>.container h2 + p<\/code> scores 0-1-2. MDN&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Guides\/Cascade\/Specificity\" title=\"Specificity - CSS | MDN\" target=\"_blank\" rel=\"noopener\">specificity<\/a> page explains how the three columns are compared.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This explains a common surprise: switching from a space to <code>&gt;<\/code> does not make a rule win a conflict, because the score is unchanged. If two rules tie, the later one wins. When a rule seems ignored, check element and class counts first. A related case is covered in <a href=\"https:\/\/html-editor-online.com\/blog\/css-where-specificity-rule-not-applying\/\" title=\"CSS Where Specificity Rule Not Applying\">why a rule inside :where() can lose to a plain element selector<\/a>, where a zero-specificity wrapper changes the outcome.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not confuse these relational selectors with CSS nesting. Nested css selectors in the strict sense means writing a rule inside another rule, which is a syntax feature for organizing stylesheets. A descendant selector is an ordinary selector that describes a relationship in the HTML. You can use one without the other, and a nested rule can itself contain combinators. Check the browser support you need before relying on the nesting syntax, since this article only covers the combinators.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On support: MDN marks the descendant and next-sibling combinators as widely available, with cross-browser availability since July 2015. That is a historical date, not a promise that every version behaves identically. The W3C <a href=\"https:\/\/www.w3.org\/TR\/selectors-4\/\" title=\"Selectors Level 4\" target=\"_blank\" rel=\"noopener\">Selectors Level 4<\/a> document lists all four combinators. As of November 26, 2026, its January 22, 2026 publication is a Working Draft rather than a Recommendation, but the combinators covered here are long-established behavior.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"when-a-css-descendant-selector-helps-and-when-it-hurts-maintenance-7\">When a CSS descendant selector helps and when it hurts maintenance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use a short selector anchored to a meaningful container when the markup relationship is stable. <code>.article p<\/code> or <code>.card &gt; h3<\/code> says what you mean and survives small edits. A good rule of thumb is that a selector should name the component or region, then one or two relationships inside it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Trouble starts with long chains tied to incidental wrappers:<\/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=\"\">\/* fragile: depends on every wrapper *\/\n.page .main .content div &gt; ul li a { color: teal; }\n\n\/* steadier: anchored to a component *\/\n.menu a { color: teal; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first rule breaks if someone adds or removes a wrapper, and it is hard to override because it carries more specificity than it needs. The second is short and easy to read. Here is how each combinator tends to fail:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&gt;<\/code> breaks when an extra wrapper is inserted between parent and child.<\/li>\n\n\n\n<li><code>+<\/code> and <code>~<\/code> break when elements are reordered or when something new appears between siblings.<\/li>\n\n\n\n<li>The plain descendant form survives wrappers but may match deeper elements than intended, such as links inside a nested widget.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A class is still the right tool when one specific element needs a distinct style, or when the same look is reused in different places. Combinators work best for styling content by its position in a flow, such as paragraphs in an article body. For a broader overview of editing and previewing stylesheets, see <a href=\"https:\/\/html-editor-online.com\/blog\/css-editors-web-development\/\" title=\"CSS Editors Web Development\">CSS editors for web development<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"checks-when-a-combinator-does-not-match-8\">Checks when a combinator does not match<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A clean preview shows only that a selector matched in that page. It does not prove the markup is valid, accessible or the same in every context. When a rule does nothing, work through these checks in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Confirm the ancestor exists. A typo in the class name, or a sample page that lacks it, means the left side matches nothing.<\/li>\n\n\n\n<li>Check the tree level. For <code>&gt;<\/code>, the element must be a direct child. Re-indent the HTML so the nesting is visible.<\/li>\n\n\n\n<li>Check the shared parent for <code>+<\/code> and <code>~<\/code>. The two elements must be siblings, and the second must come later in the source.<\/li>\n\n\n\n<li>Check for a tie or a stronger rule. Compare the 0-1-1 style scores and the source order.<\/li>\n\n\n\n<li>Isolate the rule. Keep only the failing selector and test it alone.<\/li>\n\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that formatting and minifying CSS do not change what a selector matches, but minifiers work on text and can interfere with significant whitespace. The descendant combinator is whitespace, so keep your original source and check the output. One reported case is described in <a href=\"https:\/\/html-editor-online.com\/blog\/css-minifier-removes-space-before-focus\/\" title=\"CSS Minifier Removes Space Before Focus\">a CSS minifier removing the space before :focus<\/a>, which shows how a changed space alters the selector&#8217;s meaning.<\/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 is a CSS descendant selector?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is two selectors separated by a space, such as .container p. It matches the right-hand element when it is anywhere inside an element matched by the left-hand selector, at any depth. It does not match the container itself.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-2\">What is the difference between a descendant css selector and a child selector?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The descendant form (.container p) matches paragraphs at any depth. The child form (.container &gt; p) matches only paragraphs whose direct parent is the container. Both have the same specificity, so the difference is only in which elements match.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-3\">How does the sibling selector css syntax work with + and ~?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">h2 + p matches a paragraph that immediately follows an h2 with the same parent. h2 ~ p matches every following paragraph that shares that parent, even with other elements in between. Both only look forward in source order.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-4\">Can a sibling selector target an earlier element?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Not with + or ~. They match the element on the right, which must come after the element on the left. If you need to style something based on what follows it, you need a different approach, such as adding a class in the markup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-5\">Do combinators change CSS specificity?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Combinators add no weight. Only the simple selectors on each side count, so .container p and .container &gt; p both score 0-1-1. Source order decides a tie.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-6\">Are nested css selectors the same as descendant selectors?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A descendant selector describes a relationship between elements in the HTML. CSS nesting is a syntax for writing one rule inside another. They are separate features, and a nested rule can contain a descendant selector.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-7\">Can I paste my own HTML into the CSS Editor preview?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The CSS Editor previews your CSS against a fixed sample page. To test your own markup, put the CSS in a style element inside the HTML Code Editor and use its sandboxed live preview. The HTML Beautifier can re-indent the markup, but it does not validate or repair it.<\/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\">A css descendant selector relates an element to any ancestor above it, the child combinator limits the match to direct children, and the two sibling combinators follow elements that share a parent in source order. Combinators add no specificity, so pick them for the relationship you mean, keep chains short and anchor them to a meaningful container. For your next step, paste the four sample rules into the CSS Editor, swap one combinator at a time, and tidy the result with the <a href=\"https:\/\/html-editor-online.com\/tools\/css_beautifier\" title=\"CSS Beautifier\">CSS Beautifier<\/a> when your stylesheet grows.<\/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\/tools\/html_beautifier\">HTML Beautifier<\/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:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Guides\/Selectors\/Selectors_and_combinators\" target=\"_blank\" rel=\"noopener\">CSS selectors and combinators &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.w3.org\/TR\/selectors-4\/\" target=\"_blank\" rel=\"noopener\">Selectors Level 4<\/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:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Next-sibling_combinator\" target=\"_blank\" rel=\"noopener\">Next-sibling combinator &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/html_beautifier\">HTML Beautifier<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Descendant_combinator\" target=\"_blank\" rel=\"noopener\">Descendant combinator &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/css\">CSS Editor<\/a><\/li>\n\n\n<\/ul>\n\n\n","protected":false},"excerpt":{"rendered":"<p>CSS descendant selector basics: learn how descendant, child and sibling combinators match nested elements, and test each rule in a live preview.<\/p>\n","protected":false},"author":1,"featured_media":983,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[329,73,69,118,330,331],"class_list":["post-982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css-editor","tag-css-combinators","tag-css-editor","tag-css-selectors","tag-css-specificity","tag-descendant-selector","tag-sibling-selectors"],"_links":{"self":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/982","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=982"}],"version-history":[{"count":4,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":990,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/982\/revisions\/990"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media\/983"}],"wp:attachment":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}