You can set preferences that affect how HTML files are saved.
Choose TextEdit > Preferences, and then click “Open and Save.”
Below HTML Saving Options, choose a document type, a setting for cascading style sheets (CSS), and an encoding.
If you aren’t sure what to choose, keep the original settings.
Select "Preserve white space" if you want TextEdit to include code to preserve blank areas in your document.