Just created a simple html file in TextEdit on Mac. It looks like this.
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My First Web Page</h1>
<p>This is an HTML page that I created in TextEdit.</p>
</body>
</html>
Afterwards I saved it using an .html extension, and tried to open this file in multiple browsers.
However, instead of displaying the correct layout, I got this same code on web page again: see the pic below.

The result persisted across all browsers and after refreshing the page, too. Though if I first saved the document as an RTF file, and later changed the extension manually to HTML, browsers displayed some stuff, but not as expected and shown in a textbook. Below the second result.

The intended result is from the textbook and is shown on the next picture.

Any ideas why doesn't Safari (or Firefox, Opera, Chrome, DuckDuckGo likewise) show the file correctly?
My first instinct is to make line 1 read
<!DOCTYPE HTML>to see if that would make your webbrowser read the code as HTML instead of a plain text. Not sure if that would work, but I would try it.