{"id":1012,"date":"2026-12-04T15:00:03","date_gmt":"2026-12-04T15:00:03","guid":{"rendered":"https:\/\/html-editor-online.com\/blog?p=1012"},"modified":"2026-12-04T15:00:03","modified_gmt":"2026-12-04T15:00:03","slug":"css-selector-cheat-sheet","status":"publish","type":"post","link":"https:\/\/html-editor-online.com\/blog\/css-selector-cheat-sheet\/","title":{"rendered":"CSS Selector Cheat Sheet: Common Selectors, Combinators and Pseudo-Classes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This css selector cheat sheet answers one question: which selector do you write to target a given element? The input is a stylesheet rule, the output is the set of elements that rule matches, and you can check simple rules in the live preview of the <a href=\"https:\/\/html-editor-online.com\/editors\/css\" title=\"CSS Editor\">CSS Editor<\/a>. Below you get one-line examples for type, class, ID, attribute, combinator, pseudo-class and pseudo-element selectors, a short specificity note, and a workflow for testing a rule and then tidying the stylesheet. Treat it as a css selector cheatsheet to scan rather than read top to bottom. The examples show syntax only. A rule has a visible effect only when matching markup exists on the page.<\/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=\"#css-selector-cheat-sheet-which-selector-fits-the-task-1\">CSS selector cheat sheet: which selector fits the task?<\/a><\/li><li class=\"\"><a href=\"#combinators-in-the-css-selector-cheat-sheet-descendant-child-and-siblings-2\">Combinators in the CSS selector cheat sheet: descendant, child and siblings<\/a><\/li><li class=\"\"><a href=\"#pseudo-classes-and-pseudo-elements-state-position-and-parts-of-an-element-3\">Pseudo-classes and pseudo-elements: state, position and parts of an element<\/a><\/li><li class=\"\"><a href=\"#specificity-in-one-paragraph-how-to-compare-matching-selectors-4\">Specificity in one paragraph: how to compare matching selectors<\/a><\/li><li class=\"\"><a href=\"#test-a-selector-in-the-css-editor-then-tidy-it-with-the-css-beautifier-5\">Test a selector in the CSS Editor, then tidy it with the CSS Beautifier<\/a><\/li><li class=\"\"><a href=\"#selector-mistakes-to-check-before-you-blame-the-browser-6\">Selector mistakes to check before you blame the browser<\/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-cheat-sheet-image-1-967-1-8406a949a6e29101-1024x576.jpg\" alt=\"Illustration of an organized reference sheet with shapes sorted into zones, representing a CSS selector cheat sheet\" class=\"wp-image-1015\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-1-967-1-8406a949a6e29101-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-1-967-1-8406a949a6e29101-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-1-967-1-8406a949a6e29101-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-1-967-1-8406a949a6e29101.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"css-selector-cheat-sheet-which-selector-fits-the-task-1\">CSS selector cheat sheet: which selector fits the task?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start here when you know what you want to style but not how to write the selector. Each row gives a one-line rule you can paste into a stylesheet.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Selector kind<\/th><th>Example<\/th><th>What it matches<\/th><\/tr><\/thead><tbody><tr><td>Type<\/td><td><code>p { color: navy; }<\/code><\/td><td>Every paragraph element.<\/td><\/tr><tr><td>Universal<\/td><td><code>* { box-sizing: border-box; }<\/code><\/td><td>All elements.<\/td><\/tr><tr><td>Class<\/td><td><code>.notice { color: navy; }<\/code><\/td><td>Elements that have the class <code>notice<\/code>.<\/td><\/tr><tr><td>ID<\/td><td><code>#summary { color: navy; }<\/code><\/td><td>The element with that ID. IDs should be unique within a document.<\/td><\/tr><tr><td>Attribute presence<\/td><td><code>a&#091;title&#093; { text-decoration: underline; }<\/code><\/td><td>Links that have a <code>title<\/code> attribute.<\/td><\/tr><tr><td>Attribute value<\/td><td><code>input&#091;type=\"email\"&#093; { border-color: navy; }<\/code><\/td><td>Inputs whose <code>type<\/code> is exactly <code>email<\/code>.<\/td><\/tr><tr><td>Attribute prefix<\/td><td><code>a&#091;href^=\"https:\"&#093; { color: navy; }<\/code><\/td><td>Links whose <code>href<\/code> begins with that string.<\/td><\/tr><tr><td>Selector list<\/td><td><code>h1, h2 { color: navy; }<\/code><\/td><td>Either an <code>h1<\/code> or an <code>h2<\/code>, with one shared rule.<\/td><\/tr><tr><td>Compound<\/td><td><code>button.btn { font-weight: bold; }<\/code><\/td><td>A <code>button<\/code> element that also has the class <code>btn<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A quick way to choose: use a type selector for a baseline style on every element of one kind, a class when several elements share a look, and an ID when exactly one element needs a hook. Classes are usually the more reusable choice because many elements can carry the same one, while an ID can appear only once in a valid document.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Attribute selectors fit cases where the markup already carries the information you need, such as the input type or the start of a link address. They save you from adding an extra class, but they depend on the attribute staying as written. The universal selector is handy for resets, though it matches everything, so keep its declarations small.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The last two rows are easy to mix up. A comma creates a selector list: each part is evaluated on its own and the rule applies to anything that matches either one. Writing two selectors with no space and no comma, as in <code>button.btn<\/code>, creates a compound selector that requires both conditions on the same element.<\/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-cheat-sheet-image-2-967-2-37f42e6e3301858c-1024x576.jpg\" alt=\"Conceptual illustration of a branching tree of nodes showing parent, child and sibling relationships between page elements\" class=\"wp-image-1017\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-2-967-2-37f42e6e3301858c-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-2-967-2-37f42e6e3301858c-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-2-967-2-37f42e6e3301858c-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-2-967-2-37f42e6e3301858c.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"combinators-in-the-css-selector-cheat-sheet-descendant-child-and-siblings-2\">Combinators in the CSS selector cheat sheet: descendant, child and siblings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A combinator describes the relationship between two selectors. Four are worth memorizing, and each one answers a different question about where the target sits in the document tree.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Descendant<\/strong> (a space): <code>.card p { color: navy; }<\/code> matches paragraphs anywhere inside a card, however deeply nested.<\/li>\n\n\n\n<li><strong>Child<\/strong> (<code>&gt;<\/code>): <code>.card &gt; p { color: navy; }<\/code> matches only paragraphs that are direct children of the card.<\/li>\n\n\n\n<li><strong>Next sibling<\/strong> (<code>+<\/code>): <code>h2 + p { margin-top: 0; }<\/code> matches a paragraph immediately following a heading under the same parent.<\/li>\n\n\n\n<li><strong>Subsequent sibling<\/strong> (<code>~<\/code>): <code>h2 ~ p { color: navy; }<\/code> matches later paragraph siblings of the heading, not just the next one.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These pairs cause most of the confusion, so here they are side by side with the compound and list forms:<\/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=\"\">\/* One element that meets two conditions *\/\nbutton.btn { font-weight: bold; }\n\n\/* A .btn element anywhere inside any button *\/\nbutton .btn { font-weight: bold; }\n\n\/* A list of two selectors, not a relationship *\/\nh1, h2 { color: navy; }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The distinctions to remember:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.card p<\/code> permits intervening elements, so a paragraph inside a div inside the card still matches. <code>.card &gt; p<\/code> does not, because the paragraph must be a direct child.<\/li>\n\n\n\n<li><code>h2 + p<\/code> requires immediate adjacency. A paragraph that comes after another element, even a small one, is skipped. <code>h2 ~ p<\/code> does not require adjacency but still requires the same parent.<\/li>\n\n\n\n<li><code>button.btn<\/code> matches one element that meets two conditions. <code>button .btn<\/code> instead matches a descendant, and that single space changes the meaning completely.<\/li>\n\n\n\n<li>A comma makes a selector list. It never describes a relationship between elements.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For a longer walkthrough of how <code>CSS descendant<\/code> and sibling relationships read, the MDN page on <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\">CSS selectors and combinators<\/a> covers the full set, including the column combinator and other less common forms. I keep the main sheet to the four above because they cover most everyday stylesheets.<\/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-cheat-sheet-image-3-967-3-fce4c7a013b3b4c7-1024x576.jpg\" alt=\"Illustration contrasting a hover state with a highlighted first line of text, representing pseudo-classes and pseudo-elements\" class=\"wp-image-1019\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-3-967-3-fce4c7a013b3b4c7-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-3-967-3-fce4c7a013b3b4c7-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-3-967-3-fce4c7a013b3b4c7-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/css-selector-cheat-sheet-image-3-967-3-fce4c7a013b3b4c7.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"pseudo-classes-and-pseudo-elements-state-position-and-parts-of-an-element-3\">Pseudo-classes and pseudo-elements: state, position and parts of an element<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both kinds of selector use a colon, but they select different things. A pseudo-class selects an element that is in a particular state or position. A pseudo-element selects a part of an element, and current syntax writes it with two colons.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>State<\/strong>: <code>a:hover { text-decoration: underline; }<\/code> matches a link while the pointer is over it.<\/li>\n\n\n\n<li><strong>Position<\/strong>: <code>li:first-child { font-weight: bold; }<\/code> matches a list item only when it is the first child of its parent.<\/li>\n\n\n\n<li><strong>Part of an element<\/strong>: <code>p::first-line { font-weight: bold; }<\/code> styles the first formatted line of a paragraph.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>li:first-child<\/code> rule is a good example of why position matters. If a list item is the second child of its parent, the rule does not match it, even when it looks like the first item on the screen. The selector asks about the parent&#8217;s child order, not about visual order. If the first child of a list is something other than a list item, no list item will match.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A pseudo-element such as <code>::first-line<\/code> does not match a separate element in the markup. It styles a piece of the paragraph that the browser works out when it lays the text out, so the styled part changes when the container width changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Attribute matching has one more subtlety. Whether a comparison such as <code>input&#091;type=\"email\"&#093;<\/code> is case-sensitive depends on the attribute and on the document language, so do not assume every attribute value comparison behaves the same way. The MDN <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Attribute_selectors\" title=\"Attribute selectors - CSS | MDN\" target=\"_blank\" rel=\"noopener\">attribute selectors reference<\/a> explains the matching modes, and it is worth reading before you write a rule that depends on letter case.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you need a full list, use the MDN <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Pseudo-classes\" title=\"Pseudo-classes - CSS | MDN\" target=\"_blank\" rel=\"noopener\">pseudo-classes reference<\/a> and the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Pseudo-elements\" title=\"Pseudo-elements - CSS | MDN\" target=\"_blank\" rel=\"noopener\">pseudo-elements reference<\/a>. The W3C <a href=\"https:\/\/www.w3.org\/TR\/selectors-4\/\" title=\"Selectors Level 4\" target=\"_blank\" rel=\"noopener\">Selectors Level 4<\/a> document defines the selectors formally, but it is a Working Draft dated January 22, 2026, so use it for definitions rather than as proof that every feature has identical browser support. Check MDN compatibility information before relying on a newer selector.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"specificity-in-one-paragraph-how-to-compare-matching-selectors-4\">Specificity in one paragraph: how to compare matching selectors<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When two rules match the same element and set the same property, compare their specificity. Count the parts of each selector in three columns, written ID-class-type. Here are a few examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>#summary<\/code> is 1-0-0.<\/li>\n\n\n\n<li><code>.card p<\/code> is 0-1-1.<\/li>\n\n\n\n<li><code>p::first-line<\/code> is 0-0-2.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Attribute selectors and ordinary pseudo-classes count in the class column, so <code>a&#091;href^=\"https:\"&#093;<\/code> and <code>li:first-child<\/code> are both 0-1-1. Pseudo-elements count in the type column, which is why <code>p::first-line<\/code> is 0-0-2. Combinators and the universal selector add no weight at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a comparison tool, not a rule that the highest number always wins. The browser considers the cascade origin, whether a declaration is marked important, and cascade layers before it ever looks at selector specificity. When two declarations are still tied after that, the one that appears later in the stylesheet wins. The MDN <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Guides\/Cascade\/Specificity\" title=\"Specificity - CSS | MDN\" target=\"_blank\" rel=\"noopener\">specificity guide<\/a> sets out the full order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A few modern selectors do not follow the simple counting above. <code>:where()<\/code> contributes zero specificity, while <code>:is()<\/code>, <code>:not()<\/code> and <code>:has()<\/code> take their specificity from their arguments. That difference explains puzzling results, and I walk through one in a separate article on why a <a href=\"https:\/\/html-editor-online.com\/blog\/css-where-specificity-rule-not-applying\/\" title=\"CSS Where Specificity Rule Not Applying\">CSS rule inside :where() can lose to a plain element selector<\/a>. I keep these exceptions out of the main sheet because most everyday rules use the simple forms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a rule is not applying, check these in order: does the selector match the element at all, is a later or more specific rule setting the same property, and is the declaration valid? Specificity only matters once the first question has a yes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"test-a-selector-in-the-css-editor-then-tidy-it-with-the-css-beautifier-5\">Test a selector in the CSS Editor, then tidy it with the CSS Beautifier<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a short workflow that uses only documented behavior of the site&#8217;s editors. The CSS Editor offers syntax highlighting, property auto-completion, a live preview on a sample page and beautify or minify. It has no linting, so it will not warn you about a selector that matches nothing.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the CSS Editor, enter <code>.container &gt; h1 { color: rebeccapurple; }<\/code> and inspect the live preview.<\/li>\n\n\n\n<li>Replace it with <code>a:hover { text-decoration: underline; }<\/code> and hover the sample link in the preview.<\/li>\n\n\n\n<li>When you need your own markup, switch to the <a href=\"https:\/\/html-editor-online.com\/editors\/html\" title=\"HTML Code Editor\">HTML Code Editor<\/a> and put the CSS in a style element next to the markup it targets.<\/li>\n\n\n\n<li>Paste the finished stylesheet into the <a href=\"https:\/\/html-editor-online.com\/tools\/css_beautifier\" title=\"CSS Beautifier\">CSS Beautifier<\/a>, click beautify, then copy or download the formatted result.<\/li>\n\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">As checked on November 29, 2026, the CSS Editor preview uses a fixed sample page. That means selectors for elements absent from it, such as <code>input&#091;type=\"email\"&#093;<\/code> or <code>li:first-child<\/code>, cannot be demonstrated there. For those, use a small test page in the HTML Code Editor, which has a sandboxed live preview:<\/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  .card &gt; p { color: rebeccapurple; }\n  li:first-child { font-weight: bold; }\n  input&#091;type=&quot;email&quot;&#093; { border-color: navy; }\n&lt;\/style&gt;\n\n&lt;div class=&quot;card&quot;&gt;\n  &lt;p&gt;Direct child, styled&lt;\/p&gt;\n  &lt;div&gt;&lt;p&gt;Nested paragraph, not styled&lt;\/p&gt;&lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;ul&gt;\n  &lt;li&gt;First item, bold&lt;\/li&gt;\n  &lt;li&gt;Second item&lt;\/li&gt;\n&lt;\/ul&gt;\n\n&lt;label&gt;Email &lt;input type=&quot;email&quot;&gt;&lt;\/label&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check that only the direct-child paragraph changes color, only the first list item is bold, and the email field is the only input affected. That visual check confirms the selectors match what you intended. The HTML Code Editor has no validator, so it will not flag a markup mistake that causes a selector to miss.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Beautifying is a formatting step. The CSS Beautifier makes indentation and spacing readable, but it does not validate or repair incorrect CSS, and it does not necessarily normalize spacing inside selectors. Compare the rendered result before and after, and keep the original source. If you want the broader picture of previewing styles, the article on 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 in the browser<\/a> covers what a live preview can and cannot show.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"selector-mistakes-to-check-before-you-blame-the-browser-6\">Selector mistakes to check before you blame the browser<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most selector problems are a matching problem, a priority problem or a syntax problem. They need different checks, and a clean-looking preview proves only one of them.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>No matching element<\/strong>: the selector is valid but the markup lacks what it targets. This happens often in the CSS Editor because its preview is a fixed sample page.<\/li>\n\n\n\n<li><strong>Wrong combinator<\/strong>: <code>.card p<\/code> reaches nested paragraphs and <code>.card &gt; p<\/code> does not. Swap the combinator and see which paragraphs change.<\/li>\n\n\n\n<li><strong>Missing or extra space<\/strong>: <code>.menu :focus<\/code> and <code>.menu:focus<\/code> mean different things. The first matches focused descendants of the menu, the second matches a menu that is itself focused.<\/li>\n\n\n\n<li><strong>Overridden declaration<\/strong>: another rule matches the same element with higher specificity or comes later. Compare the three-column counts from the specificity section.<\/li>\n\n\n\n<li><strong>Typo in a property or value<\/strong>: the selector matches, but the declaration is invalid and the browser ignores it. The CSS Editor has no linting, so check by sight.<\/li>\n\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The space example matters when you minify. The space in <code>.menu :focus<\/code> is a descendant combinator, so a tool that removes it changes the meaning of the rule. I wrote up a real case where a <a href=\"https:\/\/html-editor-online.com\/blog\/css-minifier-removes-space-before-focus\/\" title=\"CSS Minifier Removes Space Before Focus\">CSS minifier can remove the space before :focus<\/a>, and it is a good reminder to compare the minified output with the source before you ship it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep these checks separate. Formatting makes a stylesheet readable, syntax correctness means the browser can parse each rule, and matching means the selector hits the elements you intended. Visual equivalence in a preview is evidence for matching on one page, not proof that a selector behaves correctly across every page that uses the stylesheet.<\/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 the difference between .card p and .card &gt; p?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">.card p is a descendant selector, so it matches paragraphs at any depth inside a card. .card &gt; p is a child selector and matches only paragraphs that are direct children of the card. A paragraph wrapped in an extra div inside the card matches the first rule but not the second.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-2\">What is the difference between h2 + p and h2 ~ p?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">h2 + p matches a paragraph that immediately follows an h2 under the same parent. h2 ~ p matches every later paragraph sibling of that h2, even with other elements between them. Both require the same parent, so neither reaches into nested containers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-3\">Is button.btn the same as button .btn?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. button.btn has no space and matches one button element that also has the class btn. button .btn has a space, so it matches any element with the class btn that sits inside a button. A comma, as in h1, h2, makes a selector list instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-4\">How do I work out the specificity of a selector?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Count IDs, then classes, attributes and pseudo-classes, then types and pseudo-elements. For example, #summary is 1-0-0, .card p is 0-1-1 and p::first-line is 0-0-2. Combinators and the universal selector add nothing. Origin, importance and layers are considered before specificity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-5\">Are attribute selectors case-sensitive?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It depends. Whether an attribute value comparison is case-sensitive depends on the attribute and on the document language, so do not assume it always is. Test the exact markup you use, and read the MDN attribute selectors reference for the matching modes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-6\">Why does my selector show no change in the CSS Editor preview?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The preview uses a fixed sample page, so a selector for an element that page does not contain, such as input&#091;type=&#8221;email&#8221;&#093; or li:first-child, has nothing to match. Put the CSS in a style element in the HTML Code Editor alongside your own markup to test it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-7\">Does the CSS Beautifier fix or validate my selectors?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The CSS Beautifier improves indentation and spacing only. It does not validate or repair incorrect CSS, and it does not necessarily normalize spacing inside selectors. Check the rendered result yourself and keep your original source.<\/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\">Keep this css selector cheat sheet next to your stylesheet and reach for the row that matches the relationship you need: a type, class, ID or attribute for the element itself, a combinator for its place in the tree, and a pseudo-class or pseudo-element for state, position or a part of it. Remember that specificity compares only rules that already match and have survived the earlier cascade steps. For your next step, open the CSS Editor, try <code>.container &gt; h1<\/code> and <code>a:hover<\/code> in the preview, and use the HTML Code Editor for any selector the fixed sample page cannot show.<\/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-where-specificity-rule-not-applying\/\">CSS Where Specificity Rule Not Applying<\/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\/tools\/css_beautifier\">CSS 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\/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-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\/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:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Pseudo-classes\" target=\"_blank\" rel=\"noopener\">Pseudo-classes &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Pseudo-elements\" target=\"_blank\" rel=\"noopener\">Pseudo-elements &#8211; CSS | MDN<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Attribute_selectors\" target=\"_blank\" rel=\"noopener\">Attribute selectors &#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\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/css_beautifier\">CSS Beautifier<\/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>A CSS selector cheat sheet with one-line examples for type, class, ID, attribute, combinator and pseudo-class selectors, plus a quick way to test them.<\/p>\n","protected":false},"author":1,"featured_media":1013,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[328,342,329,73,343,69,118],"class_list":["post-1012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css-editor","tag-css-beautifier","tag-css-cheat-sheet","tag-css-combinators","tag-css-editor","tag-css-pseudo-classes","tag-css-selectors","tag-css-specificity"],"_links":{"self":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/1012","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=1012"}],"version-history":[{"count":4,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/1012\/revisions"}],"predecessor-version":[{"id":1020,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/1012\/revisions\/1020"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media\/1013"}],"wp:attachment":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media?parent=1012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/categories?post=1012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/tags?post=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}