HTML Interview Questions and Answers for freshers
-
What is HTML?
- Answer: HTML stands for HyperText Markup Language. It's the standard markup language for creating web pages and web applications. It uses tags to structure content, such as headings, paragraphs, images, and links.
-
What is the difference between HTML elements and tags?
- Answer: HTML elements are the building blocks of HTML pages. They consist of a start tag, some content, and an end tag (e.g., `
This is a paragraph.
`). Tags are the keywords enclosed in angle brackets (`<>`) that define HTML elements. The start tag marks the beginning of an element, and the end tag marks its end (indicated by a forward slash `/`).
- Answer: HTML elements are the building blocks of HTML pages. They consist of a start tag, some content, and an end tag (e.g., `
-
Explain the purpose of the `` declaration.
- Answer: The `` declaration tells the web browser which version of HTML is being used. It's crucial for proper rendering and ensures the browser interprets the code correctly according to the specified HTML standard (e.g., HTML5).
-
What are HTML attributes? Give examples.
- Answer: HTML attributes provide additional information about HTML elements. They are written inside the start tag and consist of a name-value pair (e.g., ``). Examples include `src` (for images), `href` (for links), `alt` (alternative text for images), `class`, and `id`.
-
What is the difference between `class` and `id` attributes?
- Answer: `id` attributes must be unique within an HTML document; they're used to identify a single element. `class` attributes can be used on multiple elements to apply the same styling or behavior. You use `id` for unique identification and `class` for grouping similar elements.
-
Explain the purpose of semantic HTML5 elements. Give examples.
- Answer: Semantic HTML5 elements provide meaning to the content they contain, improving accessibility and SEO. Instead of using generic elements like `` and ``, semantic elements like `
`, `
- Answer: Semantic HTML5 elements provide meaning to the content they contain, improving accessibility and SEO. Instead of using generic elements like `