HTML
HTML
1. What is HTML?
HTML (HyperText Markup Language) is the standard markup
language used to create web pages. It describes the structure of a web
page using elements and tags.
2. What are the differences between HTML and XHTML?
XHTML (eXtensible HyperText Markup Language) is a stricter,
XML-based version of HTML. It requires well-formed tags, proper
nesting, and all tags to be closed, including empty tags.
3. What is a doctype and why is it important?
A doctype declaration defines the version of HTML being used and
helps browsers render the content correctly. For example,
<!DOCTYPE html> declares HTML5.
4. Explain the structure of an HTML document.
An HTML document typically consists of:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
<body>
<!-- Content goes here -->
</body>
</html>
5. What are semantic HTML elements?
Semantic HTML elements clearly describe their meaning in a human-
and machine-readable way. Examples include <header>, <footer>,
<article>, and <section>.
6. How do you create a hyperlink in HTML?
Using the <a> tag:
<a href="https://www.example.com">Link Text</a>
7. What is the purpose of the alt attribute in an <img> tag?
The alt attribute provides alternative text for an image if it cannot be
displayed. It is also used by screen readers to describe the image for
visually impaired users.
8. What is the difference between block-level and inline
elements?
Block-level elements (e.g., <div>, <p>, <h1>) start on a new line and
take up the full width available. Inline elements (e.g., <span>, <a>,
<img>) do not start on a new line and only take up as much width as
necessary.
How can you include CSS in an HTML document?
Inline: <div style="color: red;">Text</div>
Internal:
<style> div { color: red; } </style>
External:
<link rel="stylesheet" href="styles.css">
9. What is the difference between <div> and <span>?
<div> is a block-level element used to group larger sections of
content. <span> is an inline element used to group small pieces of
content within a block.
10. What are HTML5 APIs? Can you name a few?
HTML5 introduced several new APIs for more complex web
applications:
Geolocation API: for accessing geographical location.
Web Storage API: for local and session storage.
Canvas API: for drawing graphics and animations.
Web Workers: for running scripts in background threads.
11. How do you embed a video in an HTML document?
Using the <video> tag:
html
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag. </video>
12. What is the purpose of the data-* attributes in
HTML5?
The data-* attributes allow you to store custom data on HTML
elements. These can be accessed via JavaScript for additional
functionality.
13. Explain the concept of HTML forms and form
elements.
HTML forms are used to collect user input. Form elements include
<input>, <textarea>, <select>, <button>, and <form> itself, which
groups them together.
14. How can you improve the accessibility of a web page
using HTML?
Use semantic HTML elements.
Provide alt text for images.
Use aria-* attributes to enhance accessibility for screen readers.
Ensure keyboard navigability by using the tabindex attribute and
proper focus management.