HTML Interview Questions - Set 2

HTML Interview Questions

Share

This page contains HTML interview questions and answers.

Q1: What is an image map?

An image map is an image with some defined shapes that are linked to some web pages. So, when we click on the shape drawn on the image we are taken to some website page.

Q2: How to create tables in HTML?

To create tables in HTML we use the table tag.

In the following example we are creating a table having 2 rows and 3 columns.

<table border="1">

<tr>
<th>Team</th>
<th>Score</th>
</tr>

<tr>
<td>A</td>
<td>10</td>
</tr>

<tr>
<td>B</td>
<td>10.2</td>
</tr>

</table>
Team Score
A 10
B 10.2

Q3: Create "Back to top" link to jump to the top of the page in HTML?

To solve this we will first create an anchor tag a at the beginning of the page ideally close to the body tag. And we will set the name attribute of the anchor tag to lets say back-to-top.

<a name="back-to-top"></a>

Now we create another anchor tag in the page from were we want to jump back to the top of the page and we set the href attribute to #back-to-top.

<a href="#back-to-top">Back to top</a>

Now if the user clicks the Back to top link the page will scroll back to the top of the page.

Q4: How to color a word in a paragraph in HTML?

One way of doing this is by enclosing the word in a span tags and then use the style attribute and set the color to the desired value.

In the following example we are changing the color of the word super to blue.

<p>This is <span style="color: blue;">super</span>!</p>

This is super!

Q5: What are HTML attributes and where do we add them?

HTML attributes are added in the opening tag and they provide additional information about the element.

In the following example we have an img tag and it has 5 attributes.

<img class="super-image" 
     src="path/to/image.png"
     width=200
     height=30
     alt="logo">

Q6: Can we assign any value to any attribute or is there a specific value for specific attribute?

There are some attributes that can take any value. Then there are some that can take only specific values and we also have some that needs no value.

For example src, value, alt are some attributes that can take any value.

Then, we have attributes like autocomplete which can take either on and off value.

And required, disabled, autofocus are some attributes that can be added to the input field without specifying any value.

Q7: What is the process of opening a link in a new tab or window?

To solve this we have to add the target attribute to the a tag and set the value to _blank.

<a href="https://www.dyclassroom.com" alt="dyclassroom" target="_blank">Open link in new tab</a>

Q8: Name some of the web browsers?

Chrome, Safari, Edge, Firefox are some of the web browsers.

Q9: Is there a way to change the background color of the HTML page?

Yes. By adding bgcolor attribute in the opening body tag and setting its value to some color we can change the background color of the HTML page.

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body bgcolor="lightskyblue">
  <h1>Hello World</h1>
</body>
</html>

Q10: How can we set the dimensions of an image in HTML?

To set the dimensions of an image we use the width and height attributes.

In the following example we are setting the width and height of an image to 200 pixels and 30 pixels respectively.

<img src="path/to/image.png" alt="brand-logo" width=200 height=30>
Share

Recently Updated