Have you tried opening a .txt file with your browser before? Your browser is perfectly capable of displaying the content in that .txt file. Browsers can “read” files in a variety of formats (but not all of them though) because files are simply a means for computers to store data.
All digital files are long strings of 0s and 1s AKA binary data. The exact sequence of 0s and 1s is meaningful because that is how computers differentiate one chunk of data from another.
Computers use numerous techniques to determine a file’s format. The most common approach is via the filename extension, which is the made up of a string of letters after the final period of a file. For example, dinosaur.txt has a filename extension of .txt while index.html has a filename extension of .html.
Another approach is via internal metadata. Most files start with information about the file itself in the file header, and computers make use of that information to determine which program is most suitable to open the file.
If you try to open a file format with a program that doesn’t know how to handle it, you will either receive an error message that the file cannot be read, or the content of the file will be displayed incorrectly.
The following are files that contain code in the C programming language and Rust programming language. If you are new to programming, it doesn’t matter if you don’t understand what the code does. But you can see that the code is made up of alphabets, numbers and some symbols.
/* fizzbuzz in c */#include <stdio.h>int main(){ int a; for(a=1;a<=100;a++) { if( a % 3 == 0 ) printf("Fizz"); if( a % 5 == 0 ) printf("Buzz"); if( a%3 && a%5 ) printf("%d",a); putchar('\n'); } return(0);}/* fizzbuzz in rust */
fn main() { for n in 1..101 { if n % 15 == 0 { println!("fizzbuzz"); } else if n % 3 == 0 { println!("fizz"); } else if n % 5 == 0 { println!("buzz"); } else { println!("{}", n); } }}The web browser, like you, doesn’t understand what these specific files do either, because the browser doesn’t read C or Rust. But it can also tell the code is made up of alphabets, numbers and some symbols.
So if you try to open these 2 files in your browser, the text in the file will be displayed as is. This is because the browser does not recognise the code in those files as instructions to be run, instead, the browser is treating them as plain text and displaying the code as such.
The file formats that are fundamental to web development are .html, .css and .js. In this course, you will mostly be working with HTML and CSS files.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson