Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions bindings/c/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions bindings/java/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions bindings/javascript/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.1] - 2025-12-29

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions bindings/php/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

- Initial public release
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions bindings/ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Inline `!important` styles being overwritten by stylesheet `!important` styles. [#637](https://github.com/Stranger6667/css-inline/issues/637)

## [0.19.0] - 2025-12-29

### Added
Expand Down
11 changes: 7 additions & 4 deletions css-inline/src/html/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,14 @@ fn merge_styles<Wr: Write>(
}),
) {
// The new rule is `!important` and there's an existing rule with the same name
// In this case, we override the existing rule with the new one
// Only override if the existing inline rule is NOT `!important`.
// Per CSS spec: inline `!important` takes precedence over stylesheet `!important`
(Some(value), Some(buffer)) => {
// We keep the rule name and the colon-space suffix - '<rule>: `
buffer.truncate(property.len().saturating_add(STYLE_SEPARATOR.len()));
write_declaration_value(buffer, value)?;
if !buffer.ends_with(b"!important") {
// We keep the rule name and the colon-space suffix - '<rule>: `
buffer.truncate(property.len().saturating_add(STYLE_SEPARATOR.len()));
write_declaration_value(buffer, value)?;
}
}
// There's no existing rule with the same name, but the new rule is `!important`
// In this case, we add the new rule with the `!important` suffix removed
Expand Down
12 changes: 12 additions & 0 deletions css-inline/tests/test_inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ fn important_more_specific() {
);
}

#[test]
fn important_inline_wins_over_stylesheet_important() {
// Inline `!important` rules should override stylesheet `!important` rules.
// Per CSS spec: "Inline important styles take precedence over all other important author styles"
// See: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/important#inline_styles
assert_inlined!(
style = "h1 { color: blue !important; }",
body = r#"<h1 style="color: red !important;">Big Text</h1>"#,
expected = r#"<h1 style="color: red !important">Big Text</h1>"#
);
}

#[test]
fn font_family_quoted() {
// When property value contains double quotes
Expand Down
Loading