askvity

How to Create HTML Code?

Published in HTML Basics 3 mins read

Creating HTML code is a straightforward process involving a text editor, some basic HTML syntax, and a web browser to view the results. Here's a step-by-step guide:

1. Open a Text Editor

You'll need a plain text editor to write your HTML. Avoid using word processors like Microsoft Word, as they add formatting that can interfere with the code.

  • Windows: Use Notepad. You can typically find it by searching for "Notepad" in the start menu.
  • Mac: Use TextEdit. Open Finder, go to Applications, and then open TextEdit. If you are using TextEdit, make sure to set the preferences to "Plain Text" under the "Format" menu.

2. Write Your HTML Code

This is where you'll write the actual HTML code. All HTML documents should start with the <!DOCTYPE html> declaration, which defines the document type and version of HTML being used. The root element of an HTML page is <html>, and it contains two main sections: the <head> and the <body>.

Here's a simple example:

<!DOCTYPE html>
<html>
<head>
  <title>My First Webpage</title>
</head>
<body>
  <h1>Hello, World!</h1>
  <p>This is my first webpage created using HTML.</p>
</body>
</html>

Explanation:

  • <!DOCTYPE html>: Specifies the document is HTML5.
  • <html>: The root element of the page.
  • <head>: Contains meta-information about the HTML document, such as the title.
    • <title>: Specifies a title for the HTML page (which is shown in the browser's title bar or tab).
  • <body>: Contains the visible page content.
    • <h1>: Defines a level 1 heading.
    • <p>: Defines a paragraph.

3. Save the HTML File

Save the file with a .html or .htm extension. Choose a descriptive name for your file (e.g., index.html).

  • Important: In the "Save as type" dropdown, choose "All Files" to prevent Notepad or TextEdit from adding a .txt extension to the file.

4. View the HTML Page in Your Browser

Locate the saved HTML file on your computer and double-click it. This will open the file in your default web browser (Chrome, Firefox, Safari, Edge, etc.). You should see the content you wrote in the <body> section rendered in the browser.

Summary

Creating HTML code involves opening a text editor, writing HTML code that defines the structure and content of a webpage, saving the file with a .html extension, and then opening the file in a web browser to view the rendered page. This basic process allows you to create simple webpages and is the foundation for more complex web development.

Related Articles