File tree Expand file tree Collapse file tree 9 files changed +47
-4
lines changed
Expand file tree Collapse file tree 9 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711### Added
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711### Added
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711### Added
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.1] - 2025-12-29
610
711### Fixed
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711- Initial public release
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711### Added
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Inline ` !important ` styles being overwritten by stylesheet ` !important ` styles. [ #637 ] ( https://github.com/Stranger6667/css-inline/issues/637 )
8+
59## [ 0.19.0] - 2025-12-29
610
711### Added
Original file line number Diff line number Diff line change @@ -557,11 +557,14 @@ fn merge_styles<Wr: Write>(
557557 } ) ,
558558 ) {
559559 // The new rule is `!important` and there's an existing rule with the same name
560- // In this case, we override the existing rule with the new one
560+ // Only override if the existing inline rule is NOT `!important`.
561+ // Per CSS spec: inline `!important` takes precedence over stylesheet `!important`
561562 ( Some ( value) , Some ( buffer) ) => {
562- // We keep the rule name and the colon-space suffix - '<rule>: `
563- buffer. truncate ( property. len ( ) . saturating_add ( STYLE_SEPARATOR . len ( ) ) ) ;
564- write_declaration_value ( buffer, value) ?;
563+ if !buffer. ends_with ( b"!important" ) {
564+ // We keep the rule name and the colon-space suffix - '<rule>: `
565+ buffer. truncate ( property. len ( ) . saturating_add ( STYLE_SEPARATOR . len ( ) ) ) ;
566+ write_declaration_value ( buffer, value) ?;
567+ }
565568 }
566569 // There's no existing rule with the same name, but the new rule is `!important`
567570 // In this case, we add the new rule with the `!important` suffix removed
Original file line number Diff line number Diff line change @@ -291,6 +291,18 @@ fn important_more_specific() {
291291 ) ;
292292}
293293
294+ #[ test]
295+ fn important_inline_wins_over_stylesheet_important ( ) {
296+ // Inline `!important` rules should override stylesheet `!important` rules.
297+ // Per CSS spec: "Inline important styles take precedence over all other important author styles"
298+ // See: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/important#inline_styles
299+ assert_inlined ! (
300+ style = "h1 { color: blue !important; }" ,
301+ body = r#"<h1 style="color: red !important;">Big Text</h1>"# ,
302+ expected = r#"<h1 style="color: red !important">Big Text</h1>"#
303+ ) ;
304+ }
305+
294306#[ test]
295307fn font_family_quoted ( ) {
296308 // When property value contains double quotes
You can’t perform that action at this time.
0 commit comments