1. What is HTML?
HTML stands for HyperText Markup Language. It is the standard language used to create and design web pages. HTML structures the content on the web by using elements and tags to define headings, paragraphs, links, images, and other content.
2. What are the basic components of an HTML document?
An HTML document typically includes:
- <!DOCTYPE html>: Declaration defining the document type and HTML version.
- <html>: Root element containing the entire document.
- <head>: Contains meta-information, links to stylesheets, and other resources.
- <title>: Specifies the title of the document (shown in the browser tab).
- <body>: Contains the content of the document like headings, paragraphs, images, and links.
3. What is the difference between <div> and <span> tags?
- <div>: A block-level element that is used to group and structure content on the page. It typically starts on a new line and takes up the full width available.
- <span>: An inline element used to style a portion of text or group inline elements together. It does not start on a new line and only takes up as much width as necessary.
4. How do you create a hyperlink in HTML?
To create a hyperlink, you use the <a> tag with the href attribute specifying the URL of the link. For example:
5. 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. This improves accessibility for users with screen readers and helps with SEO. For example:
6. What is the difference between id and class attributes in HTML?
- id: Used to uniquely identify a single element on a page. IDs should be unique within a document and are referenced with a # in CSS and JavaScript.
- class: Used to apply the same style to multiple elements. Classes are not unique and can be reused on multiple elements. They are referenced with a . in CSS.
7. How do you embed a video in an HTML page?
You can embed a video using the <video> tag. For example:
<video> width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
The controls attribute adds video playback controls.
8. What are semantic HTML elements? Give examples.
Semantic HTML elements clearly describe their meaning in a human- and machine-readable way. Examples include:
- <header>: Defines a header section.
- <footer>: Defines a footer section.
- <article>: Defines an independent, self-contained piece of content.
- <section>: Defines a section of content.
- <nav>: Defines navigation links.
9. What is the purpose of the <!DOCTYPE html> declaration?
The <!DOCTYPE html> declaration defines the document type and version of HTML being used. It ensures that browsers render the page in standards mode, which helps to avoid inconsistencies in how the page is displayed.
10. How do you include an external CSS file in an HTML document?
You include an external CSS file using the <link> tag within the <head> section of your HTML document. For example:
These answers should cover a broad range of basic HTML concepts that are often tested in interviews. If you need more specific or advanced topics, feel free to ask!