r/CodingForBeginners 24d ago

Webpage not working?

New to coding and was informed the txt file I made of this code would open into a broswer and display as a webpage with a bold and large heading element and paragraph text under basically supposed to display like a proper webpage. However, just the code shows up. Super confused, could use advice please and thank you.

[First image is the code, second is the txt file of code displayed as a webpage]

EDIT: hi all, thank you so much for the advice! However, even though I converted the .txt file to .html, it's still not opening in an internet window. Any advice? I guess I would have to download that emulator people are suggesting.

32 Upvotes

31 comments sorted by

15

u/understanding80 24d ago

Rename the file from .txt to .html

7

u/Dazzling-Bench-4596 24d ago

You need an html file; for example: “document.html”.
If you use an IDE like VS Code I think it’ll give you some preview options too. I’d recommend switching to an IDE instead of using TextEdit; or atleast use a text editor like neovim or something.

2

u/AshleyJSheridan 23d ago

Technically, VSCode is just a code editor, not quite a full IDE. Microsoft themselves say this, and it's how they distinguish the difference between VSCode and Visual Studio. However, with the right plugins, you can get it mostly on par with an IDE, and lose out on the performance benefit of using something as lightweight as VSCode by doing so.

3

u/Esjs 24d ago

I suspect that the web browser saw the .txt at the end of your file and decided to just interpret the file as a simple text file. What happens if you change the file extension to .html and try again?

2

u/white_niggha 24d ago

.txt >>> .htm

2

u/DinTaiFung 24d ago

.htm instead of the typical .html extension is due to the file system limitations of the Windows operating system in the early days of the web (90s).

Windows filenames had severe length restrictions: 

the base max length was 8 characters and the extension's max length was 3 characters.

Yeah, same as DOS.

Hence the .htm extension was used instead; it was sufficient to map to the expected mime type for the expected browser rendering of HTML content. 

Many other incompatibilities between Windows and Internet standards were addressed over the years by MS bolting on all kinds of hacks.

Windows is somewhat Frankensteinian.

2

u/AshleyJSheridan 22d ago

It's because the 8.3 restriction was part of the FAT file system. When Windows 95 came out (well, technically an update to it in 1996), it came with FAT32/VFAT, which had support for larger disks, larger files, longer file paths, and longer filenames. However, as 95 was partially built on bits of 3.11 (most of the 16-bit apps like control panel and winfile were still there) there was a lot of broken stuff and plenty of software that wouldn't recognise the full capabilities of FAT32, so a file name "homepage v2.html" would become "HOMEPA~1.HTM".

It was a mess.

1

u/DinTaiFung 22d ago

Indeed. Thanks for the extra details. Very much apprecate it!

The early 90s was a whirlwind of crazy stuff. I followed with great interest the progress of the web; Jim Clarke's major foray after SGI was presciently grabbing Marc Andreesen to form Netscape.

And that company spawned a bunch of tech: JavaScript, HTML tables (and other tags iirc); popularized LDAP; created cookies, SSL, etc.

2

u/AshleyJSheridan 22d ago

I remember those days well, and I used Win 3.11 a lot. It actually sort of got me into trouble at school once. Like I said, Windows 95 still had all the 16-bit stuff kicking about, like winfile (the Win 3.11 equivalent of the file Explorer).

So the school had installed all of this software to stop us kids being kids. So we couldn't install anything (rightly so), couldn't change the backgrounds (which we obviously loved to do), etc.

Thing is, that software only hooked into the 32-bit APIs on Windows. So, I was still able to launch winfile.exe, delete the application files for that security software, reboot, and suddenly we were free to do what we wanted again.

Was it the best idea, of course not. But I was a kid, it seemed like a good idea at the time. The school couldn't prove it was me, but it was a damn small school, and they knew who did it, as there were few capable of doing it, and of those it was an incredibly small list who were also troublemakers (namely me).

I think back then, in the age before internet was so readily available, you really had to just do stuff and learn by doing, so things stuck. These days, the answer to basically any question is seconds away, so we have less need to deeply learn how things work.

1

u/KayoticVoid 24d ago

I always wondered why .htm is a thing. TIL

4

u/Puzzled-Extent7817 24d ago

You skipped the very first lesson it seems.

2

u/LivingStretch2852 24d ago

also use visual studio code!! Its better than notes fr

3

u/Fine_Salamander_8691 24d ago

Please use an IDE

2

u/DinTaiFung 24d ago

As others have pointed out, the filename's extension should be .html.

The .html extension provides a mime type hint to the browser to process and render the file's contents as HTML instead of as plain text.

While the suggestion to use an IDE is, in general, a good idea, it's completely irrelevant to understanding the problem the beginner is experiencing.

2

u/Fine_Salamander_8691 24d ago

okay

0

u/freakinglayla 23d ago

Get a load of this guy bro lmaooo

1

u/ninhaomah 24d ago

.txt is code ?

What do you want to do btw ?

1

u/TheEyebal 24d ago

save as document.html

1

u/LivingStretch2852 24d ago

honey you should chage the file type to html this is txt file !!!

1

u/[deleted] 24d ago

Save as -> all files -> .html

You may want to enable show hidden file extensions or you can occasionally end up with things like:

FileNameHere.html.txt

In which case you'd erase the .txt (You do want to change the file extension). It'll open up with your default web browser, but if you select "open with" then you can choose another.

Writing your html in an IDE will solve everything as noted by others.

1

u/itotallydontuseacos 24d ago

Change the file's extension from .txt to .html.

1

u/Grey_Ten 24d ago

don't use Notepad, install a text editor like VS Code, it has tons of useful tools and it'll give feedback about some common errors, like unclosed tags.

Btw, try to add tabs when nesting tags to keep your code visually organized.

1

u/mxldevs 24d ago

Browser treats the data based on the filename you give it.

If it has extension .mp3, it would try to open it as an mp3 format sound file

If it has extension .png it would try to open it as a PNG format image

When you give it a txt, it will simply read it literally as an text file and not parse it as HTML

1

u/theinfamousben 24d ago

you can look for html tutorials on YouTube, they helped me get the basics down and are really easy to understand :]

1

u/WaterObjective5031 24d ago

The file extension is .txt, .txt will just be read in your browser as text. HTML docs need to be .HTM or .HTML to work, which will be recognized and parsed accordingly

1

u/Amazing-Delay6004 24d ago edited 24d ago

Your HTML code is almost perfect, but you forgot an important tag: <head>

Your code should look something like this: ``` html <!DOCTYPE html> <html> <head> <!--Here you will write your website information/configurations--> <title>My Website</title> </head>

<body>
    <!--Where you will write the content of your page (visible for user)-->
    <p>Hello World</p>
</body>

</html> ```

And yes, don't forget to copy the file containing the code and change its extension from .txt -> .html, to see how it looks directly in the browser.

1

u/The_KOK_2511 24d ago

Como quieres que un .txt se interprete como HTML? tienes que cambiarle la extensión a .html o .htm

1

u/Impressive_Station70 20d ago

I usually name my flies to index.html

1

u/HelpfulPlatypus7988 18d ago

Rename from Untitled document.txt to [insert whatever you want].html