HTML Course | Basics of HTML
Last Updated : 24 Nov, 2024
Now that you’ve created your first “Hello World” webpage, it’s time to learn some important concepts of HTML. In this chapter, we’ll cover basic elements that add content and structure, including paragraphs, images, lists, attributes, comments, and more.
HTML Paragraph
The <p> tag is used to create paragraphs, which helps to structure and organize text content. Each <p> tag creates a new paragraph and ends with </p>.
Here the <br> tag is used to break the line and it is an empty tag means it doesn’t require a closing tag.
Syntax
<p>GeeksforGeeks</p>
Example: This example shows the use of paragraph tag.
html <!DOCTYPE html> <html> <head> <title>Paragraph tag</title> </head> <body> <h1>Hello GeeksforGeeks</h1> <p> A Computer Science portal for geeks<br> A Computer Science portal for geeks<br> A Computer Science portal for geeks<br> </p> </body> </html>
Output

Basics of HTML
HTML Horizontal Lines
The <hr> tag creates a horizontal line across the page, often used to separate sections of content. This tag is self-closing and doesn’t require a closing </hr> tag.
Syntax
<hr>
Example: This example shows the use of horizontal row tag in an HTML document.
html <!DOCTYPE html> <html> <head> <title>Horizontal row</title> </head> <body> <h1>Hello GeeksforGeeks</h1> <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>
Output

Basics of HTML
HTML Images
The image tag is used to insert an image into our web page. It requires the src attribute for the image path and the alt attribute for alternative text (useful for accessibility and SEO).
Syntax
<img src="geeks.png" alt="image">
Attributes in Images
- src: Specifies the URL or path of the image file.
- alt: Provides a text description of the image, shown if the image cannot be displayed.
- width and height: Control the dimensions of the image.
<img src="geeks.png" alt="image" width="500" height="300">
Example: This example shows the use of HTML images in an HTML document.
html <!DOCTYPE html> <html> <head> <title>HTML Images</title> </head> <body> <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png"> </body> </html>
Output

HTML Course: Basics of HTML
HTML – Attributes
An attribute is used to provide extra or additional information about an element. It takes two parameters name and value.
The name parameter takes the name of the property we would like to assign to the element and the value takes the properties value or extent of the property names that can be aligned over the element. Every name has some value that must be written within quotes. (e.g., class=”example”).
Common Attributes
- id: Uniquely identifies an element.
- class: Assigns a CSS class to the element for styling.
- style: Allows inline styling (e.g., style=”color:red;”)
<p id="intro" class="text-large" style="color: blue;">This is a paragraph with an ID, class, and inline style.</p>
Example: This example shows the use of href, height,width and src attribute in an HTML document.
HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML Attributes</title> </head> <body> <h2>Link with href Attribute</h2> <a href="https://www.geeksforgeeks.org/" target="_blank" title="Geeks"> GeeksforGeeks </a> <h2>Image with src, height, and width Attributes:</h2> <img src="https://media.geeksforgeeks.org/gfg-gg-logo.svg" alt="GeeksforGeeks Image" height="200" width="300"> </body> </html>
Output

HTML Course: Basics of HTML
Comments are not displayed on the webpage; they’re used to explain the code. Comments are helpful for documentation or temporarily disabling code.
Using comments, specially in complex code, is the best practice of coding so that coder and reader can get help for understanding. It gives help to coder / reader of code to identify pieces of code specially in complex source code.
Syntax
<!-- Write your comments here -->
Example: This example shows the use of HTML comments in an HTML document.
HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>comment in HTML</title> </head> <body> <!-- there is a comment --> <p>GeeksforGeeks</p> </body> </html>
Output

HTML Course: Basics of HTML
HTML – Lists
A list is a record of short pieces of information, such as people’s names, usually written or printed with a single thing on each line and ordered in a way that makes a particular thing easy to find. For example shopping list , To-do list etc. HTML offers three ways for specifying lists of information. All lists must contain one or more list
- unordered list (ul) : This will list items using plain bullets.
- ordered list (ol) : This will use different schemes of numbers to list your items.
- definition list (dl) : This arranges your items in the same way as they are arranged in a dictionary.
Example: This example illustrates the use of HTML list with help of HTML document.
HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML list</title> <style> h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3>HTML Lists</h3> <h2>Ordered List:</h2> <ol> <li>DSA</li> <li>MERN</li> <li>MEAN</li> </ol> <h2>Unordered List:</h2> <ul> <li>DSA</li> <li>MERN</li> <li>MEAN</li> </ul> </body> </html>
Output

