FHRP communication path of keepalives
In order for two layer 3 devices to operate using an FHRP, the two layer 3 interfaces must be on the same layer 2 network segment so that their keepalives and their FHRP negotiation can take place successfully.
This can take place via a direct layer 2 link between the two devices as seen below:
If the link between the two devices is a layer 3 link, then the FHRP negotiation can also take place via the access layer switch that connects the two devices, which involves two layer 2 links:
Indeed in such a case, no direct link between the two gateways is necessary.
The following note describes what kind of L2 connections you can use for FHRP:
FHRP Communication Between Redundant Routers
For more information about different FHRP protocols, take a look at:
Links
https://networklessons.com/cisco/ccna-200-301//cisco-campus-network-design-basics
https://networklessons.com/cisco/ccie-enterprise-infrastructure/introduction-gateway-redundancy