Skip to content

feat: add addImportantToPseudoClasses option - #670

Merged
cossssmin merged 1 commit into
masterfrom
feat/important-pseudo-classes
Sep 24, 2026
Merged

cossssmin merged 1 commit into
masterfrom
feat/important-pseudo-classes

Conversation

@cossssmin

Copy link
Copy Markdown
Collaborator

Closes #383

Rules with pseudo-classes like :hover can't be inlined, so Juice keeps them in a <style> tag, but then the element's inlined styles win over them and the hover state never shows:

<style>.link { color: red; } .link:hover { color: green; }</style>
<a class="link">x</a>

The new addImportantToPseudoClasses option (off by default, as discussed in the issue) adds !important to the declarations in those rules:

<style>
.link:hover {
  color: green !important;
}
</style><a class="link" style="color: red;">x</a>

What it covers

  • rules using a pseudo-class from juice.ignoredPseudos (:hover, :active, :focus, :visited, :link, plus any you add), also inside @media and nested &:hover
  • every <style> tag in the output: preserved rules, style tags kept with removeStyleTags: false, removeInlinedSelectors mode, and preserved extraCss
  • declarations that are already !important aren't doubled

What it leaves alone

  • data-embed style tags
  • pseudo-elements (::first-letter etc., also in the legacy :first-letter form), since inline styles don't override them
  • the rest of the CSS: it's parsed without the nesting plugin and only rewritten when something changed

It runs as a single pass over the output's <style> tags at the end of juiceDocument, and costs nothing when the option is off.

Also available as --add-important-to-pseudo-classes on the CLI, typed in index.d.ts, and documented in the README's options table.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cossssmin
cossssmin merged commit 294d0aa into master Sep 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for pseudo tags

1 participant