I would definitely choose Hogwarts Legacy over ELDEN RING if given a chance to make such a decision. Both are open-world action-RPG games, but Elden Ring is more of a dark fantasy souls-like RPG. If you are a fan of the DARK SOULS series, then Elden Ring might be a better choice.
Else, Hogwarts Legacy is also a very good game, and it has a proper story at least. What distinguishes one from the other is an emphasis on story versus exploration. Hogwarts Legacy is more linear in gameplay though, a traditional role-playing experience, albeit with a magical spin to its combat.
Hogwarts Legacy’s open world is bound to more aggressive side quests and field guide progression before the player can proceed further in the game, while Elden Ring’s open world is almost entirely free to explore with discovery being its primary goal. There are still some restrictions though.
Moreover, Elden Ring beats Hogwarts Legacy in environment detail and level diversity since the lands are quite vast, and they are stretched between colorful biomes, whereas Hogwarts Legacy is more confined to its coastal and wooded Highlands. Elden Ring's levels are huge !
Talking about some quests, even though there are NPCs to meet and talk to in Elden Ring, the quests that some of them present to the player are not bound to a fixed or a marked waypoint path and linear quest-restriction boundaries. The player has to figure out by themselves.
Elden Ring is basically Dark Souls but in an open-world setting with many varied/expansive levels, more bosses, and many dungeons to explore. Unlike Elden Ring, however, Hogwarts Legacy features sorcery as the primary offensive and defensive tool, which should not come as a surprise given the game's background and setting.
In my opinion Hogwarts Legacy has the upper hand on Elden Ring regarding delivering a more "sorcerer-like" experience, being a game of witches and wizards, with a story set within the "Wizarding World" background.
If you like a good story, then Hogwarts Legacy is the way to go. Else, like mentioned above Elden ring is also a very good game, and the combat and enemy encounters are more fluid than the darks souls franchise.