Small SEO Tools

Why an ID Selector Changes After CSS Minification

If a rule stops styling an element after CSS minification, compare the selector with the original HTML ID. A sequence such as #aabbcc can represent a color in a declaration and an ID in a selector. Shortening it has different consequences in those two positions.

Reproduce the changed selector

Use these two elements on a local test page. Their IDs are intentionally different.

<p id="aabbcc">Intended label</p>
<p id="abc">Other label</p>

The original rule targets the first element.

#aabbcc { color: #aabbcc; }
  1. Open the CSS Minifier and paste the original rule into Paste your CSS.
  2. Leave the default options selected, including Shorten hex colours, and press Minify CSS.
  3. Compare the selector before the opening brace as well as the color after the colon.

The current tool produces the following output.

#abc{color:#abc}

The color becomes shorter, but so does the selector. On this test page, the candidate applies the color to Other label instead of Intended label. If no element has the shorter ID, that candidate rule has no matching element.

Separate ID matching from color notation

An ID selector matches an element with the corresponding identifier. The HTML ID aabbcc and the HTML ID abc name different targets. The browser does not expand a short ID as if it were a color. CSS ID selector matching

Inside the color declaration, #abc expands to the same RGB color as #aabbcc. Each short hex digit is repeated to form its full pair. That color equivalence applies to the declaration value in this example. CSS hexadecimal color notation

Both versions parse as CSS. In a local browser check with the two IDs, the original and minified rules selected different elements while producing the same RGB color on their respective targets.

Rerun the original with hex shortening disabled

Return to the original rule, untick Shorten hex colours, and press Minify CSS again. Leave the other options as they were for this comparison.

#aabbcc{color:#aabbcc}

This output preserves the intended selector and retains the longer color spelling. Test that candidate by itself on the local page. In the browser check, it restored the original target and its computed color.

Keep the HTML IDs fixed during the comparison. Renaming an element to fit the damaged selector can also affect links or scripts that use its original ID. Preserve the intended relationship between the stylesheet and the markup.

Review the affected stylesheet before replacing it

Search the candidate for selectors that differ from the original, especially IDs that resemble hexadecimal colors. Inspect the applied rule and computed style on the intended element. Also check any element that could accidentally match a shortened ID.

Disabling this option resolves the demonstrated transformation. Other rules still need their own checks. The stylesheet comparison guide covers additional calculation and selector-spacing cases before deployment.