To format the SQL on-the-fly, search for 'syntax highlighter'. One I've used is the open-source GeSHi tool (https://en.wikipedia.org/wiki/GeSHi), although its T-SQL coloring was last publicly updated a while ago. You can easily modify the reference file for T-SQL; the list of keywords, DMVs, etc. for each color are just arrays in the file that you can add any new items to in a text editor. There are syntax-highlighter plugins for many blog/wiki/etc. platforms.
If you're creating static HTML pages and just want to mark up the SQL to look good on the page, there are a variety of online sites, such as http://www.dpriver.com/pp/sqlformat.htm that let you paste your SQL in a box and it gives you the marked-up HTML. Search for 'SQL Server pretty print'.