Question:
HTML file only shows source in browser?
anonymous
2009-05-30 20:24:03 UTC
I recently started learning HTML, and as practice I made this really simple file on my computer using this code:





This is a Simple Heading



This is a simple paragraph.



This is another simple paragraph



This is a slightly more complex paragraph that has a link to Google in it.







I made this file with a simple text editor, saved it as an HTML, and then tried to open it in my web browser. The browser only shows the code, not the rendered text and links. I tried troubleshooting this, but none of the possible fixes worked for me. I am absolutely sure it is saved as an HTML file. As you can see above it has the proper coding. I tried opening the file directly, opening it within my browser, and dragging it into the browser. I simply don't understand why it won't work.
Three answers:
korgrue
2009-05-30 20:27:49 UTC
You never declared that it is a html document for your browser.



Try this




"http://www.w3.org/TR/html4/loose.dtd">







Untitled













without declaring that it is indeed an html document, and assigning a character set, the browser does not know what to do with it.
Silent
2009-05-30 20:44:04 UTC
Which text editor did you use?



Windows Notepad generally adds a .txt extension to the end of the name of any file it saves, even if the filename you provide already has an extension on it. Unless you changed the file type to "All Files" when saving the file, it may be called something like "myfile.html.txt". If your system is set to not display extensions for known file types (as most Windows systems are by default) then this may not be apparent; you'll see the name as "myfile.html", and it'll have the icon of a text file.



Because of the .txt extension, your browser will try to display it as text rather than render it as HTML.



Although you should have a doctype declaration at the top of any HTML file, I think korgrue is incorrect about this being your problem. Modern web browsers will try to infer the type of a file if no doctype is specified; on Windows, this generally means checking the file extension.
ansirs
2009-05-30 20:47:19 UTC
Hi,



The chances are that although you thought that you saved it as an html document, in fact it is probably saved as something like MySimpleSample.htm.txt



The reason is that unless you have changed the view options in Windows explorer the default extensions will be hidden, thereby causing a text file created by notepad or similar to actually be saved with its default extension which is .txt.



I suggest that you download a brilliant Free editor for HTML and other text work called NoteTab Lite from Fookes Software.

There is a professional version of this software available also.



It is a marvellous text editor and is designed to work with html, it has built-in macro language that you can program yourself and has various clips that enhance the writing of html without doing it all for you, i.e. it allows you to be creative in creating manual html but eases the process immensely.



Good Luck.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...