HTML Basics:
What is HTML?
Answer: HTML stands for HyperText Markup Language. It is the standard markup language for creating web pages.
What are the main building blocks of HTML?
Answer: The main building blocks of HTML are tags.
What is an HTML tag?
Answer: An HTML tag is a set of characters that define a specific element in an HTML document. Tags are used to structure content and create elements on a web page.
What is the basic structure of an HTML document?
Answer:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> Content of the document...... </body> </html>
What is the purpose of the <!DOCTYPE> declaration?
Answer: The
<!DOCTYPE>
declaration specifies the HTML version being used and helps browsers to render the page correctly.
HTML Tags and Elements:
Explain the difference between block-level and inline elements.
- Answer: Block-level elements start on a new line and take up the full width available, while inline elements only take up as much width as necessary and do not start on a new line.
What is the <div> tag used for?
- Answer: The
<div>
tag is a container that is used to group other HTML elements and apply styles or scripts to them collectively.
- Answer: The
What is the <span> tag used for?
- Answer: The
<span>
tag is an inline container used to group and apply styles to a specific section of text.
- Answer: The
Explain the purpose of the <a> tag.
- Answer: The
<a>
tag is used to create hyperlinks. It can link to other web pages, files, or locations within the same page.
- Answer: The
What is the purpose of the <img> tag?
- Answer: The
<img>
tag is used to embed images in an HTML document.
- Answer: The
HTML Attributes:
What is the role of the "alt" attribute in the <img> tag?
- Answer: The "alt" attribute provides alternative text for an image, which is displayed if the image cannot be loaded.
Explain the "href" attribute in the <a> tag.
- Answer: The "href" attribute in the
<a>
tag specifies the URL of the page the link goes to.
- Answer: The "href" attribute in the
What does the "src" attribute in the <script> tag do?
- Answer: The "src" attribute in the
<script>
tag specifies the source URL of the script.
- Answer: The "src" attribute in the
What is the purpose of the "colspan" attribute in a <td> tag?
- Answer: The "colspan" attribute in a
<td>
tag defines the number of columns a table cell should span.
- Answer: The "colspan" attribute in a
Explain the "placeholder" attribute in an <input> tag.
- Answer: The "placeholder" attribute in an
<input>
tag provides a hint to the user about the expected input.
- Answer: The "placeholder" attribute in an
HTML Forms:
How do you create a form in HTML?
- Answer: Use the
<form>
tag to create a form. Example:<form action="/submit" method="post"> <!-- Form elements go here --> </form>
- Answer: Use the
What is the purpose of the "action" attribute in the <form> tag?
- Answer: The "action" attribute in the
<form>
tag specifies the URL where the form data is submitted.
- Answer: The "action" attribute in the
Explain the difference between "GET" and "POST" methods in a form.
- Answer: "GET" is used to request data from a specified resource, while "POST" is used to submit data to be processed to a specified resource.
How do you create a text input field in a form?
- Answer: Use the
<input>
tag with the "type" attribute set to "text." Example:<input type="text" name="username">
- Answer: Use the
What is the purpose of the <label> tag in a form?
- Answer: The
<label>
tag is used to provide a user-readable description for an<input>
element.
- Answer: The
HTML5:
What is the significance of the HTML5 <header> and <footer> tags?
- Answer: The
<header>
tag represents a container for introductory content or a set of navigation links, while the<footer>
tag represents a container for footer content or links.
- Answer: The
What is the HTML5 <article> tag used for?
- Answer: The
<article>
tag is used to define a piece of independent, self-contained content.
- Answer: The
Explain the purpose of the HTML5 <section> tag.
- Answer: The
<section>
tag is used to define sections in a document, such as chapters, headers, footers, or any other sections.
- Answer: The
What is the <nav> tag in HTML5 used for?
- Answer: The
<nav>
tag is used to define a set of navigation links.
- Answer: The
What is the purpose of the HTML5 <canvas> tag?
- Answer: The
<canvas>
tag is used to draw graphics, animations, or other visual images on the fly using JavaScript.
- Answer: The
HTML Multimedia:
How do you embed a video in HTML?
- Answer: Use the
<video>
tag. Example:<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
- Answer: Use the
What is the purpose of the "controls" attribute in the <audio> or <video> tag?
- Answer: The "controls" attribute adds audio or video controls, such as play, pause, and volume.
How can you embed an external webpage within an HTML document?
- Answer: Use the
<iframe>
tag. Example:<iframe src="https://example.com" width="600" height="400"></iframe>
- Answer: Use the
Explain the purpose of the "alt" attribute in the <audio> tag.
- Answer: The "alt" attribute in the
<audio>
tag provides alternative text for browsers that do not support the audio element.
- Answer: The "alt" attribute in the
How do you embed an image map in HTML?
- Answer: Use the
<map>
and<area>
tags. Example:<img src="planets.jpg" usemap="#planetmap" alt="Planets"> <map name="planetmap"> <area shape="rect" coords="34,44,270,350" alt="Sun" href="sun.htm"> <!-- Other areas go here --> </map>
- Answer: Use the
HTML Semantics:
What is the purpose of semantic HTML?
- Answer: Semantic HTML provides meaning to the structure, making it clear to both the browser and the developer about the purpose of each element.
Explain the difference between <em> and <strong> tags.
- Answer: The
<em>
tag is used for emphasized text, while<strong>
is used for strongly emphasized text (often displayed as bold).
- Answer: The
What is the <mark> tag used for in HTML5?
- Answer: The
<mark>
tag is used to highlight parts of text in a document.
- Answer: The
What does the <time> tag represent in HTML5?
- Answer: The
<time>
tag represents a specific period in time or a range of time.
- Answer: The
How do you create a figure with a caption in HTML5?
- Answer: Use the
<figure>
and<figcaption>
tags. Example:<figure> <img src="image.jpg" alt="Description"> <figcaption>Caption goes here</figcaption> </figure>
- Answer: Use the
HTML Accessibility:
Why is it important to use semantic HTML for accessibility?
- Answer: Semantic HTML helps screen readers and other assistive technologies to better understand and interpret content, improving accessibility.
Explain the purpose of the "role" attribute in HTML.
- Answer: The "role" attribute is used to define the role of an element for accessibility purposes.
How can you make an HTML page more accessible to users with disabilities?
- Answer: Use appropriate semantic HTML, provide alternative text for images, use ARIA attributes, and ensure a logical tab order.
What is the purpose of the "aria-label" attribute?
- Answer: The "aria-label" attribute provides a label for an element when a visible label is not present.
How can you create a skip-to-content link for screen readers?
- Answer: Use an anchor link with a specific ID placed at the beginning of the document, and link to it from a hidden navigation link.
HTML5 APIs:
What is the Geolocation API in HTML5 used for?
- Answer: The Geolocation API is used to retrieve the geographical location of a user's device.
Explain the purpose of the Local Storage and Session Storage in HTML5.
- Answer: Local Storage and Session Storage are used to store key-value pairs on the client-side, persisting data between page reloads for Local Storage and during a session for Session Storage.
How do you use the Canvas API in HTML5 to draw shapes?
- Answer: Use the
<canvas>
tag and the JavaScript Canvas API to draw shapes and manipulate pixels.
- Answer: Use the
What is the purpose of the Web Storage API in HTML5?
- Answer: The Web Storage API provides a way to store key-value pairs locally on the client's browser.
How can you use the History API to manipulate the browser's history?
- Answer: The History API allows you to manipulate the browser's history, enabling dynamic updates to the URL and content without a full page reload.
HTML Best Practices:
Why is it recommended to use external CSS and JavaScript files rather than inline styles and scripts?
- Answer: External files can be cached, reducing page load times and promoting code reusability.
How can you optimize the loading time of a web page?
- Answer: Minimize HTTP requests, enable compression, use asynchronous loading for scripts, and optimize images.
Explain the importance of mobile responsiveness in web design.
- Answer: Mobile responsiveness ensures that a website is accessible and looks good on a variety of devices, improving the user experience.
What is the purpose of the "viewport" meta tag in HTML?
- Answer: The "viewport" meta tag controls the viewport's dimensions and scaling on mobile devices, helping to create a responsive layout.
How can you make a website more SEO-friendly using HTML?
- Answer: Use proper heading tags, add descriptive "alt" attributes to images, create a sitemap, and use semantic HTML to improve search engine rankings.