HereтАЩs a collection of common interview questions and answers based on HTML. This should help you prepare effectively.
Basic HTML Questions
- What does HTML stand for?
- Answer: HTML stands for HyperText Markup Language. It is the standard language used to create and design web pages.
- What is the purpose of HTML?
- Answer: HTML is used to structure content on the web. It allows developers to create links, embed images, and format text.
- What are HTML tags?
- Answer: HTML tags are the building blocks of HTML. They define elements on a page, typically consisting of an opening tag, content, and a closing tag (e.g.,
<tagname>Content</tagname>
).
- Answer: HTML tags are the building blocks of HTML. They define elements on a page, typically consisting of an opening tag, content, and a closing tag (e.g.,
- Explain the structure of a basic HTML document.
- Answer: A basic HTML document includes:
<!DOCTYPE html> <html> <head> <title>Document Title</title> </head> <body> <h1>Hello World</h1> <p>This is a paragraph.</p> </body> </html>
- Answer: A basic HTML document includes:
- What is the difference between
<div>
and<span>
?- Answer:
<div>
is a block-level element that is used to create sections on a page, while<span>
is an inline element used for styling a small section of text within a block.
- Answer:
Intermediate HTML Questions
- What are semantic HTML elements?
- Answer: Semantic HTML elements clearly describe their meaning to both the browser and the developer, such as
<header>
,<footer>
,<article>
, and<section>
.
- Answer: Semantic HTML elements clearly describe their meaning to both the browser and the developer, such as
- How can you create a hyperlink in HTML?
- Answer: A hyperlink is created using the┬а
<a>
┬аtag. For example:<a href="https://www.example.com">Visit Example</a>
- Answer: A hyperlink is created using the┬а
- What is the purpose of the
alt
attribute in images?- Answer: The
alt
attribute provides an alternative text description of an image, which is important for accessibility and when the image cannot be displayed.
- Answer: The
- What is a form in HTML?
- Answer: A form is an HTML element used to collect user input. It typically includes controls like text fields, radio buttons, checkboxes, and submit buttons.
- How do you create a list in HTML?
- Answer: You can create ordered and unordered lists using┬а
<ol>
┬аand┬а<ul>
┬аtags, respectively:<ul> <li>Item 1</li> <li>Item 2</li> </ul>
- Answer: You can create ordered and unordered lists using┬а
Advanced HTML Questions
- What are HTML entities?
- Answer: HTML entities are special characters that are not easily typed on a keyboard. They are represented by
&
followed by the entity name or number, e.g.,
for a non-breaking space.
- Answer: HTML entities are special characters that are not easily typed on a keyboard. They are represented by
- What is the role of the
<head>
tag?- Answer: The
<head>
tag contains meta-information about the HTML document, such as the title, character set, linked stylesheets, and scripts.
- Answer: The
- How can you embed a video in HTML?
- Answer: You can embed a video using the┬а
<video>
┬аtag:<video width="320" height="240" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
- Answer: You can embed a video using the┬а
- What are data attributes in HTML?
- Answer: Data attributes are custom attributes that allow you to store extra information on standard, semantic HTML elements using the
data-
prefix, e.g.,<div data-id="123">
.
- Answer: Data attributes are custom attributes that allow you to store extra information on standard, semantic HTML elements using the
- Explain 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, while inline elements (e.g.,<span>
,<a>
) do not start on a new line and only take up as much width as necessary.
- Answer: Block-level elements (e.g.,
Practice More Questions
Here are some more HTML-related questions you might encounter in interviews:
- What is the role of the
<meta>
tag? - How can you create an HTML table?
- Explain how the
<iframe>
tag is used. - What is the purpose of the
<link>
tag? - How do you ensure your HTML is accessible?
More HTML Questions
- What is the purpose of the
<link>
tag?- Answer: The┬а
<link>
┬аtag is used to link external resources, such as stylesheets, with the HTML document. It is typically placed inside the┬а<head>
┬аsection:<link rel="stylesheet" href="styles.css">
- Answer: The┬а
- How do you create an HTML table?
- Answer: You can create a table using the┬а
<table>
,┬а<tr>
┬а(table row),┬а<th>
┬а(table header), and┬а<td>
┬а(table data) tags. HereтАЩs a simple example:<table> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>John</td> <td>25</td> </tr> <tr> <td>Jane</td> <td>30</td> </tr> </table>
- Answer: You can create a table using the┬а
- Explain how the
<iframe>
tag is used.- Answer: The┬а
<iframe>
┬аtag creates an inline frame that embeds another document within the current HTML document. It is often used to embed videos or other web pages:<iframe src="https://www.example.com" width="600" height="400"></iframe>
- Answer: The┬а
- What is the difference between the
<script>
tag’ssrc
attribute and inline JavaScript?- Answer: The┬а
src
┬аattribute in the┬а<script>
┬аtag specifies an external JavaScript file, while inline JavaScript is written directly between the opening and closing┬а<script>
┬аtags. For example:<script src="script.js"></script>
vs.html<script> console.log('Hello, world!'); </script>
- Answer: The┬а
- How do you ensure your HTML is accessible?
- Answer: To make HTML accessible, use semantic elements, provide text alternatives (like
alt
attributes for images), ensure proper heading structure, use ARIA roles when necessary, and ensure that all interactive elements are keyboard navigable.
- Answer: To make HTML accessible, use semantic elements, provide text alternatives (like
- What are progressive enhancement and graceful degradation in web development?
- Answer: Progressive enhancement is a strategy for web development that focuses on making sure everyone can access the basic content of a web page, while additional features are layered on for users with more advanced capabilities. Graceful degradation, on the other hand, starts with a fully featured application and ensures that it still works on older browsers or devices by providing fallbacks.
- What is the
<noscript>
tag used for?- Answer: The
<noscript>
tag is used to provide alternative content for users whose browsers do not support JavaScript or have it disabled. It can contain HTML code that will be displayed only if JavaScript is not available.
- Answer: The
- What is the difference between
GET
andPOST
methods in HTML forms?- Answer: The
GET
method sends data appended to the URL, making it visible in the browser’s address bar, and is typically used for retrieving data. ThePOST
method sends data in the body of the HTTP request, making it more secure for transmitting sensitive information and is often used for submitting data.
- Answer: The
- How do you include comments in HTML?
- Answer: Comments in HTML are added using the
<!-- Comment -->
syntax. Comments are not displayed in the browser.html<!-- This is a comment -->
- Answer: Comments in HTML are added using the
- What are the new input types introduced in HTML5?
- Answer: HTML5 introduced several new input types that improve form functionality and usability, including┬а
email
,┬аurl
,┬аdate
,┬аnumber
,┬аrange
,┬аcolor
, and others. For example:<input type="email" placeholder="Enter your email">
- Answer: HTML5 introduced several new input types that improve form functionality and usability, including┬а
Further Practice Questions
Here are additional HTML-related questions to consider:
- What is the difference between HTML and XHTML?
- What does the
<meta charset="UTF-8">
tag do? - How can you control the layout of a webpage using HTML?
- Describe the
<style>
tag and its purpose. - Explain how to use the
<canvas>
element in HTML5.