Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML Comments
Next article icon

HTML Basics

Last Updated : 10 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

HTML (HyperText Markup Language) is the standard markup language for creating and structuring web pages.

  • It defines the structure of a webpage using elements and tags.
  • HTML is responsible for displaying text, images, and other content.
  • It serves as the foundation for building websites and web applications.

In this guide, we learn the basics of HTML, which includes HTML tags ( <h1>, <p>, <img>, etc), attributes, elements, and document structure,e which collectively form a working web page.

Table of Content

  • Basic HTML Document
  • HTML Basic Structure
  • HTML Headings
  • HTML Paragraph and Break Elements
  • HTML Horizontal Line
  • HTML Images
  • View HTML Source Code

Basic HTML Document

Every HTML document begins with a document type declaration, setting the foundation for the webpage. This section introduces basic HTML tags that structure the page, such as <head>, <body>, and <title>. Although this is not mandatory, it is a good convention to start the document with the below-mentioned tag. 

Below mentioned are the basic HTML tags that divide the whole page into various parts like head, body, etc. 

Basic HTML Tags for Document Structure

TagsDescriptions
<html>Encloses the entire HTML document, serving as the root element for all HTML content.
<head>Contains header information about the webpage, including title, meta tags, and linked stylesheets. It is part of the document’s structure but is not displayed on the webpage.
<title>Used within the <head> section to define the title of the HTML document. It appears in the browser tab or window and provides a brief description of the webpage’s content.
<body>Encloses the visible content of the webpage, such as text, images, audio, videos, and links. All elements within this tag are displayed on the actual webpage when viewed in a browser.


HTML
<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <title>HTML</title> </head> <body>     <!--Contents of the webpage-->     <p>GeeksforGeeks is a online study platform</p> </body> </html> 

In this Example:

  • This HTML document defines a basic webpage with a responsive design using <meta> tags, ensuring it adjusts well to different devices.
  • The content includes a paragraph <p> displaying “GeeksforGeeks is an online study platform,” and the title “HTML” appears in the browser tab.

HTML Basic Structure

Screenshot-(4)

HTML Structure

HTML Headings

The HTML heading tags are used to create headings for the content of a webpage. These tags are typically placed inside the body tag. HTML offers six heading tags, from <h1> to <h6>, each displaying the heading in a different font size.

Syntax:

<h1></h1>
<h2></h2>
<h3></h3>
<h4></h4>
<h5></h5>
<h6></h6>
HTML
<html> <body>       <h1>Heading 1 (h1)</h1>       <h2>Heading 2 (h2)</h2>       <h3>Heading 3 (h3)</h3>       <h4>Heading 4 (h4)</h4>       <h5>Heading 5 (h5)</h5>       <h6>Heading 6 (h6)</h6> </body> </html> 

In this Example:

  • This code displays six headings (<h1> to <h6>) on the webpage, with <h1> being the largest and most prominent and <h6> being the smallest.
  • The headings are used to define text hierarchy and emphasize content based on importance.

HTML Paragraph and Break Elements

HTML <p> tags are used to write paragraph statements on a webpage. They start with the <p> tag and end with </p>. The HTML <br> tag is used to insert a single line break and does not require a closing tag. In HTML, the break tag is written as <br>.

Syntax:

// for Parapgraph
<p> Content... </p>
// for Break
<br>
HTML
<html> <body>       <p>             HTML stands for HyperText Markup Language.<br>             It is used to design web pages using a markup             language.<br>HTML is a combination of Hypertext             and Markup language.<br>Hypertext defines the             link between web pages.<br>A markup language             is used to define the text document within the             tag which defines the structure of web pages.       </p> </body> </html> 

In this Example:

  • This HTML code uses a <p> tag to display a paragraph of text, providing an overview of what HTML is and its purpose.
  • The <br> tags are used to insert line breaks, making the text more readable by separating each sentence onto a new line within the paragraph.

HTML Horizontal Line

The HTML <hr> tag is used to divide a page into sections by creating a horizontal line that spans from the left to the right side of the page. This is an empty tag and does not require a closing tag or any additional attributes.

