Introduction of HTML
Introduction of HTML
Introduction to HTML
What is HTML?
All HTML documents must start with a document type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>
</body>
</html>
Example Explained
The <!DOCTYPE html> declaration defines that this document is an HTML5 document
The <html> element is the root element of an HTML page
The <head> element contains meta information about the HTML page
The <title> element specifies a title for the HTML page (which is shown in the browser's
title bar or in the page's tab)
The <body> element defines the document's body, and is a container for all the visible
contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
The <h1> element defines a large heading
The <p> element defines a paragraph
HTML Elements
The HTML element is everything from the start tag to the end tag:
<tagname>Content goes here...</tagname>
Examples of some HTML elements:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Nested HTML Elements
HTML elements can be nested (this means that elements can contain other elements).
The following example contains four HTML elements (<html>, <body>, <h1> and <p>):
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Physical and Logical tags are used in HTML for better visibility and understanding of the text by
the user on the web page. However, both tags differ from each other as suggested by their
names.
Logical Tags :
Logical Tags are used in HTML to display the text according to the logical styles. Following are
the Logical tags commonly used in HTML.
Logical Tags
Tag Description
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<address>, 5th & 6th Floor, Royal Kapsons, A- 118, Sector- 136, Noida,
Uttar Pradesh (201305) </address> <br>
<blockquote cite="https://www.geeksforgeeks.org/">
A Computer Science portal for geeks. It contains well written, well thought and well
explained computer science and programming articles, and quizzes.
</blockquote>
<p>
<dfn> GeeksforGeeks </dfn> is a Computer Science portal for geeks. It contains well
written, well thought and well explained computer science and programming articles,
and quizzes.
</p>
Congratulations !!
We are delighted to inform you that you are going to be part of GfG journey.
</body>
</html>
Types of Images
Images can improve the design and the appearance of a web page.
HTML Images Syntax
Images are not technically inserted into a web page; images are linked to web pages.
The <img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
Syntax
The required src attribute specifies the path (URL) to the image.
Example
The required alt attribute provides an alternate text for an image, if the user for some reason
cannot view it (because of slow connection, an error in the src attribute, or if the user uses a
screen reader).
Example
You can use the style attribute to specify the width and height of an image.
Example
The width, height, and style attributes are all valid in HTML.
However, we suggest using the style attribute. It prevents styles sheets from changing the size
of images:
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100%;
}
</style>
</head>
<body>
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
</body>
</html>
Image as a Link
To use an image as a link, put the <img> tag inside the <a> tag:
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;">
</a>
Image Floating
Use the CSS float property to let the image float to the right or to the left of a text:
Example
Lists in HTML
There are ordered and unordered lists in HTML. Here’s how you can create both:
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Tables in HTML
A table is created using the <table> tag with nested elements like <tr>, <th>, and <td>.
Example:
html
CopyEdit
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
Frames in HTML
Frames are created using the <iframe> tag, which allows embedding another HTML page within
the current page.
Example:
html
CopyEdit
<iframe src="https://www.example.com" width="600" height="400" title="Description of the
page"></iframe>
Frame Attributes:
Example:
html
CopyEdit
<audio controls>
<source src="audio.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
Attributes:
The <video> tag allows you to embed videos directly into your page.
Example:
html
CopyEdit
<video controls width="600">
<source src="video.mp4" type="video/mp4">
<source src="video.ogg" type="video/ogg">
Your browser does not support the video element.
</video>
Attributes:
Forms are used to collect user input. A form starts with the <form> tag.
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
html
CopyEdit
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
Checkbox:
html
CopyEdit
<input type="checkbox" name="subscribe" value="newsletter"> Subscribe
Select Dropdown:
html
CopyEdit
<select name="country">
<option value="usa">USA</option>
<option value="canada">Canada</option>
</select>
Textarea:
html
CopyEdit
<textarea name="message" rows="4" cols="50"></textarea>
Form Attributes: