HTML Interview Questions

  • 1
    What is HTML?

    HTML stands for Hyper Text Markup Language. It is a language of the World Wide Web. It is a standard text formatting language which is used to create and display pages on the Web. HTML makes the text more interactive and dynamic. It can turn text into images, tables, links. HTML pages are saved by adding .html or .html in web page name.

  • 2
    What are tags and attributes in HTML?

    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.

  • 3
    What are void elements in HTML?

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

  • 4
    What is the advantage of collapsing white space?

    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.

  • 5
    What is the ‘class’ attribute in HTML?

    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.

  • 6
    What is the difference between the ‘id’ attribute and the ‘class’ attribute of HTML elements?

    Multiple elements in HTML can have the same class value, whereas a value of id attribute of one element cannot be associated with another HTML element.

  • 7
    Define multipart form data?

    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.

  • 8
    What are the server-sent events in HTML5?

    The events pushed from the webserver to the browsers are called server-sent events. DOM elements can be continuously updated using these events. This has a major advantage over straight-up polling. In polling, there is a lot of overhead since every time it is establishing an HTTP connection and tearing it down whereas, in server-sent events, there is one long-lived HTTP connection. To use a server-sent event, <eventsource> element is used. The src attribute of this element specifies the URL from which sends a data stream having the events.

  • 9
    What is the Geolocation API in HTML5?

    Geolocation API is used to share the physical location of the client with websites. This helps in serving locale-based content and a unique experience to the user, based on their location. This works with a new property of the global navigator object and most of the modern browsers support this.

    var geolocation = navigator.geolocation;
    
  • 10
     How to support SVG in old browsers?

    To support old browsers instead of defining the resource of svg in src attribute of <img> tag, it should be defined in srcset attribute and in src the fallback png file should be defined.

    <img src="circle.png" alt="circle" srcset="circle.svg">
    
  • 11
     What are raster images and vector images?

    Raster Images - The raster image is defined by the arrangement of pixels in a grid with exactly what color the pixel should be. Few raster file formats include PNG(.png), JPEG(.jpg), etc.

    Vector Images - The vector image is defined using algorithms with shape and path definitions that can be used to render the image on-screen written in a similar markup fashion. The file extension is .svg

  • 12
    What is new about the relationship between the <header> and <h1> tags in HTML5?

    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.

  • 13
    Explain the concept of web storage in HTML5.

    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.
  • 14
    What are the significant goals of the HTML5 specification?

    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.
  • 15
    What type of audio files can be played using HTML5?

    HTML5 supports the following three types of audio file formats:

    1. Mp3
    2. WAV
    3. Ogg
  • 16
    Is drag and drop possible using HTML5 and how?

    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.

  • 17
    What is the difference between <meter> tag and <progress> tag?

    <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.

  • 18
    What are Semantic Elements?

    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.

  • 19
    What is the difference between <figure> tag and <img> tag?

    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.

  • 20
    How can we include audio or video in a webpage?

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

  • 21
    Difference between link tag <link> and anchor tag <a>?

    The anchor tag <a> is used to create a hyperlink to another webpage or to a certain part of the webpage and these links are clickable, whereas, link tag <link> defines a link between a document and an external resource and these are not clickable.

  • 22
    What is the difference between “display: none” and “visibility: hidden”, when used as attributes to the HTML element.

    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.

  • 23
    Is it possible to change an inline element into a block level element?

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

  • 24
    How can we club two or more rows or columns into a single row or column in an HTML table?

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

  • 25
    Can we display a web page inside a web page or Is nesting of webpages possible?

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

    <iframe src=”url of the web page to embed” />
    
  • 26
    How to create a Hyperlink in HTML?

    The HTML provides an anchor tag to create a hyperlink that links one page to another page. These tags can appear in any of the following ways:

    • Unvisited link – It is displayed, underlined and blue.
    • Visited link – It is displayed, underlined and purple.
    • Active link – It is displayed, underlined and red.

    The syntax of Hyperlink in HTML is:

    <a href = "..........."> Link Text </a>
    
  • 27
    What is semantic HTML?

    Semantic HTML is a coding style. It is the use of HTML markup to reinforce the semantics or meaning of the content. For example: In semantic HTML <b> </b> tag is not used for bold statement as well as <i> </i> tag is used for italic. Instead of these we use <strong></strong> and <em></em> tags.

  • 28
    What is an image map?

    An image map is used for linking many different web pages using a single image. It is represented by <map> tag. You can define shapes in images that you want to include as part of an image mapping.

  • 29
    Does a hyperlink only apply to text?

    No, hyperlinks can be used both on texts and images. The HTML anchor tag defines a hyperlink that links one page to another page. The “href” attribute is the most important attribute of the HTML anchor tag.

    Syntax:

    <a href = "..........."> Link Text </a>
    
  • 30
    What is a Style Sheet?

    A style sheet is used to build a consistent, transportable, and well-designed style template. You can add these templates on several different web pages. It describes the look and formatting of a document written in the markup language.

  • 31
     What is the purpose of using alternative texts in images?

    The purpose of using alternative texts is to define what the image is about. During an image mapping, it can be confusing and difficult to understand what hotspots correspond to a particular link. These alternative texts come in action here and put a description at each link which makes it easy for users to understand the hotspot links easily.

  • 32
     Is the <!DOCTYPE html> tag considered as a HTML tag?

    No, the <!DOCTYPE html> declaration is not an HTML tag.

    There are many type of HTML, such as, HTML 4.01 Strict, HTML 4.01 Transitional, HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1 etc. So, <!DOCTYPE html> is used to instruct the web browser about the HTML page.

  • 33
    Why is a URL encoded in HTML?

    An URL is encoded to convert non-ASCII characters into a format that can be used over the Internet because a URL is sent over the Internet by using the ASCII character-set only. If a URL contains characters outside the ASCII set, the URL has to be converted. The non-ASCII characters are replaced with a “%” followed by hexadecimal digits.

  • 34
    What are the entities in HTML?

    The HTML character entities are used as a replacement for reserved characters in HTML. You can also replace characters that are not present on your keyboard by entities. These characters are replaced because some characters are reserved in HTML.

  • 35
    Can you create a multi-colored text on a web page?

    Yes, we can create a multi-colored text on a web page. To create a multicolor text, you can use <font color =”color”> </font> for the specific texts that you want to color.

  • 36
    What is the use of a span tag? Explain with example.

    The span tag is used for following things:

    • For adding color on text
    • To add background on text
    • Highlight any color text

    Example:

    <span style="color:#ffffff;">
    In this page we use span.
    </span>
    
  • 37
     Is there any way to keep list elements straight in an HTML file?

    By using indents, you can keep the list elements straight. If you indent each sub nested list in further than the parent list, you can easily determine the various lists and the elements that it contains.

  • 38
    When is it appropriate to use frames?

    Frames can make navigating a site much easier. If the main links to the site are located in a frame that appears at the top or along the edge of the browser, the content for those links can be displayed in the remainder of the browser window

  • 39
    What happens if you open the external CSS file in a browser?

    When you try to open the external CSS file in a browser, the browser cannot open the file, because the file has a different extension. The only way to use an external CSS file is to reference it using <link/> tag within another HTML document.

  • 40
    What is the hierarchy that is being followed when it comes to style sheets?

    If a single selector includes three different style definitions, the definition that is closest to the actual tag takes precedence. Inline style takes priority over embedded style sheets, which takes priority over external style sheets.

  • 41
    How do you create text on a webpage that allows you to send an email when clicked?

    To change the text into a clickable link to send an email, you need to use the mailto command within the href tag. You can write it in the following way:

    <a href=”mailto:youremailaddress”>text to be clicked</a>
    
  • 42
    How are active links different from normal links?

    The default color for normal and active links is blue. Some browsers recognize an active link when the mouse cursor is placed over that link. Whereas, others recognize active links when the link has the focus. Those that don’t have a mouse cursor over that link is considered a normal link.

  • 43
    What is button tag?

    The button tag is used in HTML 5. It is used to create a clickable button within the HTML form on the web page. This tag creates a “submit” or “reset” button. The button tag code is as follows:

    <button name="button" type="button">Click Here</button>
    
  • 44
    What are the limits of the text field size?

    The default size for a text field is around 13 characters. However, if you include the size attribute, you can set the size value to be as low as 1. The maximum size value will be determined by the browser width. Also, if the size attribute is set to 0, the size will be set to the default size of 13 characters.

  • 45
    What happens if there is no text between the tags? Does this affect the display of the HTML file?

    If there is no text present between the tags, there is nothing to format. Therefore, no formatting will appear. Some tags, such as the tags without a closing tag like the <img> tag, do not require any text between them.

  • 46
    What is the advantage of grouping several checkboxes together?

    The checkboxes don’t affect one another. But, grouping these checkboxes together help to organize them. Checkbox buttons can have their name and do not need to belong to a group. A single web page can have many different groups of checkboxes.

  • 47
    Are there instances where the text will appear outside of the browser?

    By default, the text is wrapped to appear within the browser window. However, if the text is part of a table cell with a defined width, the text could extend beyond the browser window.

  • 48
    What are the different tags to separate sections of text?

    The <br> tag is one way to separate the lines of text. There are other tags like the <p> tag and <blockquote> tag that are also used to separate sections of text.

  • 49
     What are HTML Attributes?

    Attributes are the properties that can be added to an HTML tag. These attributes change the way the tag behaves or is displayed. For example, a <img> tag has an src attribute, which you use to add the source from which the image should be displayed.

    We add attributes right after the name of the HTML tag, inside the brackets. We can only add the attributes to opening or self-closing tags, but never be in closing tags.

  • 50
    What is a marquee in HTML?

    Marquee is used for scrolling text on a web page. It scrolls the image or text up, down, left, or right automatically. To apply for a marquee, you have to use </marquee> tags.