01.Html Textbook
01.Html Textbook
HTML Tutorial
Read Discuss Courses
HTML stands for HyperText Markup Language. It is used to design the web
pages. With the help of HTML, you can create a complete website structure.
HTML is the combination of Hypertext and Markup language. Hypertext defines
the link between the web pages and markup language defines the text document
within the tag that define the structure of web pages. This HTML Tutorial is
designed to provide basic to advanced HTML concepts for beginners and
professionals both.
HTML Tutorial
<html> – This tag is used to define the root element of HTML document. This
tag tells the browser that it is an HTML document. It is the second outer
container element that contains all other elements within it.
💡 Spotlight
<head> – This tag is used to define the head portion of the HTML document
that contains information related to the document. Elements within the head
tag are not visible on the front-end of a webpage.
<body> – The body tag is used to enclose all the visible content of a webpage.
In other words, the body content is what the browser will show on the front
end.
Example: This is the basic example of HTML that display the heading and
paragraph content.
HTML
<!DOCTYPE html>
<html>
</html>
Output:
Learn HTML
Tags
Attributes
Global Attributes
Event Attributes
Canvas
DOM
DOM Audio/Video
HTML5
MathML
Questions Complete Reference
HTML Examples
HTML examples contains a wide collection of HTML programming examples. The
HTML examples are categorized based on the topics including hyperlinks, forms,
tables, frames, and many more.
Recent Articles
Next
HTML Introduction
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
HTML Doctypes
Read Discuss Courses
Doctype Usage: In the version, HTML 4.01, the usage of DOCTYPE declaration
was to create a reference to a document type definition (DTD), since the version
HTML 4.01 was completely based on a Standard Generalized Markup
Language(SGML).
The document type definition (DTD) is responsible for specifying the rules for
the Standard Generalized Markup Language(SGML) so that the browser
processes the content correctly. But in the HTML version, HTML 5 there isn’t
any need for a reference to a document type definition (DTD) because HTML 5
is not based on a Standard Generalized Markup Language(SGML).
💡 Spotlight
In HTML 5, the DOCTYPE declaration is only required for enabling the standard
mode for writing documents.
Below is a sample HTML program with doctype declaration:
Example:
html
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<h2>This is HTML5 Doctype Tag</h2>
</body>
</html>
Output:
Below is the list of some common doctype declaration for different version of
HTML and XHTML:
1. HTML 5
html
<!DOCTYPE html>
2. HTML 4.01 Strict: In HTML 4.01 Strict document type definition (DTD) all
those elements and attributes are included that do not appear in frameset
documents or that have not been deprecated.
html
html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
html
5. XHTML 1.0 Strict: In XHTML 1.0 Strict document type definition (DTD),
deprecated tags are not supported and the code must be written according
to the XML Specification.
html
html
html
8. XHTML 1.1: In XHTML 1.1 document type definition (DTD), allows the
addition of modules.
html
Supported Browsers:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
Next
Similar Reads
What are the different kinds of Doctypes HTML Course | Structure of an HTML
available ? Document
Inline HTML Helper - HTML Helpers in How to return HTML or build HTML using
ASP.NET MVC JavaScript ?
How to convert html.slim to html.erb ? How to display HTML tags as plain text in
HTML ?
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
HTML uses predefined tags that tell the browser how to display the content.
Tags are nothing but some instructions that are enclosed in angle braces(i.e.,
<>). It is divided into three parts, i.e., opening tag, content(which will display on
the browser), and closing tag, but some tags are special tags that do not
contain closing tags like <BR> tag. When you are working with HTML tags
always remember to include closing tags. If you forget to close the tag, the
browser applies the effect of the opening tag until the end of the page. HTML
contains four essential tags that form the basic structure of any webpage or
HTML file:
1. <html></html>
2. <head></head>
3. <title></title>
4. <body></body>
1. <!DOCTYPE html>
💡 Spotlight
Syntax:
<!DOCTYPE html>
2. <html></html>
This tag marks the beginning and ending of the HTML document and whatever
code is present in between these tags totally gets considered by the browser.
Also, it tells the browser that the document is an HTML document. All the
other tags in between these tags only get considered by the browser.
Syntax:
3. <head></head>
This tag store the data which actually doesn’t appear on the webpage but it
gives more information about the webpage. Or in other words, this tag is used
to define the head part of the document which contains the information related
to the webpage. It also contain tags like, <title>, <meta>, <link>, <style>, etc.
Syntax:
4. <title> </title>
This tag stores the title/name of the web page. Whatever title/content is given
in this tag, the content appears on the tab when opened by the browser. It is
described in the head tag.
Syntax:
5. <body></body>
This tag is used to display all the information or data, i.e, text, images,
hyperlinks videos, etc., on the webpage to the user. Here, all the content like
text, images, hyperlinks videos, etc., are enclosed between this tag.
Syntax:
This tag is used to add comments in the HTML codes. These comments help
the program to understand the code. The content inside the comment tag
doesn’t visible on the browser.
Syntax:
2. <meta>
These meta tags are used inside the head tag and they making describe the
metadata i.e data about data. These tags are useful in search engine
optimization which means when users search for our websites the chances that
the browser recommends our webpage becomes high which leads to an
increase in traffic over the webpage. A single HTML document can contain
multiple tags.
Syntax:
<meta attribute-name=”value”>
This tag is used to include external style sheets. Use this tag when you don’t
want to include CSS in the HTML document. To make it more simple we make
a CSS file with the code and include this file in the link tag.
Syntax:
4. <script></script>
It is used for including javascript code. The external javascript can also be
linked using the src attribute in the opening script tag. It can be included in the
head or body tag.
Syntax:
<script>script content</script>
5. Heading:
HTML provides six types of headings, i.e., H1, H2, H3, H4, H5, and H6. Here,
H1 is the highest level heading and H6 is the lower level heading. These
headings are used to highlight the important topics.
Syntax:
Example 1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!--The description written on title tag get appeared as browser tab name-->
<title>Geeks For Geeks </title>
</head>
</body>
</html>
Output:
Example 2:
HTML program in which we are adding external CSS using the <link> tag
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!--Meta data-->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--Including css file with name GFG.css-->
<link rel="stylesheet" href="GFG.css">
<!--The description written on title tag get appeared as browser tab name-->
<title>Geeks For Geeks </title>
</head>
</body>
</html>
GFG.css
body {
text-align: center;
}
h1{
color: darkgreen;
}
h3{
color:darkgreen;
}:
Output:
Example 3:
HTML program in which we are adding javascript file GFG.JS using <script>
tag:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!--Meta data-->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--Including css file with name GFG.css-->
<link rel="stylesheet" href="GFG.css">
<!--The description written on title tag get appeared as browser tab name-->
<title>Geeks For Geeks </title>
</head>
</body>
</html>
Javascript
function darkMode() {
document.body.style.backgroundColor = "black";
}
Output:
On clicking the button.
Previous Next
Composition of Functions
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
The HTML <head> Tag is used to define the head portion of the document
which contains information related to the document. Metadata refers to data
about an HTML document. Unlike other content, metadata is not typically
displayed on the page itself.
The <head> element is a container for metadata tag and contains other head
elements such as:
<title>
<meta>
<link>
<style>
<link>
<script>
<nonscript>
Note:
In HTML 4, the <head> element was mandatory but in HTML5, the <head>
element can be omitted.
The <head> Tag supports the Global Attribute in HTML.
Syntax
<head>
<title>Title of the document</title>
</head>
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Head Tag </title>
</head>
<body>
<p>
GeeksforGeeks is a portal for geeks.
</p>
<hr>
</body>
</html>
Output:
Example 2 : The below example illustrates the usage of style tag inside head
tag.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
body {
background: skyblue;
}
h1 {
color: red;
}
p {
color: blue;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<p>It is a portal for geeks.</p>
</body>
</html>
Output:
Example 3: The below example illustrates the usage of link tag inside head
tag.
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
type="text/css"
href="mystyle.css">
</head>
<body>
<h1>GeeksforGeeks</h1>
<p>
It is a portal for geeks.
</p>
</body>
</html>
Output:
Supported Browsers
Google Chrome 15
Edge 12 and above
Firefox 1 and above
Opera 14 and above
Safari 6 and above
Previous Next
Similar Reads
Explain the significance of <head> and Which tag is used to represent progress
<body> tag in HTML of a task in HTML & how is it different
from <meter> tag ?
Is container tag same as the empty tag in HTML DOM head Property
HTML? If not, why ?
Elements that are used in head section of What purpose does a <script> tag serve
HTML page inside of a <noscript> tag?
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
The <body> tag in HTML is used to define the main content present inside an
HTML page. It is always enclosed within <html>tag. The <body> tag is the last
child of <html> tag. A body tag contains starting as well as an ending tag.
Syntax:
Attributes: There are many attributes in the <body> tag which are depreciated
from HTML5 are listed below:
Example : Using HTML body tag. All then content placed inside the body tag.
💡 Spotlight
HTML
<!DOCTYPE html>
<html>
</body>
<!-- body tag ends here -->
</html>
Output:
Example 2: Example to show the functioning of a Body tag along with its CSS
implementation.
HTML
<!DOCTYPE html>
<html>
</body>
<!-- body tag ends here -->
</html>
Output:
Supported Browsers:
Previous Next
Similar Reads
How to get all HTML content from Explain the significance of <head> and
DOMParser excluding the outer body tag <body> tag in HTML
?
Which tag is used to represent progress Is container tag same as the empty tag in
of a task in HTML & how is it different HTML? If not, why ?
from <meter> tag ?
HTML Heading
Read Discuss Courses
In this article, we will know HTML Headings, & their implementation through
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 being the
least.
Browsers display the contents of headings in different sizes. The exact size at
which each browser shows the heading can vary slightly. Users can also adjust
the size of the text in their browser.
Syntax:
Importance of Heading:
💡 Spotlight
Search Engines use headings for indexing the structure and organizing the
content of the webpage.
Headings are used for highlighting important topics.
They provide valuable information and tell us about the structure of the
document.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>H1 Heading</h1>
</body>
</html>
HTML
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to GeeksforGeeks</h1>
<h2>A computer science portal for geeks</h2>
<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>
<h1>H1 Heading</h1>
</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 any end tag. It is basically used to separate content. Please
refer to the HTML <hr> Tag article for more detailed information.
Example: This example explains the HTML Headings with horizontal rules.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>Heading 1</h1>
<p>I like HTML.</p>
<!-- hr Tag is used here-->
<hr />
<h2>Heading 2</h2>
<p>I like CSS.</p>
<!-- hr Tag is used here-->
<hr />
<h2>Heading 3</h2>
<p>I like Javascript.</p>
</body>
</html>
Output:
HTML Heading with the horizontal line
Supported Browsers:
Previous Next
Similar Reads
What are various heading elements used HTML | DOM Heading Object
to add heading in HTML ?
HTML DOM Heading align Property How to add sub heading using HTML ?
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
HTML Paragraphs
Read Discuss Courses
In this article, we will know the HTML Paragraph, & 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 a good convention, and we must use the closing tag.
Syntax:
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>
<!-- Use of <p> tag -->
<p>A computer science portal for geeks.</p>
</body>
</html>
Output:
Spotlight
HTML p tag
HTML
<!DOCTYPE html>
<html>
<body>
<p>A Computer Science portal for geeks.</p>
<p>It contains well written, well thought articles.</p>
</body>
</html>
Output:
Multiple p Tags
Key Points: When we look at the webpage, we see that there are few spaces
added before and after a paragraph. HTML does this by default. Let’s look at a
few properties of the paragraph tag:
Example: This example explains the HTML <p> tag having multiple lines.
HTML
<!DOCTYPE html>
<html>
<body>
<p>
This paragraph has multiple lines.
But HTML reduces them to a single line,
omitting the carriage return we have used.
</p>
<p>
This paragraph has multiple spaces.
But HTML reduces them all to a single
space, omitting the extra spaces and line we have used.
</p>
</body>
</html>
Output:
<br> tag: There is a way to let the HTML know where the browser needs to
change the lines by using 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
<br />lines. But HTML reduces them
<br />to a single line, omitting
<br />the carriage return we have used.
</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>
<p align="center">
Welcome Geeks
</p>
<p align="left">
A Computer Science portal for geeks.
</p>
<p align="right">
It contains well written, well thought articles.
</p>
</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 the <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:
Example: This example explains the use of the <pre> tag in the <p> tag.
HTML
<!DOCTYPE html>
<html>
<body>
<pre>
This paragraph has multiple
lines. But it is displayed
as it is unlike the paragraph
tag.
</pre>
<pre>
This paragraph has multiple
spaces. But it is displayed
as it is unlike the paragraph
tag.
</pre>
</body>
</html>
Output:
Supported Browsers:
Google Chrome
Internet Explorer
Microsoft Edge 12
Firefox 1
Opera
Safari
Previous Next
HTML Attributes
Read Discuss Courses
Attributes are always added to the start tag of an HTML element. Attributes
always come in name/value pairs like this: attribute_name=”value” and
attribute values should always be enclosed in quotes
Note: The name parameter takes the name of the property we would like to
assign to the element and the value takes the property 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.
Syntax:
<element attribute_name="attribute_value">
Supported Attributes:
It is a global attribute that is supported by all the tags.
💡 Spotlight
Table of Content
HTML src Attribute:
HTML alt Attribute:
HTML width and height Attribute:
HTML id Attribute:
HTML title Attribute:
HTML href Attribute:
HTML style Attribute:
HTML lang attribute:
Example:
This example explains the HTML src Attributes to specify the source address
of the file.
HTML
<html>
<head>
<title>src Attribute</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png">
</body>
</html>
Output:
src Attribute
Example:
This example explains the HTML alt Attributes to specify the name of the file
when the image is not loaded properly.
HTML
<html>
<head>
<title>alt Attribute</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png"
alt="The Logo"><br>
<img src="" alt="Since the src value is blank,the alt value is displayed">
</body>
</html>
Output:
alt Attribute
Example:
This example explains the HTML width & height Attributes to specify the
different sizes of the images.
HTML
<html>
<head>
<title>Width and Height</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png"
width="300px" height="100px" >
</body>
</html>
Output:
HTML id Attribute:
This attribute is used to provide a unique identification to an element.
Situations may arise when we will need to access a particular element that
may have a similar name as the others. In that case, we provide different id’s to
various elements so that they can be uniquely accessed. The properties
extending the use of id are generally used in CSS, which we will be learning
later.
Example:
This example explains the HTML id Attributes to specify the unique value for
the specific element.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#geeks {
color: green;
}
</style>
</head>
<body>
<h1 id="geeks">Welcome to GeeksforGeeks</h1> </body>
</html>
Output:
id attribute
Example:
This example explains the HTML title Attributes to specify the metadata for
the element on hovering the mouse over it.
HTML
<html>
<head>
<title>title Attribute</title>
</head>
<body>
<h3 title="Hello GeeksforGeeks">Hover to see the effect</h3>
</body>
</html>
Output:
title attribute
Example:
This example explains the HTML href Attributes specify the link address of the
file.
HTML
<html>
<head>
<title>link Attribute</title>
</head>
<body>
<a href="https://www.geeksforgeeks.org/">
Click to open in the same tab
</a><br>
<a href="https://www.geeksforgeeks.org/" target="_blank">
Click to open in a different tab
</a>
</body>
</html>
Output:
href attribute
Example:
This example explains the HTML style Attributes to specify the style
properties for the HTML element.
HTML
<html>
<head>
<title>style Attribute</title>
</head>
<body>
<h2 style="font-family:Chaparral Pro Light;">Hello GeeksforGeeks.</h2>
<h3 style="font-size:20px;">Hello GeeksforGeeks.</h3>
<h2 style="color:#8CCEF9;">Hello GeeksforGeeks.</h2>
<h2 style="text-align:center;">Hello GeeksforGeeks.</h2>
</body>
</html>
Output:
style Attribute
Example:
This example explains the HTML lang Attributes that specify the language of
the HTML page.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>lang attribute</title>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
.lang-info {
font-style: italic;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>lang attribute</h2>
<p lang="en">
A computer science portal for geeks
</p>
</html>
Output:
Please refer to the HTML Attributes Complete Reference for all the attributes
in detail.
Previous Next
Similar Reads
How to remove all attributes of an HTML HTML Id Attributes
element using jQuery ?
In this article, we will know HTML Text Formatting, & will understand various
ways of formatting the text. HTML facilitates the ability for formatting text just
like we do in MS Word or any text editing software. We will go through a few
such options.
Example: In this example, we simply display text in HTML strong, small, and
Highlight formatting respectively.
HTML
<!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:
Formatting the text using various HTML tags
💡 Spotlight
Making text Bold or Strong: We can make the text bold using the <b> tag.
The tag uses both opening and closing tags. The text that needs to be made
bold must be within <b> and </b> tag. We can also use the <strong> tag to
make the text strong, with added semantic importance. It also opens with
<strong> and ends with </strong> tag.
Example 1: The below example describes the formatting of the text to normal,
bold, & strong.
HTML
<!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:
Example: The below example describes the use of the <mark> tag that is used
to define the marked text.
HTML
<!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:
Example: The below example describes the use of the <sup> & <sub> tags
that are used to add the superscript & subscript texts to the HTML document.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Superscript and Subscript</title>
</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 sizes.
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-->
<p> <del>Hello GeeksforGeeks</del> </p>
</body>
</html>
Output:
Using <del> Tag
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>
<title>Inserting the Text</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Insert-->
<p>
<ins>Hello GeeksforGeeks</ins>
</p>
</body>
</html>
Output:
Supported Browsers:
Google Chrome
Microsoft Edge
Firefox
Opera
Safari
Previous Next
Similar Reads
HTML Text Formatting Elements What are the various formatting tags
available in HTML ?
Role of ViewPort in Visual Formatting How to display HTML tags as plain text in
Model HTML ?
How to override the current text How to align Placeholder Text in HTML ?
direction using HTML ?
HTML | DOM Input Text Object HTML | DOM Option text Property
HTML | DOM Input Text value Property HTML | DOM Input Text type Property
Complete Tutorials
HTML Tutorial JavaScript Project Ideas with Source
Code
HTML Comments
Read Discuss Courses
HTML Comments are used to insert comments in the HTML code. It is a good
practice of coding so that the coder and the reader can get help to understand
the code. It is a simple piece of code that is wiped off (ignored) by web
browsers i.e., not displayed by the browser.
Comment Types
There are three types of comments in HTML which are:
Table of Content
Comment Types
Single-line Comment
Multi-line Comment
Using comment tag
💡 Spotlight
Single-line Comment
The single-line comment is given inside the ( <!– comment –> ) tag.
Syntax
HTML
<!DOCTYPE html>
<html>
<body>
<!--This is heading Tag, It wont be displayed by the browser -->
<h1>GeeksforGeeks</h1>
</body>
</html>
Output:
Multi-line Comment
Multiple lines can be given by the syntax (<!– –>), Basically it’s the same as we
used in single line comment, difference is half part of the comment (” –> “), is
appended where the intended comment line ends.
Syntax
<!-- Multi
Line
Comment -->
HTML
<!DOCTYPE html>
<html>
<body>
<!-- This is
heading tag -->
<h1>GeeksforGeeks</h1>
<!-- This is
multi-line
comment -->
<h2>This is multi-line comment</h2>
</body>
</html>
Output:
Using comment tag
There used to be an HTML <comment> tag, but currently it is not supported by
any modern browser.
Syntax
HTML
<!DOCTYPE html>
<html>
<body>
<comment>This is heading tag</comment>
<h1>GeeksforGeeks</h1>
<comment>This is multi-line
comment
</comment>
<h2>This is a comment using</h2>
</body>
</html>
Output:
Previous Next
Similar Reads
How to write comments in HTML ? HTML Course | Structure of an HTML
Document
Inline HTML Helper - HTML Helpers in How to return HTML or build HTML using
ASP.NET MVC JavaScript ?
How to convert html.slim to html.erb ? How to display HTML tags as plain text in
HTML ?
Free CSS Course Selectors Properties Functions Examples A to Z Guide Cheat Sheet HTML and CSS Tem
Cascading Style Sheet (CSS) is used to set the style in web pages that contain
HTML elements. It sets the background color, font-size, font-family, color, …
etc. properties of elements on a web page.
Inline CSS
Internal or Embedded CSS
External CSS
Inline CSS: Inline CSS contains the CSS property in the body section attached
to the element is known as inline CSS. This kind of style is specified within an
HTML tag using the style attribute.
GeoFinder Ope
html
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<p style="color:#009900; font-size:50px;
font-style:italic; text-align:center;">
GeeksForGeeks
</p>
</body>
</html>
Output:
Internal or Embedded CSS: This can be used when a single HTML document
must be styled uniquely. The CSS rule set should be within the HTML file in
the head section i.e. the CSS is embedded within the <style> tag inside the
head section of the HTML file.
html
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS</title>
<style>
.main {
text-align: center;
}
.GFG {
color: #009900;
font-size: 50px;
font-weight: bold;
}
.geeks {
font-style: bold;
font-size: 20px;
}
</style>
</head>
<body>
<div class="main">
<div class="GFG">GeeksForGeeks</div>
<div class="geeks">
A computer science portal for geeks
</div>
</div>
</body>
</html>
Output:
External CSS: External CSS contains separate CSS files that contain only style
properties with the help of tag attributes (For example class, id, heading, …
etc). CSS property is written in a separate file with a .css extension and should
be linked to the HTML document using a link tag. It means that, for each
element, style can be set only once and will be applied across web pages.
Example: The file given below contains CSS property. This file saves with .css
extension. For Ex: geeks.css
body {
background-color:powderblue;
}
.main {
text-align:center;
}
.GFG {
color:#009900;
font-size:50px;
font-weight:bold;
}
#geeks {
font-style:bold;
font-size:20px;
}
Below is the HTML file that is making use of the created external style sheet.
link tag is used to link the external style sheet with the html webpage.
href attribute is used to specify the location of the external style sheet file.
html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="geeks.css" />
</head>
<body>
<div class="main">
<div class="GFG">GeeksForGeeks</div>
<div id="geeks">
A computer science portal for geeks
</div>
</div>
</body>
</html>
Output:
Priorities of CSS: Inline CSS has the highest priority, then comes
Internal/Embedded followed by External CSS which has the least priority.
Multiple style sheets can be defined on one page. For an HTML tag, styles can
be defined in multiple style types and follow the below order.
As Inline has the highest priority, any styles that are defined in the internal
and external style sheets are overridden by Inline styles.
Internal or Embedded stands second in the priority list and overrides the
styles in the external style sheet.
External style sheets have the least priority. If there are no styles defined
either in inline or internal style sheet then external style sheet rules are
applied for the HTML tags.
By Simplilearn
Table of Contents
Inline CSS
Internal CSS
External CSS
Properties of CSS
View More
CSS is a design language that improves the aesthetic of a website by making simple or uninteresting
text more appealing. CSS is responsible for visual structure and layout, whereas HTML is primarily
responsible for textual information. HTML is a markup language, whereas CSS is a style sheet
language. It is responsible for describing the presentation of an HTML or XML document (including
XML dialects such as SVG, MathML or XHTML). CSS specifies how elements should appear on a
screen, on paper, in speech, or in other forms of media.
CSS may be added to HTML in three different ways. To style a single HTML element on the page, use
Inline CSS in a style attribute. By adding CSS to the head section of our HTML document, we can
embed an internal stylesheet. We can also connect to an external stylesheet that separates our CSS
from our HTML.
EXPLORE PROGRAM
Inline CSS
Style rules can be applied to individual HTML elements using inline CSS. Inlining CSS is the process
of embedding CSS into an HTML file rather than using an external CSS file. Because inline CSS only
allows us to apply a single style to one HTML element, it's only useful for establishing unique
properties. Inline CSS is advantageous since it decreases the number of files that the browser must
download before the web page can be shown. The browser loads an HTML file first, then downloads
the CSS file when using external CSS. We only need to download one HTML file instead of two using
inline CSS, which speeds up the process.
The inline styles will only affect the HTML element to which the style attribute with CSS-property
values is applied. The first paragraph in the example below will be styled in red with a 20px font size.
The properties apply just to the first line of the code, not the full code.
Example 1:
<body>
</body>
Example 2:
However, using inline styles is generally thought to be a bad idea. Because style rules are inserted
directly into the HTML tag, the presentation of the document becomes intermingled with the content
of the document, making the code difficult to maintain and defeating the purpose of CSS.
Want a Top Software Development Job? Start Here!
EXPLORE PROGRAM
Internal CSS
Internal CSS is one of the most popular CSS forms for updating, customizing, and modifying a single
web page's unique styles. You can use the internal CSS by integrating the <style> element in the
<head> section of a HTML web page.
Internal CSS can be used to style a single web page, but not multiple web pages, and we can style
numerous web pages with the same code.
Example 1:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: grey;
h1 {
color: red;
margin-left: 75px;
</style>
</head>
<body>
<h1>The internal CSS is applied on this heading, so it will show some unique appearance.</h1>
<p>This paragraph will not be affected as internal CSS is not applied on this.</p>
</body>
</html>
Example 2:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: powderblue;
}
</style>
</head>
<body>
<p>The default text color for the page is black. However, we can change the color of every
paragraph element on the page using internal CSS.</p>
<p>Using internal CSS, we only need to write one rule set to change the color of every paragraph
elemnet.</p>
<p>With inline CSS, we’d have to add a style attribute to every single paragraph in my HTML.</p>
</body>
</html>
EXPLORE PROGRAM
External CSS
External CSS is one of the most often used CSS forms for updating, styling, and adjusting the
different styles in a large number of HTML web pages at the same time. There are two ways to
include an external style sheet in an HTML document. One method is to use the <link> tag in the
HTML document head. Another option is to use a combination of external CSS functions and
integrated CSS.
One of the distinguishing characteristics of external CSS is that it can be written in any text editor,
but it must always be saved with the.css extension and must not contain any HTML elements.
We use the external style sheet when we need to make changes to multiple pages. It's ideal for this
circumstance because it allows us to change the appearance of the entire website with just one file
change. It comes in handy while working on large projects or several HTML web pages.
We must define the filename of the CSS sheet with the "mystyle.css" extension within the <link>
element within the <head> section of the HTML page to use external CSS:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
mystyle.css
In this file, we can write our complete CSS code for styling the HTML web page.
Example 1:
body {
background-color:powderblue;
.main {
text-align:center;
.sideway {
color:#009900;
font-size:40px;
font-weight:bold;
#change1 {
font-style:bold;
font-size:25px;
}
Example 2:
body {
background-color: lightblue;
h1 {
color: navy;
margin-left: 20px;
EXPLORE PROGRAM
Inline CSS is advantageous since it decreases the number of files that the browser must download
g
before the web page can be shown. The browser loads an HTML file first, then downloads the CSS
file when using external CSS. We only need to download one HTML file instead of two using inline
CSS, which speeds up the process.
Lower the HTTP Request: The main advantage of utilizing Inline CSS is that it requires fewer
HTTP requests, which implies that the page loads faster than when using External CSS.
For Testing Purposes: When working on new projects, many web designers choose to use Inline
CSS because it is easier to scroll up in the source rather than changing the source file. Some
people use it to debug their websites if they run into a problem that can’t be easily fixed. This can
be used in conjunction with CSS's important rule.
Since Internal CSS has a higher priority than Inline CSS in terms of use. There are several benefits,
some of which are listed below:
Cache Problem: Unless they are hacked to hide from certain browsers, internal styles will be read
by all of them. This disables the usage of media=all or @import to hide styles in ancient, clumsy
browsers such as IE4 and NN4.
Pseudo Elements: Inline styles can't be used to style pseudo-elements or classes. Internal style
sheets let us customize the color of an anchor tag's visited, hover, active, and link states.
No Additional Downloads: We don't need any additional downloads to get style information, and
we have fewer HTTP requests.
When a style is applied to a large number of pages, an external style sheet is perfect. We can modify
the look of an entire website by changing one file with an external style sheet. The <link> tag must be
used on each page to link to the style sheet. Here are some of its advantages:
Full Control of Page Structure: CSS allows us to display our web page in accordance with W3C
HTML standards without sacrificing the page's appearance. Google is the most popular search
engine and a key traffic source. Because Google places a low value on well-organized web pages,
many designers overlook them. However, putting a low value on anything can result in a lot of
traffic to a website.
Reduced File Size: We can drastically reduce the file size of our pages by adding the text styling in
a separate file. Furthermore, compared to simple HTML pages, the content-to-code ratio is much
higher, making the page structure easier to read for both programmers and spiders. Instead of
using images, we can use CSS to define the visual impact we wish to apply to them. The space
we save this way can be utilized for spider-friendly text (i.e., keywords), and we'll also reduce the
page's download size.
Properties of CSS
The part about cascading is crucial. Cascading means that styles can inherit and override styles that
have been specified previously.
Internal/Embedded CSS has the highest importance, followed by External CSS, which has the lowest
priority. On a single page, we can declare many style sheets. If multiple style sheets describe styles
for an HTML tag, the order listed below will be used.
Any styles defined in the internal and external style sheets are overridden by Inline styles since
Inline has the highest precedence.
Internal CSS is the second most important option, and it takes precedence over the styles in the
external style sheet.
External style sheets are given the least amount of importance. If no styles are defined in the
inline or internal style sheets, the HTML tags are styled using external style sheet rules.
Cascading Style Sheets (CSS) is a way to give aesthetic instructions to the back-end code of our
website. It makes it simple to change the appearance of our website. We may quickly and easily
apply CSS to our website using any of the ways above to match the appearance. Website code is the
language that informs our browser exactly how a website should appear and function. HTML
(hypertext markup language) is the most widely used coding language. It is a type of code that
indicates which elements are available on a webpage. According to HTML, CSS is an HTML
extension that specifies particular styling instructions. CSS is used to specify a heading's color or
the font in which our text should be written. CSS allows us to personalize the appearance of our
website and make stylistic judgments across the board. It guarantees that the appearance of our
website is consistent.
Want a Top Software Development Job? Start Here!
EXPLORE PROGRAM
Conclusion
CSS specifies how a page should appear to the browser, which then renders it in that manner. It is
used to change the color of text and background on a page, remove the underline from links, and
animate images, text, and other HTML elements, among other things, and we can implement all
these features on any web page using different types of CSS based on given circumstances. In the
above article, we have discussed everything about all types of CSS (inline, internal, external CSS) and
its uses with HTML to customize any web page. We hope that this article was able to give you a
thorough knowledge of CSS and its uses and how we can use it to develop structure of any web
page and style it.
If you are interested in learning more about React JS and other related concepts, you can enroll in
Simplilearn’s exclusive Full Stack Web Development Certification Course and accelerate your career
as a software developer. The program comprises a variety of software development courses,
ranging from the fundamentals to advanced topics.
Simplilearn also offers free online skill-up courses in several domains, from data science and
business analytics to software development, AI, and machine learning. You can take up any of these
courses to upgrade your skills and advance your career.
Find our Post Graduate Program in Full Stack Web Development Online Bootcamp in top
cities:
HTML Links
Read Discuss Courses
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. You will find many websites or social media platforms ( Like
YouTube, and Instagram ) which link an image to a URL or a text to a URL etc.
This basically means that by using the ‘a’ tag, you can link 1 element of the
code to another element that may/may not be in your code.
GeoFinder Ope
Input :
html
<!DOCTYPE html>
<html>
<h3>Example Of Adding a link</h3>
<body>
<p>Click on the following link</p>
<a href="https://www.geeksforgeeks.org">GeeksforGeeks</a>
</body>
</html>
Output :
Internal Links
Input:
html
<!DOCTYPE html>
<html>
<h3>Internal Link And External Link Example</h3>
<body>
<!--internal link-->
<p>
<a href="html_contribute.asp/">
GeeksforGeeks Contribute
</a>
It is a link to the contribute page on GeeksforGeeks' website.
</p>
<!--external link-->
<p>
<a href="https://www.geeksforgeeks.org">
GeeksforGeeks
</a>
It is a link to the GeeksforGeeks website on the World Wide Web.
</p>
</body>
</html>
Output :
Input :
html
<!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>Changing the default colors of links</p>
<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:
The Target Attribute in Links
The target attribute is used to specify the location where the linked document
is opened. The various options that can be used in the target attribute are listed
below in the table:
Input:
html
<!DOCTYPE html>
<html>
<body>
<h3>Various options available in the Target Attribute</h3>
</html>
Output:
Using Image as a Link in HTML
An image can be used to create a link to a specified URL. When the viewer
clicks on the link, it redirects them to another page.
</a>
Note: img src stands for image source ( i.e URL or file address )
Input:
html
<!DOCTYPE html>
<html>
<body>
<h3>Using Image as a link</h3>
<p>Click on the image to visit GeeksforGeeks homepage.</p>
<a href="https://www.geeksforgeeks.org">
<img src="https://media.geeksforgeeks.org/gfg-gg-logo.svg"
alt="GeeksforGeeks"
style="width:80px;height:80px;border:0">
</a>
</body>
</html>
Output:
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>
<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>
<h2>Topic 18</h2>
<p>paragraph 1
.....</p>
<h2>Topic 19</h2>
<p>paragraph 1
.....</p>
</html>
Output:
A text link of a pdf, doc or zip file can be created to make it downloadable.
Input :
html
<!DOCTYPE html>
<html>
<body>
<a href="GeeksforGeeks.pdf">
Download PDF File
</a>
</body>
</html>
Output: :
Supported Browser:
Google Chrome
Microsoft Edge
Firefox
Opera
Safari
Brave
Previous Next
Similar Reads
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
HTML Images
Read Discuss Courses
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.
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.
💡 Spotlight
Syntax:
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>
<p>This is the demo of <img> tag.</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-300x300.png
alt="GFG image" />
</body>
</html>
Output:
Adding GFG logo using tag
Example 2: The example illustrates the use of the src attribute in the <img>
tag.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Inserting an image using "img" tag</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
</body>
</html>
Output:
Use of src attribute
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>
<title>Alt Attribute Example</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="This is GeeksforGeeks logo" />
</body>
</html>
Output:
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>
<title>Setting width and height of image</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="GeeksforGeeks logo" width="300"
height="300" />
</body>
</html>
Output:
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>
<title>Inserting an image using "img" tag</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="GeeksforGeeks logo"
width="200"
height="200"
title="Logo of GeeksforGeeks" />
</body>
</html>
Output:
Setting style to the Image: In this example, we are using the border property
to decorate the image. By default, every picture has a border around it. By
using the border attribute, the thickness of the border can be changed. A
thickness of “0” means that there will be no border around the picture. Please
refer to the HTML | <img> border Attribute for further details.
Example 6: This example illustrates the use of style property inside the <img>
tag in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Setting border to image</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="GeeksforGeeks logo"
width="200"
height="200"
border="5" />
</body>
</html>
Output:
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>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="GeeksforGeeks logo"
align="right" />
</body>
</html>
Output:
Adding Image as a Link: An image can work as a link with a URL embedded in
it. It can be done by using the “img” tag inside an “a” tag. We need to specify
the file path in order to render the image on the webpage. File paths are used
to link external resources such as images, videos, style sheets, JavaScript,
displaying other web pages, etc. To insert a file on a web page its source must
be known.
Absolute File Paths: It always contains the root element along with the
complete directory list required to locate the file.
Relative File Paths: It is the hierarchical path representation that locates the
file or folder on a file system beginning from the current directory.
Example 8: This example illustrates the use of link property in the <img> tag.
Here, we have used the absolute path link in order to provide the link to the
image. Please refer to the HTML | File Paths & How to turn an Image into a
Link in HTML? article for further details.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Adding image as link</title>
</head>
<body>
<h3>GeekforGeeks</h3>
<p>inserted image using <img> tag:</p>
<a href="https://ide.geeksforgeeks.org/tryit.php">
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.pn
alt="GeeksforGeeks logo" />
</a>
</body>
</html>
Output:
Adding the image as a link
Adding animated Image: Animated images in .gif format can also be added
using the “img” tag.
Example 9: This example explains the addition of an image in the GIF format in
HTML.
HTML
<!DOCTYPE html>
<html>
<body>
<h3>Adding a gif file on a webpage</h3>
<img src="smiley.gif"
alt="smiley"
style="width: 200px; height: 200px" />
</body>
</html>
Output:
Example 10: This example illustrates the use of body background property in
the <img> tag.
HTML
<!DOCTYPE html>
<html>
</html>
Output:
Adding the image as a background
Common Image Format: Here is the commonly used image file format that is
supported by all the browsers.
Supported Browsers:
Previous Next
Similar Reads
HTML DOM images Collection Property Lazy Loading images in HTML
How to display Base64 images in HTML ? How to Show Images on Click using
HTML ?
How to make the images bigger when How to compare two images using Image
clicked? comparison slider?
Complete Tutorials
HTML Tutorial JavaScript Project Ideas with Source
Code
HTML Tables
Read Discuss Courses
Table Tags
Table of Content
Defining Tables in HTML
Adding a border to an HTML Table
Adding Collapsed Borders in an HTML Table
Adding Cell Padding in an HTML Table
Adding Left Align Headings in an HTML Table
Adding Border Spacing in an HTML Table
Adding Cells that Span Many Columns in HTML Tables
Adding Cells that span many rows in HTML Tables
Adding a Caption in an HTML Table
Adding a Background Colour to the Table
Creating Nested Tables
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.
💡 Spotlight
HTML
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<th>Book Name</th>
<th>Author Name</th>
<th>Genre</th>
</tr>
<tr>
<td>The Book Thief</td>
<td>Markus Zusak</td>
<td>Historical Fiction</td>
</tr>
<tr>
<td>The Cruel Prince</td>
<td>Holly Black</td>
<td>Fantasy</td>
</tr>
<tr>
<td>The Silent Patient</td>
<td> Alex Michaelides</td>
<td>Psychological Fiction</td>
</tr>
</table>
</body>
</html>
Output:
HTML Table
HTML
<!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:
Example: This example explains the addition of the border to the HTML Table.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
}
</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:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
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:
Example: This example describes the addition of Table cell padding in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
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:
Example: This example explains the text-align property where the text is
aligned to the left.
HTML
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
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
Example: This example explains the border space property to make the space
between the Table cells.
HTML
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
}
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:
Example: 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>
<h2>Cell that spans two columns:</h2>
<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
Example: This example describes the use of the rowspan 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>
<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:
Example: This example describes the HTML Table caption by specifying the
CSS properties for setting its width.
HTML
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
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:
Example: This example describes the addition of the Table background color 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;
}
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:
<!DOCTYPE html>
<html>
<body>
<table border=5 bordercolor=black>
<tr>
<td> First Column of Outer Table </td>
<td>
<table border=5 bordercolor=grey>
<tr>
<td> First row of Inner Table </td>
</tr>
<tr>
<td> Second row of Inner Table </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Output:
Supported Browsers
Google Chrome 15
Edge 12 and above
Firefox 1 and above
Opera 14 and above
Safari 6 and above
HTML is the foundation of webpages, is used for webpage development by
structuring websites and web apps. You can learn HTML from the ground up by
following this HTML Tutorial and HTML Examples.
Previous Next
Similar Reads
How to create nest tables within tables in How to initialize multiple tables using
HTML ? jQuery DataTables plugin ?
Inline HTML Helper - HTML Helpers in How to return HTML or build HTML using
ASP.NET MVC JavaScript ?
Complete Tutorials
HTML Tutorial JavaScript Project Ideas with Source
Code
NuxtJS
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
HTML Iframes
Read Discuss Courses
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:
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:
Example: This example illustrates the use of an iframe tag which is used to
display a webpage inside the current web page.
💡 Spotlight
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML iframe Tag</title>
</head>
</iframe>
</body>
</html>
Output:
HTML iframe tag
Accepted Attribute: The following attributes can be used with the <iframe>
tag in HTML.
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>
<h2>HTML iframe Tag</h2>
<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>
<p>Content goes here</p>
<iframe src=
"https://ide.geeksforgeeks.org/tryit.php"
height="300"
width="400"
style="border: none">
</iframe>
</body>
</html>
Output:
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>
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>
<h2>HTML iframe Tag</h2>
<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:
Supported Browsers:
Previous Next
Similar Reads
Alternative to iFrames in HTML5 HTML Course | Structure of an HTML
Document
Inline HTML Helper - HTML Helpers in How to return HTML or build HTML using
ASP.NET MVC JavaScript ?
How to convert html.slim to html.erb ? How to display HTML tags as plain text in
HTML ?
Complete Tutorials
HTML Tutorial JavaScript Project Ideas with Source
Code
HTML Lists
Read Discuss Courses
In this article, we will know the HTML List, along with understanding its types,
and various ways to implement them, through the example.
Example: The below example illustrates the use of the unordered & ordered
list in HTML.
HTML
<!DOCTYPE html>
<html>
<head>
<title>GeeksforGeeks</title>
</head>
<body>
<h2>Welcome To GeeksforGeeks Learning</h2>
<h5>List of available courses</h5>
<ul>
<li>Data Structures & Algorithm</li>
<li>Web Technology</li>
<li>Aptitude & Logical Reasoning</li>
<li>Programming Languages</li>
</ul>
<h5>Data Structures topics</h5>
<ol>
<li>Array</li>
<li>Linked List</li>
<li>Stacks</li>
<li>Queues</li>
<li>Trees</li>
<li>Graphs</li>
</ol>
</body>
</html>
Output:
GeoFinder Ope
HTML List
The HTML Unordered List: An unordered list starts with the “ul” tag. Each list
item starts with the “li” tag. The list items are marked with bullets i.e small
black circles by default.
Syntax:
Attribute: This tag contains two attributes which are listed below:
HTML
<!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
Example 1: The Disc can be used to set the list item marker to a bullet i.e
default.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML ul tag</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Unordered List with Disc Bullets</h2>
<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>
<h2>Unordered List with Circle Bullets</h2>
Output:
Example 3: The Square can be used to set the list item marker to a square.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<h2>Unordered List with Square Bullets</h2>
</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>
<h2>Unordered List with No Bullets</h2>
</html>
Output:
Unordered List with none item maker
Example: Nested Unordered List, It is used to nest the list items ie., a list inside
another list.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>GeeksforGeeks</h1>
<h2>Nested Unordered List</h2>
<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:
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:
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>
<h1 style="color: green">GeeksforGeeks</h1>
<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:
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>
<h2>Ordered List with Numbers</h2>
<ol type="1">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output:
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:
Ordered List with capital alphabetic item maker
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Lowercase Letters</h2>
<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 of items will be numbered with uppercase roman
numbers.
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Roman Numbers</h2>
<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 of items will be numbered with lowercase roman
numbers.
HTML
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Lowercase Roman Numbers</h2>
<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>
<h2>Nested Ordered List</h2>
<ol>
<li>Coffee</li>
<li> Tea
<ol>
<li>Black tea</li>
<li>Green tea</li>
</ol>
</li>
<li>Milk</li>
</ol>
</body>
</html>
Output:
Nested Ordered List
There is another attribute that is specifically defined for a list item, which is
used in with the “li” tag and that is the value attribute. Below is a little
description of the value attribute specifically used with the “li” tag. Though it is
used with various other HTML elements.
Value attribute:
Example: This example illustrates the use of the “value attribute” used on the
<li> element.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h2>Welcome To GFG</h2>
<ol>
<li>Item One</li>
<li value="10">Item Two</li>
<li>Item Three</li>
<li>Item Four</li>
</ol>
</body>
</html>
Output:
<img
src="https://media.geeksforgeeks.org/wp-
content/uploads/20220522105327/GFG20220522105224.jpg"
alt="Use of "value
attribute" on
”
srcset=”https://media.geeksforgeeks.org/wp-
content/uploads/20220522105327/GFG20220522105224.jpg,
” sizes=”100vw”
width=”237″>
Value attribute
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:
HTML
<!DOCTYPE html>
<html>
<body>
<h2>A Description List</h2>
<dl>
<dt>Coffee</dt>
<dd>- 500 gms</dd>
<dt>Milk</dt>
<dd>- 1 ltr Tetra Pack</dd>
</dl>
</body>
</html>
Output:
Description List
Supported Browser:
Whether you're preparing for your first job interview or aiming to upskill in this
ever-evolving tech landscape, GeeksforGeeks Courses are your key to success.
We provide top-quality content at affordable prices, all geared towards
accelerating your growth in a time-bound manner. Join the millions we've
already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Previous Next
Similar Reads
Free HTML Course Tags Attributes Global Attributes Event Attributes HTML DOM DOM Audio/Video HTM
In this article, we will know the HTML Block element & Inline element, along
with understanding the implementation through the example. Every HTML
documents that render the web content, will depend on the element type i.e,
block or inline which are default display values. We will understand both these
concepts through the examples.
Example: This example illustrates the use of the block-level element & inline
element.
HTML
<!DOCTYPE html>
<html>
<body>
<div>GeeksforGeeks</div>
Checkout the GeeksforGeeks
<a href="https://www.geeksforgeeks.org/"
alt="GeeksforGeeks">
official</a> website for the articles on various courses.
</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.
💡 Spotlight
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 i.e, 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>
HTML
<!DOCTYPE html>
<html>
<title>Block-level Element</title>
<body>
<div>
<h1>GeeksforGeeks</h1>
<h3>GeeksforGeeks is a science portal for geeks.</h3>
<h3>
You can give reviews as well as
contribute posts on this portal.
</h3>
</div>
</body>
</html>
Output:
Block Element
Supported tags:
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>
HTML
<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
</style>
</head>
<body>
<!-- Span element. -->
<h1>Geeks
<span style="color: red"> for</span>
Geeks
</h1>
</body>
</html>
Output:
Inline Element
Supported Browsers:
Previous Next
Similar Reads
Difference between block elements and How to prevent inline-block divs from
inline elements wrapping ?
Inline HTML Helper - HTML Helpers in Which inline attribute is used to specify
ASP.NET MVC the styling of specific elements in HTML ?
How to create an inline frame using How to make a Inline Button using
HTML5 ? jQuery Mobile ?
Complete Tutorials
School Guide CBSE Class 10 Syllabus Maths Notes Class 10 Science Notes Class 10 History Notes Class 10 G
HTML Forms
Read Discuss Courses
HTML stands for Hyper Text Markup Language. It is used to design web pages
using a markup language. It is a combination of Hypertext and Markup
language. HTML uses predefined tags and elements that tell the browser how
to properly display the content on the screen, and form is one of them. So, in
this article, we will learn what is exactly HTML form, what are the elements of
forms and how can we use HTML form in our webpage.
Syntax:
<form>
<!--form elements-->
</form>
Form elements
Syntax:
We can change the type value text to password to get the input password
Example: This example shows the type password in html form.We can see the
difference between type text and type password. The username will be visible
but the password will not be visible.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1 {
text-align: center;
color: green;
}
input {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GFG</h1>
<form>
<p>
<label>Username :
<input type="text" /></label>
</p>
<p>
<label>Password :
<input type="password" /></label>
</p>
<p>
<button type="submit">Submit</button>
</p>
</form>
</div>
</body>
</html>
Output:
Output
To create a radio button, we use the <input> tag following by radio type to
provide users to choose a limited number of choices. The value attribute
defines the unique value associated with each radio button. The value is not
shown to the user, but is the value that is sent to the server on “submit” to
identify which radio button that was selected.
Syntax:
Note: The radio button must have shared the same name to be treated as a
group.
Example: In this example, we will create a radio button to choose your gender.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GFG</h1>
<h3>Choose Your Gender</h3>
<form>
<label>
Male
<input type="radio" '
name="gender" value="male" />
</label>
<label>
Female
<input type="radio"
name="gender" value="female" />
</label>
</form>
</div>
</body>
</html>
Output:
Output
To create a checkbox in an HTML form, we use the <input> tag followed by the
input type checkbox. It is a square box to tick to activate this. It used to choose
more options at a time.
Syntax:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GFG</h1>
<h3>Choose Language</h3>
<form>
<ul style="list-style-type:none;">
<li><input type="checkbox"
name="language" value="hindi" />
Hindi
</li>
<li><input type="checkbox"
name="language" value="english" />
English
</li>
<li><input type="checkbox"
name="language" value="sanskrite" />
Sanskrit
</li>
</ul>
</form>
</div>
</body>
</html>
Output:
Output
Syntax:
<select name="select_box_name">
<option value="value1">option1</option>
<option value="value2">option2</option>
<option value="value3">option3</option>
</select>
Note: the “name” and “value” attributes are used to send the Combobox data
to the server.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input {
padding: 10px;
}
<body>
<div class="main">
<h1>Welcome To GFG</h1>
<h3>Choose Your Nationality</h3>
<form>
<select name="language">
<option value="indian">
Indian
</option>
<option value="nepali">
Nepali
</option>
<option value="others">
Others
</option>
</select>
</form>
</div>
</body>
</html>
Output:
Output
In the HTML form, submit button is used to submit the details of the form to
the form handler. A form handler is a file on the server with a script that is
used to process input data.
Syntax:
<button type="submit">submit</button>
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
margin-left: 50px;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input,
button {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GFG</h1>
<form onsubmit="showAlert(event)">
<p>
<label>
Username:
<input type="text" />
</label>
</p>
<p>
<label>
Password:
<input type="password" />
</label>
</p>
<p>
<button type="submit">Submit</button>
</p>
</form>
</div>
<script>
function showAlert(event) {
// Prevents the default form submission
event.preventDefault();
alert('Form submitted!');
}
</script>
</body>
</html>
Output:
Output
Syntax:
<textarea name="textarea_name">content</textarea>
Note: the name attribute is used to reference the textarea data after it is sent to
a server.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
margin-left: 50px;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input,
button {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GeeksforGeeks</h1>
<form>
<textarea name="welcomeMessage"
rows="23" cols="40">
GeeksforGeeks is a online portal
</textarea>
</form>
</div>
</body>
</html>
Output:
Output
In this example, we will take input such as Salutation, First Name, Last Name,
Email, Phone, Gender, Date of Birth, and Address.
To create this form, we need to use the <legend> tag to define the caption,
<select> tag for Salutation, <option> tag to define elements of Salutation,
<input> tag for First Name, Last Name, Email, Phone, Date of Birth by changing
<input> tag type attribute, <textarea> to input address, the radio button for
gender. After defining all these stuff, we will use a <button> to submit this
form data.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
margin-left: 50px;
font-family: Arial, sans-serif;
line-height: 1.8;
min-height: 100vh;
background: #ffffff;
flex-direction: column;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1,
h3 {
text-align: center;
color: green;
}
input,
button {
padding: 10px;
}
</style>
</head>
<body>
<div class="main">
<h1>Welcome To GeeksforGeeks</h1>
<form>
<fieldset>
<legend>Personal Details</legend>
<p>
<label>
Salutation
<br />
<select name="salutation">
<option>--None--</option>
<option>Mr.</option>
<option>Ms.</option>
<option>Mrs.</option>
<option>Dr.</option>
<option>Prof.</option>
</select>
</label>
</p>
<p>
<label>First name:
<input name="firstName" />
</label>
</p>
<p>
<label>Last name:
<input name="lastName" />
</label>
</p>
<p>
Gender :
<label><input type="radio"
name="gender" value="male" />
Male
</label>
<label><input type="radio"
name="gender" value="female" />
Female
</label>
</p>
<p>
<label>Email:
<input type="email" name="email" />
</label>
</p>
<p>
<label>Date of Birth:
<input type="date" name="birthDate">
</label>
</p>
<p>
<label>
Address :
<br />
<textarea name="address"
cols="30" rows="3">
</textarea>
</label>
</p>
<p>
<button type="submit">Submit</button>
</p>
</fieldset>
</div>
</body>
</html>
Output:
Output
Previous Next
Similar Reads
Largest lexicographic triplet from a given New Forms of Publications
Array that forms a triangle
Search Write
101
1. Missing or incorrect DOCTYPE
The DOCTYPE tells Web browsers what version of HTML your page is using.
Technically, it refers to a Document Type Definition (DTD) that specifies the
rules for that version of HTML.
The DOCTYPE should always the very first line of your HTML code and it IS
case sensitive.
Example:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8">
<img src=myimage.gif>
<font color=#FF00FF>
If any of the lines cross, then you have probably nested improperly.
Correct:
Incorrect:
It is very common to improperly code when nesting lists (such as those
your viewing right now). Any nested <UL> or <OL> must be enclosed
within a parent <LI>.
5. Improper Tables
Tables are a common culprit of improper HTML. It is easy to incorrectly
code tables and most browsers will let you get away with it. Assistive
technologies are very strict about proper table structure. Common table
mistakes are:
Not closing the <table>, <tr>, or <td> tags or closing them improperly (see
above)
Surrounding table cells or rows with text formatting tags (i.e., <table><b>
<tr><td>I am bold</td></tr></b></table>)
Data tables should have a caption, immediately after the opening table
tag — <table><caption>Data from Jello Eating Contest</caption><tr> …
Incorrect:
<table><form><tr><td>….. </td></tr></form></table>
Correct:
<form><table><tr>…. </tr></table></form>
10. Align=absmiddle
This commonly used HTML extension is not proper HTML for the img tag
(i.e., <img src=”image.gif” align=”absmiddle”>). This attribute IS supported
by the major browsers, but if you want your code to be correct, use either
align=middle or CSS to align text to the middle of images.
<script type=”text/javascript”>
<script type=”text/javascript”>
</script>
<noscript>
</noscript>