HTML Interview Questions and Answers
-
What is HTML?
- Answer: HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It's used to structure content such as headings, paragraphs, images, and links on a webpage.
-
What is the difference between HTML and XHTML?
- Answer: HTML is a markup language that allows for flexibility in syntax, while XHTML is an XML-based markup language that requires strict syntax rules, including properly closed tags and attributes enclosed in quotes.
-
Explain the purpose of the `
` declaration. - Answer: The `DOCTYPE` declaration tells the web browser which version of HTML the document uses, allowing the browser to render the page correctly using the appropriate rendering engine.
-
What are HTML elements?
- Answer: HTML elements are the fundamental building blocks of HTML documents. They are typically comprised of a start tag, content, and an end tag (e.g., ``). Some elements are self-closing (e.g., `
`).
- Answer: HTML elements are the fundamental building blocks of HTML documents. They are typically comprised of a start tag, content, and an end tag (e.g., ``). Some elements are self-closing (e.g., `
-
What are HTML attributes?
- Answer: HTML attributes provide additional information about HTML elements. They are placed inside the start tag and consist of a name-value pair (e.g., `Link` where `href` is the attribute).
-
Explain the difference between `
` and `` elements.- Answer: `` is a block-level element, meaning it takes up the full width available. `` is an inline element, meaning it only takes up as much width as its content requires.
What are semantic HTML elements? Give examples.
- Answer: Semantic HTML elements convey meaning about the content they contain, improving accessibility and SEO. Examples include: `
`, `
How do you create a hyperlink in HTML?
- Answer: Using the `` (anchor) element with the `href` attribute specifying the URL (e.g., `Link`).
How do you embed an image in HTML?
- Answer: Using the `
` element with the `src` attribute specifying the image path and the `alt` attribute providing alternative text (e.g., `
`).
Explain the purpose of the `alt` attribute in the `
` tag.
- Answer: The `alt` attribute provides alternative text for images, crucial for accessibility (screen readers) and SEO. It describes the image's content.
How do you create a list in HTML? Give examples of ordered and unordered lists.
- Answer: Unordered lists use `
- ` and `
- ` (list item) elements. Ordered lists use `
- ` and `
- ` elements. Example: `
- Item 1
- Item 2
- Item 1
- Item 2
- ` elements. Example: `
- ` (list item) elements. Ordered lists use `
-
What are the different heading levels in HTML?
- Answer: HTML offers six heading levels, from `
` (most important) to `
` (least important).
- Answer: HTML offers six heading levels, from `
-
How do you create a table in HTML?
- Answer: Using `
`, `
` (table row), ` ` (table header), and ` ` (table data) elements. What is the purpose of the `
- Answer: The `
What are some common form input types?
- Answer: `text`, `password`, `email`, `number`, `radio`, `checkbox`, `submit`, `file`, `date`, etc.
How do you create a comment in HTML?
- Answer: Using ``.
What is the difference between inline and block-level elements?
- Answer: Inline elements only take up as much width as necessary, while block-level elements take up the full width available.
What is the purpose of the `` tag?
- Answer: The `` tag provides metadata about the HTML document, such as character set, description, keywords, viewport settings, etc.
What is the role of the `` and `` sections of an HTML document?
- Answer: The `` contains metadata and information about the document (title, links to CSS, scripts, etc.), while the `` contains the visible content of the page.
Explain the concept of CSS and its relationship to HTML.
- Answer: CSS (Cascading Style Sheets) is used to style HTML elements, controlling their appearance (colors, fonts, layout, etc.). It separates presentation from content.
How do you link an external CSS stylesheet to an HTML document?
- Answer: Using the `` tag within the `` section (e.g., ``).
Explain the concept of inline, embedded, and external CSS.
- Answer: Inline CSS styles a single element directly within its HTML tag. Embedded CSS styles are placed within the `
- Answer: Using `
- Answer: `