HTML5 Introduction FC
HTML5 Introduction FC
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
Removed Elements Use Instead Elements
<center> CSS
<dir> <ul>
<font> CSS
<frame>
<frameset>
<noframes>
<isindex>
<tt> CSS
<!DOCTYPE html>
<html>
<head>
<title>HTML 5</title>
<style>
h1 {
font-size:50px;
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
</body>
</html>
Output:
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>HTML 5 Demo</title>
<style>
.GFG {
font-size:40px;
font-weight:bold;
color:green;
body {
text-align:center;
</style>
</head>
<body>
<aside>
</body>
</html>
Output:
HTML
<!DOCTYPE html>
<html>
<body>
<form>
<p>
</p>
<p>
<textarea spellcheck="true"></textarea>
</p>
<button type="reset">Reset</button>
</form>
</body>
</html>
Output:
Disabling Spell Check in a HTML Form: To disable spellcheck in a HTML form the
spellcheck attribute is set to “false”. Below is the sample HTML program with disabled
spellcheck.
Example:2
HTML
<!DOCTYPE html>
<html>
<body>
<form>
<p>
</p>
<p>
<textarea spellcheck="false"></textarea>
</p>
<button type="reset">Reset</button>
</form>
</body>
</html>
Output:
Supported Browsers: The browser supported by spellcheck attribute are listed below:
Google Chrome 9.0
Internet Explorer 11.0
Firefox
Opera
Safari
HTML | Editors
Difficulty Level : Basic
Last Updated : 05 Dec, 2018
HTML text editors are used to create and modify web pages. HTML codes can be written
in any text editors including the notepad. One just needs to write HTML in any text
editor and save the file with an extension “.html”. Some of the popular HTML text
editors are given below:
Notepad
Notepad++
Sublime Text 3
Atom
GeeksforGeeks IDE
Notepad: Notepad is a simple text editor. It is an inbuilt desktop application available in
Windows OS.
Bracket: Bracket is an open-source software primarily used for Web development. It
provides live HTML, CSS, JavaScript editing functionality.
Sublime Text 3: Sublime is a cross platform code editor tool. It supports all markup
languages.
Atom: Atom is an open source code editor tool for MAC, Linux and Windows.
Steps to write HTML code in Editor:
1. Open any of the text editors of your choice. Here we are using the notepad text
editor.
4. Save the file with a suitable name of your choice and .html extension.
5. Open the saved HTML file in your favourite browser (double click on the file, or
right-click – and choose “Open with”).
GeeksforGeeks IDE: It is an online code editor to test the code. It provides the shareable
link to share code with others.
<html>
<head>
<style>
h1 {
color:#009900;
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
</body>
</html>
HTML Comments
Difficulty Level : Basic
Last Updated : 04 Feb, 2021
The comment tag (<!– Comment –>) is used to insert comments in the HTML code. It is
a good practice of coding so that coder and the reader can get help to understand the
code. It is helpful to understand the complex code. The comment tag is useful during the
debugging of codes.
It is a simple piece of code that is wiped off (ignore) by web browsers i.e, not
displayed by the browser.
It helps the coder and reader to understand the piece of code used for especially in
complex source code.
Syntax:
<!-- Comments here -->
Types of HTML Comments: There are three types of comments in HTML which are:
Single-line comment
Multi-lines comment
Using <comment> tag
Single-line comment:
HTML
<!DOCTYPE html>
<html>
<body>
<!--This is heading Tag -->
<h1>GeeksforGeeks</h1>
</body>
</html>
Output: Here you can see the single-line comment. Single line comment will not display
in the output.
Multi-line comment: Multiple lines can be also used by using the (<!– –>).
HTML
<!DOCTYPE html>
<html>
<body>
<!-- This is
<!-- This is
multi-line
comment -->
</body>
</html>
Output: Here we can see that in the comment section we have used multiple lines but
still it’s not printed.
Using <comment> tag: There used to be an HTML <comment> tag, but it is not
supported by any modern browser.
HTML
<!DOCTYPE html>
<html>
<body>
<comment>This is heading tag</comment>
<h1>GeeksforGeeks</h1>
<comment>This is multi-line
comment
</comment>
</body>
</html>
Output:
HTML | Layout
Difficulty Level : Medium
Last Updated : 12 Aug, 2021
Page layout is the part of graphic design that deals with the arrangement of visual
elements on a page. Page layout is used to make the web pages look better. It establishes
the overall appearance, relative importance, and relationships between the graphic
elements to achieve a smooth flow of information and eye movement for maximum
effectiveness or impact.
Header: The part of a front end which is used at the top of the page. <header> tag is
used to add header section in web pages.
Navigation bar: The navigation bar is same as menu list. It is used to display the
content information using hyperlink.
Index / Sidebar: It holds additional information or advertisements and is not always
necessary to be added into the page.
Content Section: The content section is the main part where content is displayed.
Footer: The footer section contains the contact information and other query related to
web pages. The footer section always put on the bottom of the web pages. The
<footer> tag is used to set the footer in web pages.
Example:
html
<!DOCTYPE html>
<html>
<head>
<title>Page Layout</title>
<style>
.head1 {
font-size:40px;
color:#009900;
font-weight:bold;
.head2 {
font-size:17px;
margin-left:10px;
margin-bottom:15px;
body {
margin: 0 auto;
background-position:center;
background-size: contain;
}
.menu {
position: sticky;
top: 0;
background-color: #009900;
color:white;
margin: 0 auto;
overflow: hidden;
.menu a {
float: left;
color: white;
text-align: center;
text-decoration: none;
font-size: 20px;
.menu-log {
right: auto;
float: right;
footer {
width: 100%;
bottom: 0px;
background-color: #000;
color: #fff;
position: absolute;
padding-top:20px;
padding-bottom:50px;
text-align:center;
font-size:30px;
font-weight:bold;
.body_sec {
margin-left:20px;
</style>
</head>
<body>
<header>
<div class="head1">GeeksforGeeks</div>
</header>
<div class="menu">
<a href="#home">HOME</a>
<a href="#news">NEWS</a>
<a href="#notification">NOTIFICATIONS</a>
<div class="menu-log">
<a href="#login">LOGIN</a>
</div>
</div>
<section id="Content">
<h3>Content section</h3>
</section>
</div>
<footer>Footer Section</footer>
</body>
</html>
Output:
Supported Browser:
Google Chrome
Microsoft Edge
Firefox
Opera
Safari
HTML is the foundation of webpages, is used for webpage development by structuring
websites and web apps.
CSS is the foundation of webpages, is used for webpage development by styling websites
and web apps.You can learn CSS from the ground up by following this
HTML Elements
Difficulty Level : Basic
Last Updated : 09 Dec, 2021
In this article, we will know the HTML Elements, along with understanding the various
available elements & their syntax through the examples. An HTML element is the
collection of start and end tags with the content inserted in between them.
Syntax:
<tagname > Contents... </tagname>
Supported Tags: HTML Elements supports almost all HTML Tags.
Example 1: In this example <p> is a starting tag, </p> is an ending tag and it contains
some content between the tags, which form an element.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements</title>
</head>
<body>
<h2>Welcome To GeeksforGeeks</h2>
<p>Hi Geeks!</p>
</body>
</html>
Output:
Example 2: This example illustrates the use of the HTML paragraph element.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements</title>
</head>
<body>
<p>Welcome to GeeksforGeeks!</p>
</body>
</html>
Output:
Welcome to GeeksforGeeks!
Nested HTML Elements: The HTML element is use inside the another HTML Element
is called nested HTML elements.
Example 3: This example describes the use of the Nested HTML elements. Here, <html>
tag contains the <head> and <body>. The <head> and <body> tag contains another
elements so it is called nested element.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements</title>
</head>
</body>
</html>
Output:
Necessary to add end tag: It is necessary to add the end tag of an element. Otherwise,
the displayed content may or may not be displayed correctly.
Example 4: This example describes the HTML element by specifying the end tag.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Welcome To GfG</h2>
<br />
<p>Hello Geeks.</p>
</body>
</html>
Output:
HTML empty element
HTML Heading
Difficulty Level : Basic
Last Updated : 09 Dec, 2021
In this article, we will know HTML Heading, & its implementation through the
examples. An HTML heading tag is used to define the headings of a page. There are six
levels of headings defined by HTML. These 6 heading elements are H1, H2, H3, H4, H5,
and H6; with H1 being the highest level and H6 the least.
Syntax:
<h1></h1>
<h3></h3>
<h6></h6>
Importance of Heading:
Search Engines use headings for indexing the structure and content of the webpage.
Headings are used for highlighting important topics.
They provide valuable information and tell us about the structure of the document.
Example 1: This example illustrates the HTML heading tags.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Heading Tags</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>GeeksforGeeks</h2>
<h3>GeeksforGeeks</h3>
<h4>GeeksforGeeks</h4>
<h5>GeeksforGeeks</h5>
<h6>GeeksforGeeks</h6>
</body>
</html>
Output:
HTML Headings
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to GeeksforGeeks</h1>
<h5>Tutorial</h5>
<h6>Geeks</h6>
</body>
</html>
Output:
Changing the size of HTML Headings: The default size of HTML headings can be
changed using the style attribute.
Example: This example explains the HTML heading tags by specifying the size of the
font.
HTML
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Horizontal rule: The <hr> tag which stands for the horizontal rule is used to define a
thematic break in an HTML page. The <hr> tag is an empty tag, and it does not require
an end tag. It is basically used to separate content. Please refer to the HTML <hr>
Tag article for further details.
Example: This example explains the HTML Headings with horizontal rules.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>Heading 1</h1>
<hr />
<h2>Heading 2</h2>
<hr />
<h2>Heading 3</h2>
</html>
Output:
HTML Paragraphs
Difficulty Level : Basic
Last Updated : 09 Dec, 2021
In this article, we will know the HTML Paragraphs, & its basic implementation through
the examples. The <p> tag in HTML defines a paragraph. These have both opening and
closing tags. So anything mentioned within <p> and </p> is treated as a paragraph. Most
browsers read a line as a paragraph even if we don’t use the closing tag i.e, </p>, but this
may raise unexpected results. So, it is both a good convention, and we must use the
closing tag.
Syntax:
<p> Content </p>
Example 1: In this example, we are using the <p> tag that is used for paragraphs in
HTML.
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Welcome To GeeksforGeeks</h2>
</body>
</html>
Output:
HTML <p> tag
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<p>
</p>
<p>
</body>
</html>
Output:
<br> tag: There is a way to let the HTML know where does the browser need to change
the lines by the use of the <br> tag. These tags do not have any closing tag. So, just a
single opening tag will change the line.
Syntax:
<br>
Example: This example explains the <br> tag inside the <p> tag to add the line-break.
HTML
<!DOCTYPE html>
<html>
<body>
<p>
This paragraph has multiple
</p>
</body>
</html>
Output:
Align attribute: The <p> tag specifically supports the alignment attribute and allows us
to align our paragraphs in left, right, or center alignment.
Syntax:
<p align="value">
Example: This example explains the align attribute to align the content in the <p> tag.
HTML
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
<pre> tag: We have seen how the paragraph tag ignores all the changes of lines and
extra spaces within a paragraph, but there is a way to preserve this by the use
of <pre> tag. It also contains an opening and a closing tag. It displays a text within a
fixed height and width and preserves the extra lines and spaces we use.
Syntax:
<pre> Content </pre>
Example: This example explains the use of the <pre> tag in the <p> tag.
HTML
<!DOCTYPE html>
<html>
<body>
<pre>
tag.
</pre>
<pre>
tag.
</pre>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<h2>Welcome To GeeksforGeeks</h2>
<!--Text in Strong-->
<strong>Hello Geeks</strong>
<br>
<!--Text in small-->
<small>Hello Geeks</small>
<br>
<!--Text in Highlight-->
<mark>Hello Geeks</mark>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title>Bold Text</title>
</head>
<body>
<!--Normal text-->
<p>Hello GeeksforGeeks</p>
<!--Text in Bold-->
<p>
<b>Hello GeeksforGeeks</b>
</p>
<!--Text in Strong-->
<p>
<strong>Hello GeeksforGeeks</strong>
</p>
</body>
</html>
Output:
Making text Italic or emphasize: The <i> tag is used to italicise the text. It opens with
<i> and ends with </i> tag. The <em> tag is used to emphasize the text, with added
semantic importance. It opens with <em> and ends with </em> tag.
Example 2: The below example describes the formatting of the text to Italic or
emphasize.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Italic</title>
</head>
<body>
<!--Normal text-->
<p>Hello GeeksforGeeks</p>
<!--Text in Italics-->
<p>
<i>Hello GeeksforGeeks</i>
</p>
<!--Text in Emphasize-->
<p>
<em>Hello GeeksforGeeks</em>
</p>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title>Highlight</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Highlight-->
<p>
<mark>Hello GeeksforGeeks</mark>
</p>
</body>
</html>
Output:
Using <mark> Tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Superscript-->
<p>Hello
<sup>GeeksforGeeks</sup>
</p>
<!--Text in Subscript-->
<p>Hello
<sub>GeeksforGeeks</sub>
</p>
</body>
</html>
Output:
Making text smaller: The <small> element is used to make the text smaller. The text
that needs to be displayed smaller should be written inside <small> and </small> tag.
Example: The below example describes the use of the <small> tag that is used to set
small font size.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Small</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in small-->
<p>
<small>Hello GeeksforGeeks</small>
</p>
</body>
</html>
Output:
Striking through the text: The <del> element is used to strike through the text marking
the part as deleted. It also has an opening and a closing tag.
Example: The below example describes the use of the <del> tag that is used to mark a
portion of text which has been deleted from the document.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Delete</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Delete-->
</body>
</html>
Output:
Adding a text: The <ins> element is used to underline a text marking the part as inserted
or added. It also has an opening and a closing tag.
Example: This example describes the use of the <ins> tag to used to specify a block of
inserted text.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Insert-->
<p><ins>Hello GeeksforGeeks</ins></p>
</body>
</html>
Output:
HTML | Quotations
Difficulty Level : Easy
Last Updated : 12 Aug, 2021
The Quotation elements in HTML are used to insert quoted texts in a web page, that is,
portion of texts different from the normal texts in the web page.
Below are some of the most used quotation elements of HTML:
1. <q> element:
The <q> element is used to set a set of text inside the quotation marks. It has both
opening and closing tags.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Quotations</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
<!--Inside quotes-->
</body>
</html>
1. Output:
1. <blockquote> element:
The <blockquote> element is also used for quotations in a different way. Instead of
putting the text in quotes, it changes the alignment to make it unique from others. It
has both opening and closing tags.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Blockquote</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
<!--Inside blockquotes-->
</body>
</html>
1. Output:
1. <address> element:
Using the <address> element, we can define an address in a webpage and the text put
inside the address tag will be emphasized. It has both opening and closing tags.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Address</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
<address>
<p>Address:<br>
</address>
</body>
</html>
1. Output:
1. <abbr> element:
The <abbr> element is used to define a text as an acronym or abbreviations. The title
attribute can be used to show the full version of the abbreviation/acronym when you
mouse over the <abbr> element. It has both opening and closing tags. This is useful
for browsers and search engines.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Abbreviations</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
</body>
</html>
1. Output:
1. <bdo> element:
The <bdo> element is used to define a bidirectional override which means that the
text written from right to left or left to right. It has both opening and closing tags. It is
used to over-ride the current text direction.It takes an attribute “rtl” to display the text
from right to left.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Bidirectional</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
<!--Normal text-->
</body>
</html>
1. Output:
1. <cite> element:
This element is used define a title of a work and emphasizes a text.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Cite</title>
</head>
<body>
<h3>GeeksforGeeks</h3>
</body>
</html>
1. Output:
HTML | Links
Difficulty Level : Basic
Last Updated : 12 Aug, 2021
What is a link?
It is a connection from one web resource to another.A link has two ends,An anchor and
direction. The link starts at the “source” anchor and points to the “destination” anchor,
which may be any Web resource such as an image, a video clip, a sound bite, a program,
an HTML document or an element within an HTML document.
Syntax Explanation:
href : The href attribute is used to specify
the destination address of the link used.
Text link : The text link
is the visible part of the link.
Input :
html
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output :
Internal Links
An internal link is a type of hyperlink whose target or destination is a resource, such as an
image or document, on the same website or domain.
Input:
html
<!DOCTYPE html>
<html>
<body>
<p><a href="https://www.geeksforgeeks.org">GeeksforGeeks
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
color: red;
background-color: transparent;
a:visited {
color: green;
background-color: transparent;
a:hover {
color: blue;
background-color: transparent;
a:active {
color: yellow;
background-color: transparent;
}
</style>
</head>
<body>
<p>Visited Link</p>
<a href="https://www.geeksforgeeks.org">GeeksforGeeks</a>
<p>Link</p>
<a href="https://facebook.com">facebook</a>
<p>hovering effect</p>
<a href="https://www.geeksforgeeks.org">GeeksforGeeks</a>
</body>
</html>
Output:
Input:
html
<!DOCTYPE html>
<html>
<body>
<a href="https://www.geeksforgeeks.org"
target="_self">GeeksforGeeks</a>
<a href="https://www.geeksforgeeks.org"
target="_top">GeeksforGeeks</a>
<a href="https://www.geeksforgeeks.org"
target="_parent">GeeksforGeeks</a>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<a href="https://www.geeksforgeeks.org">
style="width:80px;height:80px;border:0">
</a>
</body>
</html>
Output:
Creating a Bookmark Link for a Webpage
A bookmark is a link that can be used to jump to specified portion of a
webpage.Bookmarks are very useful if a webpage is quite long.
Steps to create a bookmark are:
1. Using the id attribute,create a bookmark.
Input :
html
<!DOCTYPE html>
<html>
<body>
<h2>Topic 1</h2>
<p>paragraph 1
.....</p>
<h2>Topic 2</h2>
<p>paragraph 1
.....</p>
<h2>Topic 3</h2>
<p>paragraph 1
.....</p>
<h2>Topic 4</h2>
<p>paragraph 1
.....</p>
<h2>Topic 5</h2>
<p>paragraph 1
.....</p>
<h2>Topic 6</h2>
<p>paragraph 1
.....</p>
<h2>Topic 7</h2>
<p>paragraph 1
.....</p>
<h2>Topic 8</h2>
<p>paragraph 1
.....</p>
<h2>Topic 9</h2>
<p>paragraph 1
.....</p>
<h2>Topic 10</h2>
<p>paragraph 1
.....</p>
<p>paragraph 1
.....</p>
<h2>Topic 12</h2>
<p>paragraph 1
.....</p>
<h2>Topic 13</h2>
<p>paragraph 1
.....</p>
<h2>Topic 14</h2>
<p>paragraph 1
.....</p>
<h2>Topic 15</h2>
<p>paragraph 1
.....</p>
<h2>Topic 16</h2>
<p>paragraph 1
.....</p>
<p>paragraph 1
.....</p>
<h2>Topic 18</h2>
<p>paragraph 1
.....</p>
<h2>Topic 19</h2>
<p>paragraph 1
.....</p>
<h2 id="T20">Topic 20</h2>
<p>paragraph 1
.....</p>
</body>
</html>
Output:
html
<!DOCTYPE html>
<html>
</body>
</html>
Output: :
HTML Images
Difficulty Level : Basic
Last Updated : 08 Dec, 2021
In this article, we will know the HTML Image, how to add the image in HTML, along
with knowing its implementation & usage through the examples. In earlier times, the web
pages only contains textual contents, which made them appear quite boring and
uninteresting. Fortunately, it wasn’t long enough that the ability to embed images on web
pages was added for users. In this article, we will know how to add images to the web
page that will make the website attractive & various methods to insert the images.
There are 2 ways to insert the images into a webpage:
By providing a full path or address (URL) to access an internet file.
By providing the file path relative to the location of the current web page file.
We will first discuss inserting the image to the webpage & simultaneously, we will
understand both the above approaches.
Adding images on a webpage: The <img> tag is used to add or embed the images to a
webpage/website. The “img” tag is an empty tag, which means it can contain only a list
of attributes and it has no closing tag. The addition of the images improves the quality
along with enhancing the design structure, appearance of the webpage. Nowadays, a
website does not directly add images to a web page, as the images are linked to web
pages by using the <img> tag which holds space for the image.
Syntax:
<img src="url" alt="some_text" width="" height="">
Attribute: The <img> tag has following attributes:
src: It is used to specify the path to the image.
alt: It is used to specify an alternate text for the image. It is useful as it informs the
user about what the image means and also due to any network issue if the image
cannot be displayed then this alternate text will be displayed.
crossorigin: It is used to import images from third-party sites that allow cross-origin
access to be used with canvas.
height: It is used to specify the height of the image.
width: It is used to specify the width of the image.
ismap: It is used to specify an image as a server-side image map.
loading: It is used to specify whether a browser should defer the loading of images
until some conditions are met or load an image immediately.
longdesc: It is used to specify a URL to a detailed description of an image.
referrerpolicy: It is used to specify which referrer information to use when fetching
an image i.e. no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-
origin, unsafe-url.
sizes: It is used to specify image sizes for different page layouts.
srcset: It is used to specify a list of image files to use in different situations.
usemap: It is used to specify an image as a client-side image map.
src: The src stands for source. Every image has an src attribute which tells the browser
where to find the image you want to display. The URL of the image provided points to
the location where the image is stored. When the webpage loads for the first time, then
the browser gets the image from a web server and inserts it into the page. If the image is
not spotted by the browser then users will get a broken link icon. It might be possible if
the file path is wrong or the image got deleted from that location.
Example 1: This simple example illustrates the use of the <img> tag in HTML that is
used to embed the image into the webpage.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Welcome To GFG</title>
</head>
<body>
<h2>GeeksforGeeks</h2>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/
20210915115837/gfg3-300x300.png"
</body>
</html>
Output:
Example 2: The example illustrates the use of the src attribute in the <img> tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"/>
</body>
</html>
Output:
alt: If the image cannot be displayed then the alt attribute acts as an alternative
description for the image. The value of the alt attribute is a user-defined text. It generally
happens when the user, for some reason, cannot view it due to a slow internet connection
or an error in the src attribute, or if the user uses a screen reader.
Example 3: The example illustrates the use of the alt attribute in the <img> tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
</body>
</html>
Output:
Adding image name in the alt attribute
Setting width and height of Image: The width and height attributes are used to specify
the height and width of an image. The attribute values are specified in pixels by default.
The width and height attributes are always declared in pixels. Please refer to the How to
set the width and height of an image using HTML? article for further details.
Example 4: The example illustrates the use of the width & height attribute in the <img>
tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="300"
height="300" />
</body>
</html>
Output:
Setting the width & height of the image
Adding titles to Image: Along with the images, titles can also be added to images to
provide further information related to the inserted image. For inserting a title, the title
attribute is used. Please refer to the HTML | title Attribute article for further details.
Example 5: The example illustrates the use of the title attribute in the <img> tag.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
border="5" />
</body>
</html>
Output:
Aligning an Image: By default, an image is aligned on the left side of the page, but it
can be aligned to the centre or right using the align attribute. Please refer to the HTML |
<img> align Attribute for further details.
Example 7: This example illustrates the use of align property in the <img> tag whose
value is set to right.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Aligning an image</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
alt="GeeksforGeeks logo"
align="right" />
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>GeekforGeeks</h3>
<a href="https://ide.geeksforgeeks.org/tryit.php">
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png"
</a>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<img src="smiley.gif"
alt="smiley"
</body>
</html>
Output:
Adding an image in GIF format
<!DOCTYPE html>
<html>
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/
20190710102234/download3.png'
);">
<h2>Image As a Background</h2>
<p>
In this example we have specified a
</p>
</body>
</html>
Output:
Common Image Format: Here is the commonly used image file format that is supported
by all the browsers.
Abbreviatio
S.No. n File Type Extension
PNG
1. Portable Network Graphics. .png
SVG
3. Scalable Vector Graphics. .svg.
GIF
4. Graphics Interchange Format. .gif
ICO
5. Microsoft Icon. .ico, .cur
HTML Tables
Difficulty Level : Easy
Last Updated : 15 Dec, 2021
In this article, we will know the HTML Table, various ways to implement it, & will also
understand its usage through the examples. HTML Table is an arrangement of data in
rows and columns, or possibly in a more complex structure. Tables are widely used in
communication, research, and data analysis. Tables are useful for various tasks such as
presenting text information and numerical data. It can be used to compare two or more
items in the tabular form layout. Tables are used to create databases.
Defining Tables in HTML: An HTML table is defined with the “table” tag. Each table
row is defined with the “tr” tag. A table header is defined with the “th” tag. By default,
table headings are bold and centered. A table data/cell is defined with the “td” tag.
Example 1: In this example, we are creating a simple table in HTML using a table tag.
HTML
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<th>Book Name</th>
<th>Author Name</th>
<th>Genre</th>
</tr>
<tr>
<td>Markus Zusak</td>
<td>Historical Fiction</td>
</tr>
<tr>
<td>Holly Black</td>
<td>Fantasy</td>
</tr>
<tr>
<td>Psychological Fiction</td>
</tr>
</table>
</body>
</html>
Output:
HTML Table
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Accepted Attributes:
<table> cellspacing Attribute
<table> rules Attribute
Adding a border to an HTML Table: A border is set using the CSS border property. If
you do not specify a border for the table, it will be displayed without borders.
Example 3: This example explains the addition of the border to the HTML Table.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding Cell Padding in an HTML Table: Cell padding specifies the space between the
cell content and its borders. If we do not specify a padding, the table cells will be
displayed without padding.
Example 5: This example describes the addition of Table cell padding in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
th,
td {
padding: 20px;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding Left Align Headings in an HTML Table: By default, the table headings are
bold and centered. To left-align the table headings, we must use the CSS text-align
property.
Example 6: This example explains the text-align property where the text is aligned to the
left.
HTML
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
th,
td {
padding: 20px;
th {
text-align: left;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
text-align Property
Adding Border Spacing in an HTML Table: Border spacing specifies the space
between the cells. To set the border-spacing for a table, we must use the CSS border-
spacing property.
Example 7: This example explains the border space property to make the space between
the Table cells.
HTML
<html>
<head>
<style>
table,
th,
td {
table {
border-spacing: 5px;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding Cells that Span Many Columns in HTML Tables: To make a cell span more
than one column, we must use the colspan attribute.
Example 8: This example describes the use of the colspan attribute in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
th,
td {
padding: 5px;
text-align: left;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Vikas Rawat</td>
<td>9125577854</td>
<td>8565557785</td>
</tr>
</table>
</body>
</html>
Output:
colspan attribute
Adding Cells that span many rows in HTML Tables: To make a cell span more than
one row, we must use the rowspan attribute.
Example 9: This example describes the use of the rowspan attribute in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
th,
td {
padding: 5px;
text-align: left;
</style>
</head>
<body>
<h2>Cell that spans two rows:</h2>
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Vikas Rawat</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>9125577854</td>
</tr>
<tr>
<td>8565557785</td>
</tr>
</table>
</body>
</html>
Output:
Use of rowspan attribute
Adding a Caption in an HTML Table: To add a caption to a table, we must use the
“caption” tag.
Example 10: This example describes the HTML Table caption by specifying the CSS
properties for setting its width.
HTML
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
}
th,
td {
padding: 20px;
th {
text-align: left;
</style>
</head>
<body>
<table style="width:100%">
<caption>DETAILS</caption>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding the caption using the <caption> tag
Example 11: This example describes the addition of the Table background color in
HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border-collapse: collapse;
th,
td {
padding: 5px;
text-align: left;
table#t01 {
width: 100%;
background-color: #f2f2d1;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
<br />
<br />
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Creating Nested Tables: Nesting tables simply means making a Table inside another
Table. Nesting tables can lead to complex tables layouts, which are visually interesting
and have the potential of introducing errors.
Example 12: This example describes the Nested of HTML Table.
HTML
<!DOCTYPE html>
<html>
<body>
<tr>
<td>
<tr>
</tr>
<tr>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Output:
HTML Lists
Difficulty Level : Easy
Last Updated : 09 Dec, 2021
In this article, we will know the HTML List, along with understanding its types, various
ways to implement them, through the example.
A list is a record of short pieces of related information or used to display the data or any
information in web pages in the ordered or unordered form. For instance, to purchase the
items, we need to prepare a list that can either be ordered or unordered list which helps us
to organize the data & easy to find the item. Please refer to the HTML <li> type
Attribute article for the various types of attributes that can be used with the ordered &
unordered list.
Example: The below example illustrates the use of the unordered & ordered list in
HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<title>GeeksforGeeks</title>
</head>
<body>
<ul>
<li>Web Technology</li>
<li>Programming Languages</li>
</ul>
<ol>
<li>Array</li>
<li>Linked List</li>
<li>Stacks</li>
<li>Queues</li>
<li>Trees</li>
<li>Graphs</li>
</ol>
</body>
</html>
Output:
HTML List
<!DOCTYPE html>
<html>
<body>
<h2>Grocery list</h2>
<ul>
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ul>
</body>
</html>
Output:
Unordered List
<!DOCTYPE html>
<html>
<head>
<title>HTML ul tag</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<ul style="list-style-type:disc">
<li>Geeks</li>
<li>Sudo</li>
<li>Gfg</li>
<li>Gate</li>
<li>Placement</li>
</ul>
</body>
</html>
Output:
Example 2: The Circle can be used to set the list item marker to a circle.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<li>Geeks</li>
<li>Sudo</li>
<li>Gfg</li>
<li>Gate</li>
<li>Placement</li>
</ul>
</body>
</html>
Output:
Unordered List with circle item maker
Example 3: The Square can be used to set the list item marker to a square.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<li>Geeks</li>
<li>Sudo</li>
<li>Gfg</li>
<li>Gate</li>
<li>Placement</li>
</ul>
</body>
</html>
Output:
Example 4: It’s none that can be used to set the list item marker with no mark.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<li>Geeks</li>
<li>Sudo</li>
<li>Gfg</li>
<li>Gate</li>
<li>Placement</li>
</ul>
</body>
</html>
Output:
Unordered List with none item maker
Example: Nested Unordered List, It is used to nest the list items ie., list inside another
list.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<ul>
<li>DSA</li>
<ul>
<li>Array</li>
<li>Linked List</li>
<li>stack</li>
<li>Queue</li>
</ul>
<li>Web Technologies</li>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<li>Aptitude</li>
<li>Gate</li>
<li>Placement</li>
</ul>
</body>
</html>
Output:
Nested Unordered List
HTML Ordered List: An ordered list starts with the “ol” tag. Each list item starts with
the “li” tag. The list items are marked with numbers by default.
Syntax:
<ol>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
</ol>
Attributes:
compact: It defines the list should be compacted (compact attribute is not supported
HTML5. Use CSS instead.).
reversed: It defines that the order will be descending.
start: It defines that from which number or alphabet the order will start.
type: It defines which type(1, A, a, I, and i) of the order you want in your list
numeric, alphabetic, or roman numbers.
Example: This example illustrates the use of the reverse attribute, control list counting &
type attribute.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML ol tag</title>
</head>
<body>
<h3>HTML ol tag</h3>
<p>reversed attribute</p>
<ol reversed>
<li>HTML</li>
<li>CSS</li>
<li>JS</li>
</ol>
<p>start attribute</p>
<ol start="5">
<li>HTML</li>
<li>CSS</li>
<li>JS</li>
</ol>
<p>type attribute</p>
<ol type="i">
<li>HTML</li>
<li>CSS</li>
<li>JS</li>
</ol>
</body>
</html>
Output:
Ordered List with different list style
HTML ordered list has various list item markers: The type attribute of the <ol> tag
defines the type of the list item marker.
Example 1: The list items will be numbered with numbers i.e default.
HTML
<!DOCTYPE html>
<html>
<body>
<ol type="1">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
Example 2: Type=”A”, this list of items will be numbered with uppercase letters.
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Letters</h2>
<ol type="A">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
Example 3: Type=”a”, this list items will be numbered with lowercase letters.
HTML
<!DOCTYPE html>
<html>
<body>
<ol type="a">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
Example 4: Type=”I”, this list items will be numbered with uppercase roman numbers.
HTML
<!DOCTYPE html>
<html>
<body>
<ol type="I">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
Example 5: Type=”i”, this list items will be numbered with lowercase roman numbers.
HTML
<!DOCTYPE html>
<html>
<body>
<ol type="i">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
Example 6: Nested ordered list, a nested ordered list is a list that has a list inside another
list.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<ol>
<li>Coffee</li>
<li> Tea
<ol>
<li>Black tea</li>
<li>Green tea</li>
</ol>
</li>
<li>Milk</li>
</ol>
</body>
</html>
Output:
HTML Description List: A description list is a list of terms, with a description of each
term. The <dl> tag defines the description list, the <dt> tag defines the term name, and
the <dd> tag describes each term. Please refer to the How to add description list of an
element using HTML? article for further details.
Syntax:
<dl> Contents... </dl>
Example: This example describes the HTML Description List.
html
<!DOCTYPE html>
<html>
<body>
<dl>
<dt>Coffee</dt>
<dt>Milk</dt>
</dl>
</body>
</html>
Output:
Description List
<!DOCTYPE html>
<html>
<body>
<div>GeeksforGeeks</div>
<a href="https://www.geeksforgeeks.org/"
alt="GeeksforGeeks">
</body>
</html>
Output:
Block & Inline Elements
In the above example, we have used the <div> tag that always starts in a new line &
captures the full width available. We have used the inline element anchor tag <a>that is
used to provide a link to a text. The inline element doesn’t start in a new line & captures
only the space around the element.
Block Level Elements: A block-level element always starts on a new line and stretches
out to the left and right as far as it can ie, it occupies the whole horizontal space of its
parent element & the height is equal to the content’s height.
Supported tags:
HTML <address> Tag
HTML <blockquote> Tag
HTML <dd> Tag
HTML <Div> Tag
HTML <dl> Tag
HTML <dt> Tag
HTML <canvas> Tag
HTML <form> Tag
HTML <Heading> Tag
HTML <hr> Tag
HTML <li> Tag
HTML <main> Tag
HTML <nav> Tag
HTML <noscript> Tag
HTML <ol> Tag
HTML <pre> Tag
HTML <section> Tag
HTML <tfoot> Tag
HTML <ul> Tag
HTML Tables
HTML Paragraphs
HTML5 <Video> Tag
HTML5 <aside> Tag
HTML5 <article> Tag
HTML5 <figcaption> Tag
HTML5 <fieldset> Tag
HTML5 <figure> Tag
HTML5 <footer> Tag
HTML 5 <header> Tag
div element: The <div> element is used as a container for other HTML elements. It has
no required attributes. Style, class, and id are the commonly used attributes.
Syntax:
<div>GFG</div>
Example: Below code illustrates the implementation of <div> tag.
HTML
<!DOCTYPE html>
<html>
<title>Block-level Element</title>
<body>
<div>
<h1>GeeksforGeeks</h1>
</h3>
</div>
</body>
</html>
Output:
Block Element
Inline Elements: An inline element is the opposite of the block-level element. It does not
start on a new line and takes up only the necessary width ie., it only occupies the space
bounded by the tags defining the HTML element, instead of breaking the flow of the
content.
Supported tags:
HTML <br> Tag
HTML <button> Tag
HTML <time> Tag
HTML <tt> Tag
HTML <var> Tag
HTML <a> Tag
HTML <abbr> Tag
HTML <acronym> Tag
HTML <b> Tag
HTML <cite> Tag
HTML <code> Tag
HTML <dfn> Tag
HTML <em> Tag
HTML <i> Tag
HTML <output> Tag
HTML <q> Tag
HTML <samp> Tag
HTML <script> Tag
HTML <select> Tag
HTML <small> Tag
HTML <span> Tag
HTML <strong> Tag
HTML <sub> Tag
HTML <sup> Tag
HTML <textarea> tag
HTML <bdo> Tag
HTML <big> Tag
HTML <img> Tag
HTML <input> Tag
HTML <kbd> Tag
HTML <label> Tag
HTML <map> Tag
HTML <Object> tag
span element: The <span> tag is used as a container for text. It has no required
attributes. Style, class, and id are the commonly used attributes.
Syntax:
<span>GFG</span>
Example: Below code illustrates the implementation of <span> tag.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align: center;
h1 {
color: green;
</style>
</head>
<body>
<h1>Geeks
Geeks
</h1>
</body>
</html>
Output:
Inline Element
HTML Iframes
Difficulty Level : Medium
Last Updated : 09 Dec, 2021
In this article, we will know HTML Iframes, their implementation through the
examples. The iframe in HTML stands for Inline Frame. The ” iframe ” tag defines a
rectangular region within the document in which the browser can display a separate
document, including scrollbars and borders. An inline frame is used to embed another
document within the current HTML document. The HTML iframe name attribute is used
to specify a reference for an <Iframe> element. The name attribute is also used as a
reference to the elements in JavaScript. The iframe is basically used to show a webpage
inside the current web page. The ‘ src ‘ attribute is used to specify the URL of the
document that occupies the iframe.
Syntax:
<iframe src="URL" title="description"></iframe>
Attributes value: It contains a single value URL that specifies the URL of the document
that is embedded in the iframe. There are two types of URL links which are listed below:
Absolute URL: It points to another webpage.
Relative URL: It points to other files of the same web page.
Example: This example illustrates the use of an iframe tag which is used to display a
webpage inside the current web page.
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<h1>GeeksforGeeks</h1>
<iframe src=
"https://ide.geeksforgeeks.org/index.php"
height="200"
width="400">
</iframe>
</body>
</html>
Output:
HTML iframe tag
Accepted Attribute: The following attributes can be used with the <iframe> tag in
HTML.
HTML <iframe> allow Attribute
HTML <iframe> allowfullscreen attribute
HTML <iframe> allowpaymentrequest attribute
HTML <iframe> height attribute
HTML <iframe> width attribute
HTML <iframe> loading attribute
HTML <iframe> scrolling attribute
HTML <iframe> name attribute
HTML <iframe> referrerpolicy attribute
HTML <iframe> sandbox attribute
HTML <iframe> src attribute
HTML <iframe> srcdoc attribute
Below few of the attributes examples are given:
Height and Width: The height and width attributes are used to specify the size of the
iframe. The attribute values are specified in pixels by default, but they can also be
specified in percentages like ” 80% “.
Example: This example describes the HTML iframe Tag by setting the width & height of
the iframe.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<iframe src=
"https://ide.geeksforgeeks.org/tryit.php"
height="300"
width="400">
</iframe>
</body>
</html>
Output:
Setting the width & height of HTML iframe
Removing Border: By default, iframe has a border around it. To remove the border, we
must use the style attribute and use the CSS border property.
Example: This example describes the HTML iframe Tag where the border property is set
as none.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML iframe Tag</h2>
<iframe src=
"https://ide.geeksforgeeks.org/tryit.php"
height="300"
width="400"
style="border: none">
</iframe>
</body>
</html>
Output:
HTML iframe with no border
Border Style: Changing the size, style, and color of the Iframe’s border:
Example: This example describes the HTML iframe Tag by specifying the border style.
HTML
<!DOCTYPE html>
<html>
<body>
<iframe src=
"https://ide.geeksforgeeks.org/tryit.php"
height="300"
width="400"
</iframe>
</body>
</html>
Output:
Link: An iframe can be used as the target frame for a link. The target attribute of the link
must refer to the name attribute of the iframe.
Example: This example describes the HTML iframe Tag by using the target frame for a
link.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<iframe height="300"
width="350"
src=
"https://media.geeksforgeeks.org/wp-content/uploads/
20210910170539/gfg-221x300.png"
name="iframe_a">
</iframe>
<p><a href=
"https://ide.geeksforgeeks.org/tryit.php"
target="iframe_a">
GeeksforGeeks IDE
</a>
</p>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<script>
function gfg() {
</script>
</head>
<body>
<h2>JavaScript in Head</h2>
</body>
</html>
Output:
Before clicking the button
JavaScript in body: A JavaScript function is placed inside the body section of an HTML
page and the function is invoked when a button is clicked.
Example:
<!DOCTYPE html>
<html>
<center>
<body>
<h2>JavaScript in Body</h2>
<p id="demo">geeksforgeeks.</p>
<script>
function gfg() {
document.getElementById("demo").innerHTML = "Geeks
For Geeks";
</script>
</body>
</center>
</html>
Output:
Before clicking the button
External JavaScript: JavaScript can also be used as external files. JavaScript files have
file extension .js . To use an external script put the name of the script file in the src
attribute of a script tag. External scripts cannot contain script tags.
Example:
<!DOCTYPE html>
<html>
<center>
<body>
<h2>External JavaScript</h2>
<script src="myScript.js"></script>
</body>
<center>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Welcome</h2>
<p id="geek"></p>
<script>
// Statement 1
var a, b, c;
// Statement 2
a = 2;
// Statement 3
b = 3;
// Statement 4
c = a + b;
document.getElementById(
"geek").innerHTML =
</script>
</body>
</html>
Output:
Multiple statements on one line are allowed if they are separated with a semicolon.
a=2;b=3;z=a+b;
2. Code Blocks:
JavaScript statements can be grouped together inside curly brackets. Such groups are
known as code blocks. The purpose of grouping is to define statements to be executed
together.
Example:JavaScript function
<!DOCTYPE html>
<html>
<body>
<p>Welcome</p>
<button type="button"
onclick="myFunction()">
Click Me!
</button>
<p id="geek1"></p>
<p id="geek2"></p>
<script>
function myFunction() {
document.getElementById(
"geek1").innerHTML = "Hello";
document.getElementById(
"geek2").innerHTML =
</script>
</body>
</html>
Output:
Before Click:
After Click:
3. White Space:
Javascript ignores multiple white spaces.
Javascript would treat following 2 statements as same:
Example:
var a="Hello Geek";
var a = "Hello Geek";
4. Line Length and Line Breaks:
Javascript code preferred line length by most programmers is upto 80 characters.
The best place to break a code line in Javascript, if it doesn’t fits, is after an
operator.
Example:
5. document.getElementById("geek1").innerHTML =
6. "Hello Geek!";
7. Keywords:
Keywords are reserved words and cannot be used as variable name.
A Javascript keyword tells about what kind of operation it will perform.
Some commonly used keywords are:
break: This is used to terminate a loop or switch.
continue: This is used to skip a particular iteration in a loop and move to next
iteration.
do…. while: In this the statements written within do block are executed till the
condition in while is true.
for: It helps in executing a block of statements till the condition is true.
function: This keyword is used to declare a function.
return: This keyword is used to exit a function.
var: This keyword is used to declare a variable.
switch: This helps in executing a block of codes depending on different cases.