As it is mentioned in https://www.w3schools.com/html/html_editors.asp
first in your textEdit settings**: Format >** choose "Plain Text"
then select "Open and Save" tab: check the box that says "Display HTML files as HTML code instead of formatted text".
and use .html instead of .txt when you want to save.