HTML Interview Questions and Answers for 5 years experience
-
What is HTML?
- Answer: HTML stands for HyperText Markup Language. It's the foundation of all web pages. It uses tags to structure content, such as headings, paragraphs, images, and links.
-
Explain the difference between HTML and XHTML.
- Answer: XHTML is an XML-compliant version of HTML. Key differences include stricter syntax (requiring well-formed XML), lowercase tag names, and mandatory closing tags for all elements. HTML is more flexible and forgiving.
-
What are semantic HTML5 elements? Give examples.
- Answer: Semantic HTML5 elements convey meaning to both the browser and developers. Examples include `
`, `
- Answer: Semantic HTML5 elements convey meaning to both the browser and developers. Examples include `
-
Explain the `DOCTYPE` declaration.
- Answer: The `DOCTYPE` declaration tells the browser which version of HTML the document is written in. It's crucial for proper rendering and compatibility.
-
What are HTML attributes? Give some common examples.
- Answer: HTML attributes provide additional information about HTML elements. Common examples include `id`, `class`, `src`, `href`, `alt`, `title`, `style`, and `lang`.
-
Describe the difference between `id` and `class` attributes.
- Answer: `id` attributes must be unique within a document, used for identifying a single element. `class` attributes can be used on multiple elements, allowing for styling and scripting using the same selector.
-
How do you create a hyperlink in HTML?
- Answer: Using the `` tag with the `href` attribute specifying the URL, e.g., `Example`
-
Explain the use of the `` tag and its important attributes.
- Answer: The `` tag embeds an image into the HTML document. Important attributes include `src` (image source), `alt` (alternative text for accessibility), `width`, and `height`.
-
What is the purpose of the `
- Answer: The `
-
Explain different input types in HTML forms.
- Answer: Common input types include `text`, `password`, `email`, `number`, `radio`, `checkbox`, `submit`, `button`, `file`, `date`, etc. Each defines the type of input expected from the user.
-
How do you create a table in HTML?
- Answer: Using the `
`, `
` (table row), ` ` (table data), and ` ` (table header) tags. What are lists in HTML and their types?
- Answer: Lists are used to organize items. Types include unordered lists (`
- `, `
- `), ordered lists (`
- `, `
- `), and definition lists (`
- `, `
- `, `
- `).
- `), and definition lists (`
- `), ordered lists (`
-
Explain the use of `
` and `` elements.- Answer: `` is a block-level element used for grouping and styling larger sections of content. `` is an inline element used for styling smaller portions of text within a line.
What is the difference between block-level and inline elements?
- Answer: Block-level elements always start on a new line and take up the full width available. Inline elements only take up as much width as necessary and flow within a line.
How do you embed CSS in HTML?
- Answer: Using the `
- Answer: `
- Answer: Using the `