TextEdit is the wrong tool for editing raw HTML or whatever, since it tries to do rich text markup and all of that itself. For raw text, you want a programmer's editor. If something like Emacs is too imposing, and something like Xcode is overkill, there are a variety of other options, some free, some costing dollars. Since I just use Emacs, I haven't really bothered to look into what else is out there.

Of course, if you've got the money, the way to go is to get something like Dreamweaver, which is meant for doing web things.