How to access an HTML document in a browser?


HTML stands for Hyper Text Markup Language and is a web-based scripting language. HTML consists set of elements that are used to create and structure web pages. Programmers often prefer HTML to design websites because it is flexible and easy to use.

In this article, we discuss how to create an HTML file, what is an HTML file, and explain how to open one in a browser.

What is an HTML file?

An HTML file is a text document written in Hypertext markup language that contains the content and structure of a webpage. This HTML file contains various tags and elements that are used to design a webpage, such as headings, paragraphs, images, etc.

There are various tools that we can use to create or edit an HTML file. However, we can create one using a basic text editor (say Notepad or Notepad++) and are saved it with a .html or .htm file extension.

Following will be the basic elements present inside an HTML file −

<html>
   <head></head>
<body>
   <h1></h1>
   <p></p>
</body>
</html>

How to open an HTML file in a browser

There are different ways we can access HTML in a browser. The following are some possible methods −

Using "Open with" option

Following are the steps to access an HTML file in any browser using the "open with" option −

  • Step 1 − Open a text editor (say Notepad++) and write some HTML code in it.

  • Step 2 − Now, click on the file menu in the left-top corner and click on "Save As" (or ctrl+Shift+s) option.

  • Step 3 − Name the file accordingly.

  • Step 4 − Click on the "Save as type" drop-down menu and click on "Hyper Text Markup Language file" option. Then click on the Save button.

  • Step 5 − Now, right-click the saved .html file and click on "open with" menu. You may see a long list of browser list from which you choose to open your file. Your default browser may be at the top of the list.

Note − To ensure, that you have opened the right HTML file, you can check the path in the URL bar of the browser. The address should match the file location on your computer.

Example

<!DOCTYPE html>
<head>
   <title>Accessing a HTML document in a browser</title>
</head>
<body>
   <h1>Tutorialspoint</h1>
   <p>Simply Easy Learning at your fingertips.</p>
</body>

Output

After selecting the browser, you can see that file is opened in the browser.

Drag and Drop the file in browser

Following are the steps to access an HTML file in any browser (using the drag and drop technique) −

  • Step 1 − Select the HTML file by left-clicking on it.

  • Step 2 − Now, drag on to the browser from which you choose to open your file. The browser will automatically open the HTML file into a new tab.

Updated on: 04-Aug-2023

140 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements