diff --git a/installer/templates/phx_web/components/core_components.ex b/installer/templates/phx_web/components/core_components.ex
index 2fe64b24b3..b91fbd2ff8 100644
--- a/installer/templates/phx_web/components/core_components.ex
+++ b/installer/templates/phx_web/components/core_components.ex
@@ -106,10 +106,11 @@ defmodule <%= @web_namespace %>.CoreComponents do
slot :inner_block, doc: "the optional inner block that renders the flash message"
def flash(assigns) do
+ assigns = assign(assigns, :id, assigns.id || "flash-#{assigns.kind}")
~H"""
hide("##{@id}")}
role="alert"
class={[
diff --git a/priv/templates/phx.gen.live/core_components.ex b/priv/templates/phx.gen.live/core_components.ex
index 2fe64b24b3..b91fbd2ff8 100644
--- a/priv/templates/phx.gen.live/core_components.ex
+++ b/priv/templates/phx.gen.live/core_components.ex
@@ -106,10 +106,11 @@ defmodule <%= @web_namespace %>.CoreComponents do
slot :inner_block, doc: "the optional inner block that renders the flash message"
def flash(assigns) do
+ assigns = assign(assigns, :id, assigns.id || "flash-#{assigns.kind}")
~H"""
hide("##{@id}")}
role="alert"
class={[