Not sure legal is the correct way of putting the question but many sites allow the use of HUDs. Look at the terms and conditions and they will tell you if its OK or not.
Also if its not ok, the HUD usually wont work, so its not like, you can inadvertently end up breaking the Terms and Conditions (TOS). You just need to be carefull with some sites like GG Poker, which have totally ridiculous TOS allowing them to steal your money for having a program like PT4 open while playing on their site, even though the HUD is not working on GG Poker. The problems with GG Poker are explained very well in this video:
This question also arose in me. So far, I have known that more and more poker rooms are banning these utilities.
However, i see in the comments that I knew wrong which I am very happy about because my plans include using such a utility.