Syntax:

<hr>
HTML
<html> <body>     <p>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>     </p>     <hr>     <p>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>     </p>     <hr>     <p>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>         A Computer Science portal for geeks<br>     </p>     <hr> </body> </html> 

In this Example:

  • <h1> to <h6> tags are used to define headings, with <h1> being the largest and <h6> the smallest.
  • Each tag displays “Hello World!” in decreasing font sizes, illustrating the hierarchy of headings in HTML.

HTML Images

The <img> tag is used to insert an image into a webpage. The source of the image is specified within the src attribute, like this: <img src=”source_of_image”>.

Syntax:

<img src="geeks.png">
HTML
<html> <body>       <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png"> </body> </html> 
  • This HTML code uses the <img> tag to display an image on a webpage.
  • The src attribute specifies the URL of the image, which is loaded and displayed when the page is rendered in the browser.

View HTML Source Code

While checking a web page, you might want to see the HTML code behind it. Here we will see how you can view HTML source code for the entire page or a specific element.

1. View HTML Source Code of Entire Page

  • To view the source code of a webpage press ctrl + u on the page, or right-click on the page and select the “view page source” option.
  • This will open a new tab that shows the HTML source code for that entire page.

2. Inspect an HTML Element on a Page

  • To check the HTML code for a specific element on a page, right-click on the page and select the “Inspect” option.
  • This lets you see the HTML and CSS behind that element. You can also try making changes and see the changes.


Next Article
HTML Comments
https://media.geeksforgeeks.org/auth/avatar.png
GeeksforGeeks
Improve
Article Tags :
  • HTML
  • Web Technologies
  • HTML-Basics
  • HTML5
  • Web technologies-HTML and XML

Similar Reads

  • HTML Tutorial
    HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
    10 min read
  • HTML Introduction
    HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It defines the structure of a webpage by using a series of elements, tags, and attributes to organize text, images, links, and other multimedia elements. HTML is a markup language,
    7 min read
  • HTML Editors
    An HTML Editor is a software application designed to help users create and modify HTML code. It often includes features like syntax highlighting, tag completion, and error detection, which facilitate the coding process. There are two main types of HTML editors: Text-Based Editors - Allow direct codi
    5 min read
  • HTML Basics
    HTML (HyperText Markup Language) is the standard markup language for creating and structuring web pages. It defines the structure of a webpage using elements and tags.HTML is responsible for displaying text, images, and other content.It serves as the foundation for building websites and web applicat
    6 min read
  • HTML Comments
    HTML comments are used to add notes or explanations in the HTML code that are not displayed by the browser. They are useful for documenting the code, making it easier to understand and maintain.To add a comment, use the syntax <!-- your comment here -->. [GFGTABS] HTML <!-- This is a commen
    4 min read
  • HTML Elements
    An HTML Element consists of a start tag, content, and an end tag, which together define the element's structure and functionality. Elements are the basic building blocks of a webpage and can represent different types of content, such as text, links, images, or headings. For example, the <p> el
    5 min read
  • HTML Attributes
    HTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behavior, appearance, or functionality in a variety of ways. Each attribute has a name and a value
    9 min read
  • HTML Headings
    HTML headings are used to define the titles and subtitles of sections on a webpage. They help organize the content and create a structure that is easy to navigate. Proper use of headings enhances readability by organizing content into clear sections.Search engines utilize headings to understand page
    4 min read
  • HTML Paragraphs
    A paragraph in HTML is simply a block of text enclosed within the <p> tag. The <p> tag helps divide content into manageable, readable sections. It’s the go-to element for wrapping text in a web page that is meant to be displayed as a distinct paragraph. Syntax: <p> Content</p
    5 min read
  • HTML Text Formatting
    HTML text formatting refers to the use of specific HTML tags to modify the appearance and structure of text on a webpage. It allows you to style text in different ways, such as making it bold, italic, underlined, highlighted, or struck-through. Table of Content Categories of HTML Text FormattingLogi
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences