Note: This article covers the most frequently asked HTML and HTML5 questions asked in interviews.

  • HTML stands for HyperText Markup Language.

  • It is a standard text formatting language used for developing web pages released in 1993.

  • HTML is a language that is interpreted by the browser and it tells the browser what to display and how to display.

  • HTML is an important language to learn if anyone wants to work in the web development domain [Web designers, Web Developers].

  • HTML alone is not sufficient for a web developer because HTML only defines the structure of the data that will be rendered on the browser in a webpage, to make it visually appealing and to make it functional, we will need to use CSS and Javascript respectively.

  • The latest version of HTML is HTML5. There are two main components in HTML language, Tags and Attributes.

  • The below image shows some basic HTML tags and attributes.

No. HTML elements are defined by a starting tag, may contain some content and a closing tag.For example, <h1>Heading 1</h1> is a HTML element but just <h1> is a starting tag and </h1> is a closing tag.

Tags are the primary component of the HTML that defines how the content will be structured/ formatted, whereas Attributes are used along with the HTML tags to define the characteristics of the element. For example, <p align=” center”>Interview questions</p>, in this the ‘align’ is the attribute using which we will align the paragraph to show in the center of the view.

HTML elements which do not have closing tags or do not need to be closed are Void elements. For Example <br />, <img />, <hr />, etc.

In HTML, a blank sequence of whitespace characters is treated as a single space character, Because the browser collapses multiple spaces into a single space character and this helps a developer to indent lines of text without worrying about multiple spaces and maintain readability and understandability of HTML codes

In HTML some characters are reserved like ‘<’, ‘>’, ‘/’, etc. To use these characters in our webpage we need to use the character entities called HTML Entities. Below are a few mapping between the reserved character and its respective entity character to be used.

The class attribute is used to specify the class name for an HTML element. Multiple elements in HTML can have the same class value. Also, it is mainly used to associate the styles written in the stylesheet with the HTML elements.
Multipart form data is one of the values of the enctype attribute. It is used to send the file data to the server-side for processing. The other valid values of the enctype attribute are text/plain and application/x-www-form-urlencoded.
  • Every web page has different components to display the intended content and a specific UI. But still, there are few things which are templated and are globally accepted way to structure the web page, such as:
  • Stores the starting information about the web page.
  • Represents the last section of the page.
  • The navigation menu of the HTML page.
  • It is a set of information.
  • It is used inside the article block to define the basic structure of a page.
  • Sidebar content of the page
    To optimize website load time we need to optimize its asset loading and for that:

  • CDN hosting - A CDN or content delivery network is geographically distributed servers to help reduce latency.

  • File compression - This is a method that helps to reduce the size of an asset to reduce the data transfer

  • File concatenation - This reduces the number of HTTP calls

  • Minify scripts - This reduces the overall file size of js and CSS files.

  • Parallel downloads - Hosting assets in multiple subdomains can help to bypass the download limit of 6 assets per domain of all modern browsers. This can be configured but most general users never modify these settings.

  • Lazy Loading - Instead of loading all the assets at once, the non-critical assets can be loaded on a need basis.
  • <b> - makes text bold
  • <i> - makes text italic
  • <em> - makes text italic but with added semantics importance
  • <big> - increases the font size of the text by one unit
  • <small> - decreases the font size of the text by one unit
  • <sub> - makes the text a subscript
  • <sup> - makes the text a superscript
  • <del> - displays as strike out text
  • <strong> - marks the text as important
  • <mark> - highlights the text
  • <ins> - displays as added text
  • The three kinds of Doctypes which are available:

    • Strict Doctype 
    • Transitional Doctype
    • Frameset Doctype

    The character set is defined in <meta> tag inside <head> element.

    The effect on a normal webpage of the tags <strong>, <b>  and <em>, <i> is the same. <b> and <i> tags stands for bold and italic. These two tags only apply font styling and bold tag <b>, just adds more ink to the text, these tags don't say anything about the text.

    Whereas, <strong> and <em> tags represent that the span of text is of strong importance or more importance and emphatic stress respectively than the rest of the text. These tags have semantic meaning.

    <head> tag provides the information about the document. It should always be enclosed in the <html> tag. This tag contains the metadata about the webpage and the tags which are enclosed by head tag like <link>, <meta>, <style>, <script>, etc. are not displayed on the web page. Also, there can be only 1 <head> tag in the entire Html document and will always be before the <body> tag.

    <body> tag defines the body of the HTML document. It should always be enclosed in the <html> tag. All the contents which needs to be displayed on the web page like images, text, audio, video, contents, using elements like <p>, <img>, <audio>, <heading>, <video>, <div>, etc. will always be enclosed by the <body> tag. Also, there can be only 1 body element in an HTML document and will always be after the <head> tag.

    Yes, we can display a web page inside another HTML web page. HTML provides a tag <iframe> using which we can achieve this functionality.

    Cell Spacing is the space or gap between two consecutive cells. Whereas, Cell Padding is the space or gap between the text/ content of the cell and the edge/ border of the cell. Please refer to the above figure example to find the difference.

    HTML provides two table attributes “rowspan” and “colspan” to make a cell span to multiple rows and columns respectively.

    Yes, it is possible using the “display” property with its value as “block”, to change the inline element into a block-level element.

    There are mainly 7 values of position attribute that can be used to position an HTML element:

    1. static: Default value. Here the element is positioned according to the normal flow of the document.
    2. absolute: Here the element is positioned relative to its parent element. The final position is determined by the values of left, right, top, bottom.
    3. fixed: This is similar to absolute except here the elements are positioned relative to the <html> element.
    4. relative: Here the element is positioned according to the normal flow of the document and positioned relative to its original/ normal position.
    5. initial: This resets the property to its default value.
    6. inherit: Here the element inherits or takes the property of its parent.

    There are mainly 7 values of position attribute that can be used to position an HTML element:

    1. inline: Using this we can display any block-level element as an inline element. The height and width attribute values of the element will not affect.
    2. block: using this, we can display any inline element as a block-level element.
    3. inline-block: This property is similar to inline, except by using the display as inline-block, we can actually format the element using height and width values.
    4. flex: It displays the container and element as a flexible structure. It follows flexbox property.
    5. inline-flex: It displays the flex container as an inline element while its content follows the flexbox properties.
    6. grid: It displays the HTML elements as a grid container.
    7. none: Using this property we can hide the HTML element.

    Below are some of the display types which are rarely used:

    1. table
    2. inline-table
    3. table-cell
    4. table-column
    5. table-row
    6. inline-grid
    7. list-item
    8. inherit
    9. initial
    10. table-caption

    When we use the attribute “visibility: hidden” for an HTML element then that element will be hidden from the webpage but still takes up space. Whereas, if we use the “display: none” attribute for an HTML element then the element will be hidden, and also it won’t take up any space on the webpage.

    HTML provides a hyperlink - <a> tag to specify the links in a webpage. The ‘href’ attribute is used to specify the link and the ‘target’ attribute is used to specify, where do we want to open the linked document. The ‘target’ attribute can have the following values:

    1. _self: This is a default value. It opens the document in the same window or tab as it was clicked.
    2. _blank: It opens the document in a new window or tab.
    3. _parent: It opens the document in a parent frame.
    4. _top: It opens the document in a full-body window.
    • Inline: Here we use the ‘style’ attribute inside the HTML element.
    • Internal: Here we use the <style> tag inside the <head> tag. To apply the style we bind the elements using ‘id’ or ‘class’ attributes.
    • External: Here we use the <link> tag inside <head> tag to reference the CSS file into our HTML code. Again the binding between elements and styles is done using ‘id’ or ‘class’ attributes.

    HTML provides a <script> tag using which we can run the javascript code and make our HTML page more dynamic.

    If the scripts contain some event-triggered functions or jquery library then we should use them in the head section. If the script writes the content on the page or is not inside a function then it should be placed inside the body section at the bottom. In short, follow below three points:

    1. Place library scripts or event scripts in the head section.
    2. Place normal scripts that do not write anything on the page, in the head section until there is any performance issue.
    3. Place scripts that render something on the web page at the bottom of the body section.

    The HTML form is used to collect the user inputs. HTML provides a <form> tag to create forms. To take input from the user we use the <input> tag inside the form so that all collected user data can be sent to the server for processing. There are different input types like ‘button’, ‘checkbox’, ‘number’, ‘text’, ‘password’, ‘submit’ etc.

    HTML allows event trigger actions in browsers using javascript or JQuery. There are a lot of events like ‘onclick’, ‘ondrag’, ‘onchange’, etc.

    Some advantages of HTML5 are:-

    • It has Multimedia Support.
    • It has the capabilities to store offline data using SQL databases and application cache.
    • Javascript can be run in the background.
    • HTML5 also allows users to draw various shapes like rectangles, circles, triangles, etc.
    • Included new Semantic tags and form control tags.

    HTML5 provides two tags: <audio> and <video> tags using which we can add the audio or video directly in the webpage.

    Inline Block
    Inline elements just take up the space that is absolutely necessary for the content and does not start from a new line.
    Example:- <span>, <a>, <strong>, <img>, <button>, <em>, <select>, <abbr>, <label>, <sub>, <cite>, <abbr>, <script>, <label>, <i>, <input>, <output>, <q>, etc.
    Block elements start on a new line and consume the full width of the page available.
    Example:- <div>, <p>, <header>, <footer>, <h1>...<h6>, <form>, <table>, <canvas>, <video>, <blockquote>, <pre>, <ul>, <ol>, <figcaption>, <figure>, <hr>, <article>, <section>, etc.


    The <figure> tag specifies the self-contained content, like diagrams, images, code snippets, etc. <figure> tag is used to semantically organize the contents of an image like image, image caption, etc., whereas the <img> tag is used to embed the picture in the HTML5 document.

    To specify we can use <meta> tag which is a void tag,i.e., it does not have a closing tag. Some of the attributes used with meta tags are name, content, http-equiv, etc. The below image tells how to specify the metadata.

    No. The <datalist> tag and <select> tag are different. In the case of <select> tag a user will have to choose from a list of options, whereas <datalist> when used along with the <input> tag provides a suggestion that the user selects one of the options given or can enter some entirely different value.

    Image Map lets a developer map/link different parts of images with the different web pages. It can be achieved by the <map> tag in HTML5, using which we can link images with clickable areas.

    Semantic elements are those which describe the particular meaning to the browser and the developer. Elements like <form>, <table>, <article>, <figure>, etc., are semantic elements

    S.no., Language, Mostly used for

    1, HTML, FrontEnd

    2, CSS, FrontEnd

    3, Python, BackEnd

    <progress> tag should be used when we want to show the completion progress of a task, whereas if we just want a scalar measurement within a known range or fraction value. Also, we can specify multiple extra attributes for <meter> tags like ‘form’, ‘low’, ‘high’, ‘min’, etc

    Yes, in HTML5 we can drag and drop an element. This can be achieved using the drag and drop-related events to be used with the element which we want to drag and drop

    SVG Canvas
    SVG is a vector based i.e., composed of shapes.  It is Raster based i.e., composed of pixels.
    SVG works better with a larger surface. Canvas works better with a smaller surface.
    SVG can be modified using CSS and scripts. Canvas can only be modified using scripts.
    SVG is highly scalable. So we can print at
    high quality with high resolution.
    It is less scalable.

    HTML5 supports the following three types of audio file formats:

    1. Mp3
    2. WAV
    3. Ogg

    These were the target area of the HTML5 specs:

    • Introduction of new element tags to better structure the web page such as <header> tag.
    • Forming a standard in cross-browser behavior and support for different devices and platforms
    • Backward compatible with the older version HTML web pages
    • Introduction of basic interactive elements without the dependency of plugins such as <video> tag instead of the flash plugin.

    This web storage helps in storing some of the static data in the local storage of the browser so that we do not need to fetch it from the server every time we need it. There is a size limit based on different browsers. This helps in decreasing the load time and a smooth user experience. There are two types of web storage that are used to store data locally in HTML5:

    • Local Storage - This helps in storing data that will be retained even though the user reopens the browser. It is stored for each webapp on different browsers.
    • Session Storage - This is used for one session only. After the user closes the browser this gets deleted.

    It is used to help extract data for site crawlers and search engines. It is basically a group of name-value pairs. The groups are called items, and each name-value pair is a property. Most of the search engines like Google, Microsoft, Yandex, etc follow schema.org vocabulary to extract this microdata.

    • itemid – The unique, global identifier of an item.
    • itemprop – Used to add properties to an item.
    • itemref – Provides a list of element ids with additional properties.
    • itemscope – It defines the scope of the itemtype associated with it.
    • itemtype – Specifies the URL of the vocabulary that will be used to define itemprop.

    The above example will be parsed by Google as

    The <output> tag is used for representing the result of a calculation. It has the following attributes:

    • for - It defines the relationship between the elements used in calculation and result.
    • form - This is used to define the form the output element belongs to.
    • name - The name of the output element.

    The above example looks like

    As HTML5 was all about better semantics and arrangements of the tags and elements, the <header> tag specifies the header section of the webpage. Unlike in previous version there was one <h1> element for the entire webpage, now this is the header for one section such as <article> or <section>. According to the HTML5 specification, each <header> element must at least have one <h1> tag.

    HTML5 supports two kinds of graphics:

    • Canvas - It is like drawing on a whitepaper or a blank webpage. We can add different graphic designs on web pages with available methods for drawing various geometrical shapes.
    • SVG - Scalable Vector Graphics are used mostly for diagrams or icons. It follows the XML format.

    Both of the above examples produce this output and represent two different approaches provided by HTML5 to implement graphical aspects in the webpage.