To see an HTML file’s tags and text in TextEdit instead of its formatted page, open it from TextEdit and choose Ignore rich text commands in the Open dialog’s options. To make that the default for future HTML files, enable Display HTML files as HTML code instead of formatted text in TextEdit settings. These controls change how TextEdit displays the file; you don’t need to edit or save it to view its source.
Open one HTML file as code
Open TextEdit on your Mac.
Choose File > Open, select the
.htmlfile, and click Show Options at the bottom of the dialog.Select Ignore rich text commands, then click Open.
The document should appear as text containing its HTML markup, such as tags and attributes, instead of as a formatted page. Apple documents this option for opening an individual file in code-editing mode. Work with HTML documents in TextEdit on Mac
Make code view the default
If you regularly inspect HTML files, set TextEdit to show their code automatically: choose TextEdit > Settings, click Open and Save, then select Display HTML files as HTML code instead of formatted text under When Opening a File. After that, open the file in TextEdit as usual.
This setting applies to HTML files opened in TextEdit, so it changes the app’s default behavior rather than just the current document. To return to formatted display, clear the checkbox. Apple lists this preference separately from the per-file Ignore rich text commands option. Change settings in TextEdit on Mac
If the file still looks like a webpage
Check that you opened the intended file in TextEdit and that the code-view option is selected. If you used the Open dialog, try opening the file again and selecting Show Options > Ignore rich text commands. If you want this behavior for other HTML files too, use the default setting above.
TextEdit can display HTML as formatted text, much like a browser, or show it in code-editing mode. In formatted mode, markup may be hidden, and Apple notes that curly quotes and em dashes can replace straight quotes and hyphens when editing HTML in that mode. Choose code view when you need to inspect the literal source. Work with HTML documents in TextEdit on Mac
View source without changing the file
Opening a file in code view is enough to inspect its contents. You do not need to type into the document or save it. If you do make changes, TextEdit can modify the file when you save; to keep the original untouched, close without saving if you have made edits you don’t want to retain. The viewing controls themselves are display options, not a guarantee that later edits will be discarded.
TextEdit’s code view is useful for reading or making simple text changes, but it is not a browser preview. If your goal is only to see how the page appears to visitors, open the HTML file in a browser instead. If your goal is to read the tags or copy source text, use TextEdit’s code view.
Sources
Work with HTML documents in TextEdit on Mac — Apple Support
Change settings in TextEdit on Mac — Apple Support