Browser shows plain text instead of HTML in mac
Asked Answered
K

9

11

I want to write an html document like this :

<html>
<body>

<h1>My First Heading</h1>

</body>
</html>

I wrote it and saved it in my desktop with the name hello.html , but when I open this file with firefox or safari, the browser shows the whole text (including <html> and all of the texts) instead of only showing my first heading! what's the problem?

Keslie answered 21/1, 2013 at 13:16 Comment(4)
Do you have hide extensions turned on? Because you could have saved the file as hello.html.txt. Use right click -> Get Info to check.Karaganda
no, hide extensions is turned off, the name was first hello.html.rtf, but I renamed it to hello.htmlKeslie
Then you saved it as an rtf, which is not plain text. Go to the top menu bar -> text edit -> preferences and select plain text at the top. And then save it again.Karaganda
My case was a little different but this is the first result on Google so I'll place this here. I was returning the HTML back from a REST endpoint, and it was also showing as text. The issue was the absence of a "content-type" header with the value "text/html". Once added, HTML was displaying as expected.Graz
K
17

The problem was that I wrote the HTML document with "Text Edit" application, and it saved the file with .rtf extension, that is not plain text, so changing the name of file to hello.html didn't change anything.

there are two ways to fix this problem:

1) if you insist on using "Text Edit" you should go to text edit->preferences and tick the plain text at top of the page, then when you save something, it is saved as plain text

2) you can use some text editor, like lime edit

Keslie answered 21/1, 2013 at 13:39 Comment(2)
Checking in, in case it's useful for anyone else. On TextEdit version 1.13 (333), this option is Format > Make plain text.Trawl
Just to add, I also changed text edit->preference->open and save->display html files as html code instead of formatted text. Without this i was not able to see the html code written.Groveman
L
4

The most likely reason is that you used a WYSIWYG editor and saved the document as HTML.

This created an HTML representation of the HTML source code you typed.

Use a text editor instead. I'm fond of Sublime Edit 2.

Laurencelaurene answered 21/1, 2013 at 13:18 Comment(5)
Use a text editor (or force TextEditor to save in plain text mode … but getting a decent editor would be better, you get other benefits like syntax highlighting).Laurencelaurene
It is what I use. There are lots of options out there. TextWrangler is free.Laurencelaurene
Why is the choice of the editor important for which file extension is set to a file on save?Politian
@Politian — It isn't and I never said it was. The OP had two problems. This answer addresses only one of them. The other was resolved in comments.Laurencelaurene
@quentin what should I do now ? accept your answer and vote up user23127's comment, or write an answer that contains both ?Keslie
C
1

I've had the same issue in TextEdit. The resolution is - go to "Format", then "Make plain text". Save the document and open it again in browser. It had worked in my case. Hope it will work for you too.

Cloy answered 8/6, 2017 at 14:33 Comment(0)
M
0

Use a text editor such as Dreamweaver, Sublime

Sublime http://www.sublimetext.com/2

and ensure your file ends in .html not .txt

Minster answered 21/1, 2013 at 13:23 Comment(3)
What does the editor has to do with the file extensions given for a file? (Except nothing.)Politian
Just in case. Opening a new window with Sublime text without changing the format could result in this (I mean hello.html.txt).Minster
@Politian Look at the answer below, see what happens. Its a common thing. I did this simply to make OP aware while troubleshooting.Minster
I
0

Download install "TextWrangler" (for mac) paste your html content to a new file in it and save with .html link. Dont use TextEdit.

Irbm answered 27/8, 2016 at 16:16 Comment(0)
U
0

If you open the file using a basic text editor (like nano from the terminal), you'll probably see there's a lot of additional lines added to your basic HTML code. That's what happened to me.

I removed all the lines except what I wanted and it finally rendered correctly.

Upturn answered 5/11, 2016 at 14:5 Comment(0)
M
0

I found that the parent folder on my web server contained an old .htaccess file that was causing HTML files to display as plain text. Renaming/reworking the .htaccess file or just moving my HTML file to another folder fixed the issue.

Michelemichelina answered 24/3, 2020 at 16:23 Comment(0)
G
0

TextEdit setting change fixed this issue for me : text edit->preferences>New document>Fromat>plain text (unmark Rich text).

Guenther answered 4/12, 2023 at 18:44 Comment(0)
S
-1

I have same issue. I am using TextEdit. Issue was fixed by following the change: text edit->preferences>New document>Fromat>plain text (not Rich text).

Sloe answered 10/8, 2021 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.