Return HTML from a function

Hello,

my question is: Is there a good way to return HTML from a function?

I must reuse the a block of HTML code in three different if/else statements. I thought maybe I could write a function which returns the HTML code, instead of reusing the same HTML three times. The advantage also would be that I only need to change the HTML from one place. But I only could find a solution by using echo. The problem with that is, it’s hard to debug/maintain, because essentially, it’s just a string with HTML code inside, without syntax highlighting or formatting. I fear that there no better solution, but I thought I try and ask here. I am open for other solutions as well. Thanks.