HTML Intreview Questions and Answers
HTML Intreview Questions and Answers
The full form of HTML stands for Hypertext Markup Language and it also
allows the user to create and structure sections, paragraphs, headings,
links, and blockquotes for web pages and applications.
Images are not inserted into a web page basically they are linked to web
pages. The <img> tag helps to create a holding space for the referenced
image.
The <img> tag is normally empty, it has attributes only, and does not have
a closing tag.
Full form of CSS stands for Cascading Style Sheets (CSS) which is used to
format the layout of a webpage.
With the help of CSS, someone can control the color, font, the size of text,
the spacing between elements and also how elements are positioned and
laid out, what background images or background colors to be used,
different displays for different devices and screen sizes, and so many more
as well.
Types of CSS:
Inline CSS
An inline CSS can be used to apply a unique and also different style to a
single HTML element.
Now put the text color of the <h1> element to red, and the text color of the
<p> element to blue:
Internal CSS
An internal CSS can be used to define a style for a single HTML page.
Now let’s have an example of the text color of ALL the <h1> elements (on
that page) to blue, and the text color of ALL the <p> elements to red.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
External CSS
An external style sheet concept is normally used to define the style for
many HTML pages.
In order to start using an external style sheet, put a link to it in the <head>
section of each HTML page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Basically, if you want to align your text using HTML, then you need to use
css and follow the proper process:
div.a {
text-align: center;
div.b {
text-align: left;
div.c {
text-align: right;
div.c {
text-align: justify;
}
HTML tables help web developers to set the data into rows and columns.
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Hobbies</th>
</tr>
<tr>
<td>Ram</td>
<td>Kumar</td>
<td>Travelling</td>
</tr>
<tr>
<td>Shyam</td>
<td>Chadra</td>
<td>Reading books</td>
</tr>
</table>
If you are working in a Windows system then open an HTML web page in
Internet Explorer, Google Chrome or Firefox.
The HTML style attribute is the option to add styles to an element, like:
Color, Font, Size, and more.
<!DOCTYPE html>
<html>
<body>
<p>I am normal</p>
</body>
</html>
1. <font Color=”Blue”>
2. <font color=”rgb(128,128,0)”
3. <font color=”#00FF00″>
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
<font color="orange">
<!-- The color attribute of font tag sets the color name 'orange' for the word
Great Learningt-->
<center>
<h1>
Great Learning
</h1>
</center>
</font>
</body>
</html>
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML Font</title>
</head>
<body>
<h1>Our Products</h1>
</p>
</body>
</html>
15. How to add space using < pre > tag in HTML?
The pre tag is used to create preformatted text. The text inside this tag will
preserve both spaces and line breaks. To add space using the tag, you can
add the style attribute and set the value to “margin:10px”.
DOM stands for Document Object Model. When a web page is getting
loaded that time the browser creates a Document Object Model of the page
and it is constructed as a tree of Objects. HTML DOM is basically an Object
Model for HTML.
<form>
</form>
<option value="Mango">Mango</option>
<option value="Lichhi">Licchi</option>
</select>
The div tag stands for Division tag. This is used in HTML to make divisions
of content in the web page like text, images, header, footer, navigation bar,
etc. Div tag has two parts like:
1. open(<div>) and
2. closing (</div>) tag and it is mandatory to maintain the tag.
The Div is the most used tag in web page development because it has
power to separate respective data in the web page and also a particular
section can be created for particular data or function in the web pages.
<head>
<style type=text/css>
p{
background-color:gray;
margin: 100px;
div
color: white;
background-color: 009900;
margin: 4px;
font-size: 35px;
</style>
</head>
<body>
</html>
HTML is used to make static web pages and HTML stands for markup
language.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Demo</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<body>
<h1 style="color:red;font-size:40px;">Heading</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>Button Colors</h2>
<button class="button">Green</button>
</body>
</html>
HTML5 is the newest version of HTML and it is better than HTML because
it includes new features like audio and video elements, new semantic
elements, and support for local storage.
The HTML <span> element stands for a generic inline container for
phrasing content, that does not inherently represent anything. It can also be
used to group elements for styling purposes like using the class or id
attributes, or because they share attribute values, such as lang.
<u> tag is used for underline the text. The <u> tag was deprecated
in HTML, but then they re-introduced in HTML5.
<font Color=”Blue”>
<font color=”rgb(128,128,0)”
<font color=”#00FF00″>
1
2
3
4
5
6
7
8
9
1<!DOCTYPE html>
0<html>
1<head>
1<title>
1 Example of color attribute
2</title>
1</head>
3<body>
1<font color="orange">
4<!-- The color attribute of font tag sets the color name 'orange' for t
1<center>
5<h1>
1Great Learning
6</h1>
1</center>
7</font>
1</body>
8</html>
37. How to add a link in HTML?
To add links in html we use <a> and </a> tags, which are the tags used to
define the links. The <a> tag indicates where the hyperlink starts and the
</a> tag indicates where it ends. Whatever text gets added inside these
tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.
1<!DOCTYPE html>
2
3
4
5<html lang="en">
6<head>
7 <title>Title of the document</title>
8</head>
9<body>
1
0<h1>This is a heading</h1>
1<p>This is a paragraph.</p>
1
1</body>
2</html>
39. How to create a checkbox in HTML?
1<!DOCTYPE html>
2<html>
3<head>
4<style>
5div {
6 background-color: lightgrey;
7 width: 300px;
8 border: 15px solid green;
9 padding: 50px;
1 margin: 20px;
0}
1</style>
1</head>
1<body>
2
1<h2>Demonstrating the Box Model</h2>
3
1<p>Hey, welcome to Great Learning.</p>
4
1<div>Great Learning Academy is an initiative taken by Great Learning, w
5Science, Machine Learning, Artificial Intelligence, Cloud Computing, Bu
1
6</body>
1</html>
7
1
8
1
9
2
0
2
1
2
2
2
3
41. How to add a scroll bar in HTML?
1<!DOCTYPE html>
2<html>
3<head>
4<style>
5div.ex1 {
6 background-color: lightblue;
7 width: 110px;
8 height: 110px;
9 overflow: scroll;
1}
0
1div.ex2 {
1 background-color: lightblue;
1 width: 110px;
2 height: 110px;
1 overflow: hidden;
3}
1
4div.ex3 {
1 background-color: lightblue;
5 width: 110px;
1 height: 110px;
6 overflow: auto;
1}
7
1div.ex4 {
8 background-color: lightblue;
1 width: 110px;
9 height: 110px;
2 overflow: visible;
0}
2</style>
1</head>
2<body>
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0<h1>Welcome to great learning</h1>
4
1
4
2<h2>scroll:</h2>
4<div class="ex1">Great Learning Academy is an initiative taken by Great
3in Data Science, Machine Learning, Artificial Intelligence, Cloud Compu
4</body>
4</html>
42. What is an attribute in HTML?
1
2<!DOCTYPE html>
3 <html>
4 <head>
5 <title>Demo HTML font size</title>
6 </head>
7 <body>
8 <h1 style="color:red;font-size:40px;">Heading</h1>
9 <p style="color:blue;font-size:18px;">Font size demo</p>
1 </body>
0</html>
45. How to change color of text in HTML?
To text bold in HTML, use the <b> </b> tag or <strong> </strong> tag.
1<!DOCTYPE html>
2<html>
3<body>
4
5<h1>The footer element</h1>
6
7<footer>
8 <p>demo of footer<br>
9 <a href="mailto:[email protected]">[email protected]</a></p>
1</footer>
0
1</body>
1</html>
1
2
1
3
1
4
48. Who invented HTML?
1
2
3
4<!DOCTYPE html>
5<html>
6<body>
7
8
9 <header>
1 <b>hey</b>
0 </header>
1
1
1</body>
2</html>
52. How to give space between two buttons in HTML?
1<div class='myDiv'>
2 <button style='margin-right:16px'>Button 1</button>
3 <button style='margin-right:16px'>Button 2</button>
4 <button>Button 3</button>
5</div>
53. How to change image size in HTML?
You can create a .png image and then use f the following snippets between
the <head> tags for the static HTML documents:
1<div class="container">
2 <img src="img_snow.jpg" alt="Snow" style="width:100%;">
3 <div class="bottom-left">Left</div>
4 <div class="top-left">Up Left</div>
5 <div class="top-right">Up Right</div>
6 <div class="bottom-right"> Right</div>
7 <div class="centered">Middle</div>
8</div>
59. How to create a popup in html with CSS?
The HTML <blink> tag stands for a non-standard element that is used to
create an enclosed text. It flashes slowly and normally blinks, meaning is
light flashing on and off in a regular or intermittent way so samely blinking
effect is used very rarely, as it is not eye soothing for users to watch a part
of text constantly turning on and off.
1
2
3
4
5
6
7
8
9
1
0
1<!DOCTYPE html>
1<html>
1<body>
2
1
3
1<button onclick=”CalenderFunction()">Put the date</button>
4
1
5<script>
1function CalenderFunction()n() {
6 var x = document.createElement("INPUT");
1 x.setAttribute("type", "date");
7 x.setAttribute("value", "2014-02-09");
1 document.body.appendChild(x);
8}
1</script>
9
2</body>
0</html>
63. How to add video in HTML?
1The HTML <video> element is used to show a video on a web page.
2<video width="320" height="240" controls>
3 <source src="movie.mp4" type="video/mp4">
4 <source src="movie.ogg" type="video/ogg">
5Your browser does not support the video tag.
6</video>
64. How to add google map in HTML?
1
2
3
4
5
6
7
8
9
1
0
1
1
1<!DOCTYPE html>
2<html>
1<body>
3
1<h1> Google Map</h1>
4
1<div id="googleMap" style="width:100%;height:400px;"></div>
5
1<script>
6function myMap() {
1var mapProp= {
7 center:new google.maps.LatLng(51.508742,-0.120850),
1 zoom:5,
8};
1var map = new google.maps.Map(document.getElementById("googleMap"),mapP
9}
2</script>
0
2<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callb
1
2</body>
2</html>
65. How to create registration form in HTML with database?
1<form>
2 <label for="fname">First name:</label><br>
3 <input type="text" id="fname" name="fname"><br>
4 <label for="lname">Last name:</label><br>
5 <input type="text" id="lname" name="lname">
6</form>
66. How to create a dynamic calendar in HTML?
1<div class="month">
2 <ul>
3 <li class="prev">❮</li>
4 <li class="next">❯</li>
5 <li>August<br><span style="font-size:18px">2017</span></li>
6 </ul>
7</div>
8
9<ul class="weekdays">
1 <li>Mo</li>
0 <li>Tu</li>
1 <li>We</li>
1 <li>Th</li>
1 <li>Fr</li>
2 <li>Sa</li>
1 <li>Su</li>
3</ul>
1
4<ul class="days">
1 <li>1</li>
5 <li>2</li>
1 <li>3</li>
6 <li>4</li>
1 <li>5</li>
7 <li>6</li>
1 <li>7</li>
8 <li>8</li>
1 <li>9</li>
9 <li><span class="active">10</span></li>
2 <li>11</li>
0 </ul>
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
67. How to create frames in HTML?
1
2
3
4
5
6
7
8
9
1
0<!DOCTYPE html>
1<html>
1
1 <head>
2 <title>HTML Demp Frames</title>
1 </head>
3
1 <frameset rows = "10%,80%,10%">
4 <frame name = "top1" src = "/html/top_frame.htm" />
1 <frame name = "mainframe" src = "/html/main_frame.htm" />
5 <frame name = "bottompart" src = "/html/bottom_frame.htm" />
1
6 <noframes>
1 <body>Hey Great Learning</body>
7 </noframes>
1
8 </frameset>
1
9</html>
68. How to create a menu in HTML?
1<!DOCTYPE html>
2<html>
3<head>
4<meta name="viewport" content="width=device-width, initial-scale=1">
5<style>
6div {
7 width: 35px;
8 height: 5px;
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6 background-color: black;
1 margin: 6px 0;
7}
1</style>
8</head>
1<body>
9
2<p>Menu icon:</p>
0
2<div></div>
1<div></div>
2<div></div>
2
2</body>
3</html>
69. What is the difference between HTML tags and elements?
The starting and ending tags mark the beginning and end of the HTML
element. The tags are enclosed within the < and > symbol. HTML Elements
is the text written between HTML tags and it holds the content.
There are 6 types of headings that can be found in HTML which are
numbered <h1> to <h6> from largest to smallest. Headings are used in the
following way.
To insert the copyright symbol you can use the “©” as well as “©”
in the HTML file.
<meta> is the tag used to specify metadata in HTML. <meta> is a void tag
which means there is no closing tag.
The block elements take up the full page width and start on a new line,
instead of inline element that only take the space to accommodate the
length of the content and continue on the same line. Some examples of
block elements are <div>, <p>, <header>, <footer>, <h1>…<h6>, <form>,
<table>, <canvas>, <video>, <blockquote>, <pre>, <ul>, <ol>, <figcaption>,
<figure>, <hr>, <article>, <section>, etc. Some examples of inline
elements are <span>, <a>, <strong>, <img>, <button>, <em>, <select>,
<abbr>, <label>, <sub>, <cite>, <abbr>, <script>, <label>, <i>, <input>,
<output>, <q>, etc.
Audio tags are supported in HTML5 and with these, you can add audio to a
webpage. The file formats supported by HTML5 include MP3, WAV, and
OGG.
To change the color of the bullet, you need to change the text color of the
first line in the list. The bullet takes the color from the first line of the list.
76. How can you keep list elements straight in an HTML file?
You can use indents to keep the elements of a list aligned straight. You can
use a nested list and indent them further than the parent list, you can
quickly determine the lists and elements contained under the list.
If you want to collect the information of the visitors to the webpage, you can
add a form to the webpage. Once the user enters the information into the
form fields, it is added to a database specified by you.
Some elements in HTML only need an opening tag, without the need for a
close tag, and these are known as void elements. Some examples are
<br />, <img />, <hr />, etc.
A scrolling text that can go in a specific direction across the screen i.e. left,
right, up, or down, automatically. For this you can use the tag <marquee>
Text to scroll </marquee>.
Whenever you need to link any two web pages, website templates, or
sections, you can do so using the anchor tag. The anchor tag format is <a
href=”#” target=”link”></a>. Here the ‘link’ is defined as the target attribute,
while the ‘href’ attribute indicates the sections in the documents.
Identified by the <map> tag, the image map can link an image to different
web pages. It is one of the most asked questions in interviews these days.
The datalist tag is an HTML tag that lets the user auto-complete the form
based on the predefined options. It presents the users with predefined
options that they can choose from. An example of this can be as below:
<label>
<datalist id=”BolActor”>
</datalist>
</label>
It is an attribute that refers to one or more than one class name for an
HTML element. The class attribute can be used for the HTML elements.
The HTML figure tag is used for adding self-contained content such as
illustrations, photos, diagrams, or code listings. HTML figure tag contains
two tags such img src and figcaption. Img src is used for adding image
source in a document; while figcaption is used for setting caption to an
image.
The common doctype declaration for different version of HTML and XHTML
are:
1. For HTML 5 we simply write <!DOCTYPE html>
2. HTML 4.01 Strict: The strict version of HTML 4.01 does not
permit presentational to be written within HTML Elements. It
also does not support inclusion of Frames.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
“http://www.w3.org/TR/html4/transitional.dtd”>
“http://www.w3.org/TR/html4/frameset.dtd”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd”>
8. XHTML 1.1: In XHTML 1.1 version document type definition
(DTD), allows the addition of modules
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
89. Please explain how to indicate the character set being used by a
document in HTML?
1<head>
2 <title>Charset HTML</title>
3 <meta charset="UTF-8">
4</head>
90. What is the advantage of collapsing white space?
Page loading refers to how quickly your content is displayed when a user
visits a page on your site.
Cell Padding and Cell Spacing are the attributes of formatting a table
basically sets the white spaces in your table.
Used to fix the width/space between the Fixes the white space between the single cell, i.e.,
border and its content space between the edges and adjacent cell
Syntax: Syntax:
<table cellpadding=”value” > <table cellspacing=”value” >
….. …..
….. ……
</table> </table>
Here, cellpadding value specifies the space Here, cellspacing value specifies the space
between the border and its content between adjacent cells
Example:
static.
relative.
fixed.
absolute.
sticky.
96. How to include javascript code in HTML?
There are two ways we can include javascript code in the HTML
Can add the script tag either in the head section of the body section of an
HTML document depending on when you want the script to be loaded.
2. External Js: create a separate javascript file and save it with .js
extension and with the help of src attribute of script tag add
the .js file to the HTML document as shown below:
<script src=”file1.js”></script>
The Head and Body tag of HTML have their own significance as below:
Head Body
Describes the metadata or information Describes the documents main content of an HTML
related to the document document
Head Tag contains the title for the Body tag contains all the contents of an HTML
document, and also other tags such as document, defined using different tags such as text,
scripts, styles, links, and meta. hyperlinks, images, tables, lists, etc.