HTML Course: Basics of HTML
HTML Tables
HTML table is a structured way to display data in rows and columns on a web page. It consists of a series of elements that define the structure of the table and its contents.
- <table>: The main container element for the table. It contains all the rows and columns of the table.
- <tr>: Defines a single row in the table. It contains one or more <td> or <th> elements.
- <td>: Defines a cell in a table row. It contains the actual data of the table.
- <th>: Defines a header cell in a table. It is typically used to represent column or row headers and is usually bold and centered by default.
Example: Below example shows how we can create a table in HTML.
HTML <!DOCTYPE html> <html> <head> <style> body{ text-align: center; } h1{ color: green; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid black; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h3>HTML Tables</h3> <table> <thead> <tr> <th>Name</th> <th>Roll No</th> <th>Div</th> </tr> </thead> <tbody> <tr> <td>Prasad Bade</td> <td>23</td> <td>D</td> </tr> <tr> <td>Saurabh Puri</td> <td>87</td> <td>A</td> </tr> </tbody> </table> </body> </html>
Output

HTML Course: Basics of HTML
Similar Reads
Introduction to HTML and CSS | Learn to Design Your First Website in Just 1 Week
Ready to Design Your First Website in Just 1 Week? With this guide, learn how to build a simple yet stylish website in just one week to gain skills and confidence. This is an introduction course to HTML and CSS which will help you learn all about the basics of HTML and CSS needed to begin with Web D
4 min read
HTML Course | Structure of an HTML Document
HTML (Hypertext Markup Language) is the standard language used to create webpages. It forms the backbone of web development, providing the structure and content for websites. If you're new to web development, understanding HTML is the first step in creating web pages. What is an HTML Document?HTML i
4 min read
HTML Course | First Web Page Printing Hello World
So far, we have already learned about the structure of an HTML document, tags, etc in the previous module. Let us use this knowledge to create our first web page. Here, we are creating a simple webpage that displays a "Hello World" message as the perfect starting point. This exercise will help you u
2 min read
HTML Course | Basics of HTML
Now that you've created your first "Hello World" webpage, it's time to learn some important concepts of HTML. In this chapter, weâll cover basic elements that add content and structure, including paragraphs, images, lists, attributes, comments, and more. Table of Content HTML Paragraph HTML Horizont
6 min read
HTML Course | Starting the Project - Creating Directories
Now we have understood the important concepts of HTML, it's time to start building a structured web project. In this chapter, youâll learn how to set up directories and organize files efficiently. It is important to have a well-structured directory for both small and large projects, as it makes your
3 min read
HTML Course | Understanding and Building Project Structure
Now that you've already set up a basic directory structure, it's time to understand and build the basic structure of our project. Course Navigation We have already created all of the directories needed for our project. Let's just start writing our HTML code. Since we are designing a single-page webs
3 min read
CSS Introduction
CSS (Cascading Style Sheets) is a language designed to simplify the process of making web pages presentable. It allows you to apply styles to HTML documents by prescribing colors, fonts, spacing, and positioning.The main advantages are the separation of content (in HTML) and styling (in CSS) and the
5 min read
HTML Course | Creating Navigation Menu
A navigation menu is the first element we see in any website. It allows users to explore different pages and sections easily. In this chapter, youâll learn how to create a navigation menu in HTML. Course Navigation In the last chapter, we have created the entire structure of our website using HTML e
6 min read
HTML Course | Building Header of the Website
The header is the top part of the website and the important area for branding and navigation. In this chapter, youâll learn how to build a header with the tags which we have already learnt. Course Navigation So far, we have created the navigation bar for the header of our website. The next thing to
4 min read
HTML Course | Building Main Content - Section 1
The main content of a website is where you show the core information that visitors are looking for. This could be text, images, links, or any important details about your services, products, or ideas. Course Navigation We just completed building the header for our website. Let's start building the m
4 min read