HTML interview questions
Here in this blog I am going to share HTML interview questions and answers. But, first of all I want to share some resources to learn HTML like W3school.com , html.com, javapoint.com, tutorialspont.com
And there are some videos like video by apna collage in hindi , code with harry in hindi, Supersimpledev in english , freecodecamp in english.
1. Are the HTML tags and elements the same thing?
Ans: HTML tags are used to hold the HTML element. HTML element holds the content. HTML attributes are used to describe the characteristic of an HTML element in detail. Whatever written within a HTML tag are HTML elements.
2. What are tags and attributes in HTML?
Ans: HTML tags are used to hold the HTML element. HTML element holds the content. HTML attributes are used to describe the characteristic of an HTML element in detail. HTML tag starts with < and ends with > Whatever written within a HTML tag are HTML elements
3. What are void elements in HTML?
Ans: A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes. The following is a complete list of the void elements in HTML : <br>, <hr>, <img>, <input>, <link>, <base>, <meta>, <param>, <area>, <embed>, <col>, <track>, <source>
4. What is the advantage of collapsing white space?
Ans: Collapsing white spaces decreases the transmission time between the server and the client because collapsing features remove unnecessary bytes that are occupied by the white spaces. By mistake, if you leave extra white space, the browser will ignore it and display the UI perfectly.
5. What are HTML Entities?
Ans: An HTML entity is a piece of text (“string”) that begins with an ampersand ( & ) and ends with a semicolon ( ; ). Entities are frequently used to display reserved characters (which would otherwise be interpreted as HTML code), and invisible characters (like non-breaking spaces). e.g – ® , © , € and etc.
6. What are different types of lists in HTML?
Ans: There are three types of lists in HTML: Unordered list or Bulleted list (ul), Ordered list or Numbered list (ol), Description list or Definition list (dl).
7. What is the ‘class’ attribute in HTML?
8.What is the difference between the ‘id’ attribute and the ‘class’ attribute of HTML elements?
Ans: The only difference between them is that “id” is unique in a page and can only apply to at most one element, while “class” selector can apply to multiple elements.
9. Define multipart form data?
Ans: The ENCTYPE attribute of <form> tag specifies the method of encoding for the form data. It is one of the two ways of encoding the HTML form. It is specifically used when file uploading is required in HTML form. It sends the form data to server in multiple parts because of large size of file.
10. Describe HTML layout structure.
Ans: An HTML layout is a blueprint used to arrange web pages in a well-defined manner. It is easy to navigate, simple to understand and uses HTML tags to customize web design elements. Crucial for any website, an HTML layout that uses the correct format will easily improve a website’s appearance.
II. How to optimize website assets loading?
Ans: Scripts should be placed at the bottom and style sheets at the top: It is beneficial to place style sheets in the head section of a website
12. What are the various formatting tags in HTML?
Ans: HTML Formatting is a process of formatting text for better look and feel. HTML provides us ability to format text without using CSS. There are many formatting tags in HTML. These tags are used to make text bold, italicized, or underlined. There are almost 14 options available that how text appears in HTML and XHTML. e.g – <b>, <strong> , <em> and etc.
13. What are the different kinds of Doctypes available ?
Ans: HTML5 doctype, Strict doctype (HTML 4.01), Strict and Transitional doctypes (XML 1.0), Frameset doctypes (HTML 4.01 and XML 1.0) and more…
14. Please explain how to indicate the character set being used by a document in HTML?
Ans: The character set being used by an HTML document is indicated using the charset attribute of a <meta> tag inside the <head> element of the HTML
16. What is the significance of <head> and <body >tag in HTML?
Ans: The <head> element is a container for metadata (data about data) and is placed between the <html> tag and the <body> tag. Metadata is data about the HTML document. Metadata is not displayed. Metadata typically define the document title, character set, styles, scripts, and other meta information.
17. Can we display a web page inside a web page or Is nesting of webpages possible?
Ans: When the content of one completely different webpage is embedded into another webpage, it is called a nested webpage. In simple words, a webpage that is inside another webpage of a completely different domain. In this article, we are going to learn how to create a nested webpage. It can be done through <iframe> , <embed> tags.
18. How is Cell Padding different from Cell Spacing?
Ans: Cellpadding basically defines the space present between a table cell’s border and the content present in it. Cellspacing basically defines the space present between individual adjacent cells.
19. How can we club two or more rows or columns into a single row or column in an HTML table?
Ans: It can be done by using the rowspan and colspan attribute in HTML. The rowspan is used to merge or combine the number of cells in a row whereas the colspan is used to merge column cells in a table. Example 1: In this example, we will merge two table row and make a single row.
20. Is it possible to change an inline element into a block level element?
Ans: You can change the visual presentation of an element using the CSS display property. For example, by changing the value of display from “inline” to “block” , you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa.
21. In how many ways can we position an HTML element? Or what are the permissible values of the position attribute?
Ans: The positioning of an element can be done using the top, right, bottom, and left properties. These specify the distance of an HTML element from the edge of the viewport. To set the position by these four properties, we have to declare the positioning method.
22. In how many ways you can display HTML elements?
Ans: There are three ways in which we can specify the styles for HTML elements:
- Inline: Here we use the ‘style’ attribute inside the HTML element.
- Internal: Here we use the <style> tag inside the <head> tag. …
- External: Here we use the <link> tag inside <head> tag to reference the CSS file into our HTML code.
23. What is the difference between “display: none” and “visibility: hidden”, when used as attributes to the HTML element ?
Ans: So, the difference between display: “none”; and visibility: “hidden”; right from the name itself we can tell the difference as display: “none”; completely gets rids of the tag, as it had never existed in the HTML page whereas visibility: “hidden”; just makes the tag invisible, it will still on the HTML page occupying
24. How to specify the link in HTML and explain the target attribute?
Ans: Links can be specified with the help of <a> tags. e.g – <a href=”https://thecyberblogs.com”>Click here </a>”
25. In how many ways can we specify the CSS styles for the HTML element?
Ans: CSS style can be added to HTML documents in 3 ways:
- Inline – by using the
styleattribute inside HTML elements
- Internal – by using a
<style>element in the
- External – by using a
<link>element to link to an external CSS file
26. Difference between link tag <link> and anchor tag <a>?
Ans: 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.
28. When to use scripts in the head and when to use scripts in the body?
29. What are forms and how to create forms in HTML?
Ans: HTML forms can be created using <form> tags in HTML , click here to know more.
30. How to handle events in HTML?