0% found this document useful (0 votes)
2 views6 pages

HTML Interview Questions and Answer

The document provides a comprehensive list of HTML interview questions and answers, covering basic and advanced topics. Key concepts include HTML structure, elements, attributes, and differences between various tags. It also discusses semantic HTML, forms, and multimedia elements, making it a valuable resource for those preparing for HTML-related interviews.

Uploaded by

SRDC CDE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

HTML Interview Questions and Answer

The document provides a comprehensive list of HTML interview questions and answers, covering basic and advanced topics. Key concepts include HTML structure, elements, attributes, and differences between various tags. It also discusses semantic HTML, forms, and multimedia elements, making it a valuable resource for those preparing for HTML-related interviews.

Uploaded by

SRDC CDE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

HTML Interview Questions and Answers

Basic Questions
1. What is HTML?

Answer: HTML stands for Hyper Text Markup Language. It is the standard language for creating web
pages and web applications, describing the structure of a web page.

2. What are HTML Elements?

Answer: HTML Elements are the building blocks of HTML that describe the structure and content of a
web page. They generally consist of a start tag, content, and end tag.

3. What is the difference between HTML and HTML5?

Answer: HTML5 is the latest version of HTML, introducing new elements (e.g., <header>, <footer>,
<article>, <section>), attributes, and APIs (e.g., local storage, geolocation).

4. What is the structure of an HTML document?

Answer: The HTML head element consists of HTML elements that define the metadata of an HTML
document and the HTML body element consists of the content that should be displayed on the web
page.

5. What is a DOCTYPE, and why is it important?

Answer: DOCTYPE is a declaration at the beginning of an HTML document specifying the HTML version.
It helps browsers render the page correctly. For HTML5, it is <!DOCTYPE html>.

6. What are semantic HTML elements?

Answer: Semantic HTML elements clearly describe their meaning in a human- and machine-readable
way. Examples include <article>, <section>, <aside>, and <footer>.

7. What is the difference between block-level and inline elements?

Answer: Block-level elements (e.g., <div>, <p>) start on a new line and take up the full width available.
Inline elements (e.g., <span>, <a>) do not start on a new line and only take up as much width as
necessary.

8. What is an attribute in HTML?

Answer: Attributes provide additional information about HTML elements, specified within the opening
tag. Examples include href in <a>, src in <img>, and class in most tags.

9. What is the use of the <meta> tag?

Answer: <meta> tags provide metadata about the HTML document, such as character set, author,
description, and viewport settings for responsive design.
10. What is nested HTML?

Answer: HTML elements can be nested. It means that the HTML element can be placed inside another
HTML element.

11. What is the purpose of the <form> tag?

Answer: The <form> tag is used to create an HTML form for user input, containing elements like
<input>, <textarea>, <button>, and <select>.

12. What is the use of an HTML anchor element?

Answer: We use the HTML anchor elements to navigate to other web resources or a specific HTML
element within the HTML document. They are also called as Hyperlinks/ Links.

13. What are the differences between HTML div and span elements?

Answer: The HTML div element is a block-level element. It can be used to wrap around other HTML
elements and apply CSS styles to many elements at once. The HTML span element is an inline element. It
can be used to wrap a small portion of text, etc and add CSS styles to it.

14. What is the purpose of the action attribute in a form?

Answer: The action attribute specifies the URL where the form data should be sent when the form is
submitted.

15. What is an HTML container element?

Answer: The HTML container element (div) defines a container. It can be used to wrap a group of
elements and apply CSS styles to many elements at once.

16. How do you create a hyperlink in HTML?

Answer: A hyperlink is created using the <a> tag with the href attribute specifying the URL. Example:
<a href="https://example.com">Link Text</a>.

17. What is the difference between id and class attributes?

Answer: id is a unique identifier for an element, used for styling and scripting, while class is a way to
group elements for styling.

18. What is the purpose of the alt attribute in images?

Answer: The alt attribute provides alternative text for an image if it cannot be displayed, improving
accessibility and SEO.

19. What is an HTML script element?

Answer: The HTML script element can be used to embed the JavaScript code. It can contain scripting
statements, or it points to an external script file through the src attribute.
20. How to add line breaks to an HTML paragraph element?

Answer: The HTML br element is used to add a line break to an HTML paragraph element. It breaks the
text and continue it in the next line. It is useful in writing poems, addresses, etc.

21. How to display images on the web page?

Answer: We can display images on the web page using the HTML img element. Generally, the HTML img
element requires two main HTML attributes. src specifies the path to the image. alt specifies an
alternate text for the image.

22. What is the difference between HTML anchor element and HTML link element?

Answer: HTML anchor element: We use the HTML anchor element to navigate to other web resources
or a specific element within the HTML document.

HTML link element:We use the HTML link element to link the HTML and CSS files.

23. Explain the HTML hr (horizontal line) element?

