If you are new to programming or coding and have started learning HTML or have good knowledge of HTML but want to test you skills, here are the top HTML Interview questions with answers which can be helpful for you.

html-interview-questions-min.png

What is HTML?

HTML stands for Hypertext Markup language, it is standard language used to create web-pages. It consistes of tags which is used to define content and web page formatting.

What is Doctype in HTML?

Doctype is not a HTML element. Rather, the doctype element specifies which version of the markup language is used. It also contains instructions about the elements and properties available in HTML code.

Doctype must always be the first element of a web page. This means that it is placed in HTML code before the actual mark-up code and thus before the HTML tag.

Difference between html element and tags?

HTML tag is just opening or closing entity. For example: <div> and </div> are called HTML tags

An element in HTML represents some kind of structure or semantics and generally consists of a start tag, content (optional for content-less tags), and an end tag . For example:

<div>This is the content</div> ,This complete thing is called a HTML element

html-element-tag-difference-min.png

What is HTML attribute?

HTMl attribute puts additional information in HTML elements for example

<p id="first">My first paragraph.</p>

In the above HTML, "id" is an attribute, using which we can apply CSS to html element or can be used in Javascript to perform certaing operations.

Do all HTML tags are written in pair (open and closed)?

No, some html tags doesn't require closing tags like <img />, <br/>, <hr/> ,<meta> etc

What are some common lists type used in HTML?

  • Ordered list
  • Unordered list
  • Definition list
  • Menu list
  • Directory list

What is the difference between <div> and <frame>?

The <div> tag defines a division or a section in an HTML document and it is used to group-elements to format them with CSS.

 <frame> creates divisions within a web page and should be used within the <frameset> tag. The <frame> tag is not supported in HTML5.

How to write comments in HTML?

You can write comments using "<!--Comment-->" in your HTML code.

 <!-- This is a comment -->

<p>This is a paragraph.</p>

<!-- Some more comment --> 

What is the difference between HTML and HTML5?

HTML5 is the newest version of HTML, here is the difference between them:

  • HTML5 supports both audio and video whereas none of these was a part of HTML
  • HTML5 allows JavaScript to run in background using Web-Worker API while it is not possible with HTML.
  • In HTML5 vector graphics are possible with new html tags <canvas> or <svg> while in old HTML you had to use silverlight or flash for it.
  • HTML5 allows drag and drop, while HTML doesn't allow it.
  • Using HTML5 it is possible to draw shapes like cicular, rectangular, while it is not possible with old HTML.
  • Attributes like charset, async and ping are absent in HTML while Attributes of charset, async and ping are a part of HTML 5.
  • Elements like nav, header were not present in HTML while HTML5 contains web-structure elements like nav, header.

What is the difference between <SVG> and <Canvas>?

SVG:

  • SVG is Object Model-based.
  • Scalable Vector Graphics (SVG) is used to define 2D vector based graphics for the Web
  • The Document Object Model (DOM) has the subpart as multiple graphical elements.
  • With HTML, Visual presentation is created and by CSS it is modified or programmatically through the script.
  • Accessibility is supported by SVG markup and object model directly.
  • Good scalability, can be used at any resolution, with high quality.

Canvas:

  • Canvas is pixel based.
  • Canvas can be used for either a 2D or 3D drawing context.
  • Through script, we can create visual presentation and modified programmatically.
  • Worst scalability, not suitable for higher resolution and printing.

Explain Cell Padding and Cell Spacing.

Cell Padding : It refers to the gap or space between the cell content and cell border or cell wall.
Cell Spacing : It refers to the gap between the two cells of same tables.

How many types of CSS can be included in HTML?

In 3 ways we can add CSS in html web-page

  • Inline CSS: To use inline styles add the style attribute in the relevant tag.
  • External Style Sheet: It is used when the style is applied to many pages. You can include it in HTML as below|
    <head>
        <link rel="stylesheet" type="text/css" href="mystyle.css" />
    </head>
  • Internal Style Sheet: It is used within single page and CSS placed inside <style></style> tags inside <head> tag of HTML.
    <head>
     <style>
       p{
       color:red;
       }
     </style>
    </head>

Explain about marquee tag

Marquee tag is used when we want that some text or content move in the web page whether horizontally or vertically.

<marquee>This is moving text</marquee>

What are the different ways to represent color in HTML?

Specifies the text color with a color name (like "green").

Specifies the text color with a hex code (like "#ff0000").

Specifies the text color with an rgb code (like "rgb(255,0,0)")

What is the use of image map?

A image map is an image with clickable areas. It is a list of coordinates relating to a specific image. It provides an easy way of linking various parts of an image without dividing the image into separate image files.

How can we get the geographic position of a user in HTML5?

By using Geolocation API we can retrieve the location of the user, it would also require us to use Javascript.