diff --git a/lib/cucumber/formatter/html.rb b/lib/cucumber/formatter/html.rb
index 5d60e032b0..d1ae8b7a37 100644
--- a/lib/cucumber/formatter/html.rb
+++ b/lib/cucumber/formatter/html.rb
@@ -417,7 +417,8 @@ def set_scenario_color_failed
@builder.script do
@builder.text!("makeRed('cucumber-header');") unless @header_red
@header_red = true
- @builder.text!("makeRed('scenario_#{@scenario_number}');") unless @scenario_red
+ scenario_or_background = @in_background ? "background" : "scenario"
+ @builder.text!("makeRed('#{scenario_or_background}_#{@scenario_number}');") unless @scenario_red
@scenario_red = true
end
end
@@ -425,7 +426,8 @@ def set_scenario_color_failed
def set_scenario_color_pending
@builder.script do
@builder.text!("makeYellow('cucumber-header');") unless @header_red
- @builder.text!("makeYellow('scenario_#{@scenario_number}');") unless @scenario_red
+ scenario_or_background = @in_background ? "background" : "scenario"
+ @builder.text!("makeYellow('#{scenario_or_background}_#{@scenario_number}');") unless @scenario_red
end
end