Answer: HTML Horizontal Rule Element: The HTML hr element inserts a horizontal line and helps to
separate the content.

24. What is meant by the HTML href attribute?

Answer: The HTML href attribute is the most important attribute of the HTML anchor element. It
specifies the URL/path of the page the link goes to

25. Can multiple HTML elements have the same id?

Answer: No. There shouldn't be more than one HTML element with the same id. The id must be unique
within the HTML document.
Advanced Questions

1. What is the purpose of the data-* attributes?

Answer: The data-* attributes are used to store custom data private to the page or application.
Example: <div data-user-id="12345">.

2. How can you make a list in HTML?

Answer: Ordered lists are created with <ol> and <li> for list items, and unordered lists with <ul> and
<li>.

3. What is the difference between <iframe> and <embed>?

Answer: <iframe> embeds another HTML page within the current page, while <embed> is used for
embedding external content like multimedia (e.g., videos).

4. What are self-closing tags?

Answer: Self-closing tags do not have a closing tag and end with />. Examples include <img />,
<input />, <br />, <hr />.

5. What is the <canvas> element in HTML5?

Answer: <canvas> is used to draw graphics on the fly via JavaScript, allowing for dynamic, scriptable
rendering of 2D shapes and images.

6. What is the purpose of the viewport meta tag?

Answer: The viewport meta tag controls the layout on mobile browsers. Example: <meta
name="viewport" content="width=device-width, initial-scale=1.0">.

7. What is an HTML style element?

Answer: The HTML style element contains style information for an HTML document, or part of an HTML
document. It contains CSS, which is applied to the contents of the HTML document.

8. What are custom data attributes in HTML5?

Answer: Custom data attributes (data-*) allow embedding custom data attributes on all HTML
elements. They are used to store extra information that doesn’t have any visual representation.

9. What is the srcset attribute in the <img> tag?

Answer: The srcset attribute provides a set of images with different resolutions, allowing the browser
to choose the best image for the current viewport and display density.
10. How do you create a responsive image in HTML?

Answer: Use the srcset attribute and the <picture> element with different <source> tags for
different screen sizes.

11. What is the purpose of the rel attribute in the <link> tag?

Answer: The rel attribute specifies the relationship between the current document and the linked
resource. Common values are stylesheet and icon.

12. How do you create an HTML comment?

Answer: HTML comments are created using <!-- Comment text -->.

13. What is the lang attribute in the <html> tag?

Answer: The lang attribute specifies the language of the document, which helps search engines and
browsers. Example: <html lang="en">.

14. How do you create a favicon in HTML?

Answer: A favicon is created using the <link rel="icon" href="favicon.ico"


type="image/x-icon"> tag in the <head> section.

15. What are microdata in HTML5?

Answer: Microdata is a way to embed metadata within existing content on web pages, using the
itemscope, itemtype, and itemprop attributes.

16. What is the purpose of the draggable attribute?

Answer: The draggable attribute specifies whether an element is draggable. Example: <div
draggable="true">Drag me!</div>.

17. What is the difference between the nav and aside tags?

Answer: The <nav> tag defines a section for navigation links, while the <aside> tag defines content
aside from the main content (e.g., sidebars).

18. How can you define a multi-column layout in HTML5?

Answer: Multi-column layouts can be defined using CSS3, specifically the column-count and column-
gap properties.

19. What is HTML video element?

Answer: The HTML video element represents a video. It is used to play audio files with captions, videos or
movies.

Tag: <video> <source src="movie.mp4" type="video/mp4" /></video>


20. How to set controls in HTML video element?

Answer: The HTML controls attribute is used to set controls in HTML video element. It is a boolean
attribute. When this attribute is present, it specifies that video controls should be displayed. Video
controls include: Play, Pause, Seeking, Volume, Fullscreen toggle, Captions/Subtitles (when available),
Track (when available)

21. What is an HTML picture element?

Answer: The HTML picture element is a container to provide multiple alternative sources for the HTML
img element. It is useful in different display/device scenarios. It can contain zero or more source
elements and one HTML img element.

22. What are HTML non-semantic elements?

Answer: The HTML non-semantic elements don't have any meaning. Examples: div and span. We
cannot exactly find out the type of content within the given element unlike semantic elements like h1, p,
etc.

23. What are Global attributes?

Answer: Global attributes are attributes common to all HTML elements. They can be used on all
elements, though they may not affect some elements. Examples: class, id, title, etc.

24. What are HTML selected and multiple attributes?

Answer: Selected Attribute is a boolean attribute. It specifies that an option should be pre-selected
when the page loads. Multiple Attribute is a boolean attribute. It specifies whether the user is allowed
to provide more than one value in an input field. It can be used in the HTML select element.

25. What is an HTML required attribute?

Answer: The HTML required attribute is a boolean attribute. If present, it specifies that an input field
must be filled out before submitting the form.

Example:

<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required />
<input type="submit" />
</form>

You might also like