XHTML Interview Questions and Answers
-
What is XHTML?
- Answer: XHTML (Extensible HyperText Markup Language) is a reformulation of HTML (HyperText Markup Language) as an XML application. It emphasizes stricter syntax rules compared to HTML, requiring well-formed XML documents with properly closed tags, lowercase tag names, and attribute values enclosed in quotes.
-
What is the difference between HTML and XHTML?
- Answer: XHTML is stricter than HTML. It requires well-formed XML syntax, including properly nested tags, lowercase tag names, and quoted attributes. HTML is more lenient, allowing for some syntax errors. XHTML is also more compatible with XML-based technologies.
-
What is the DTD in XHTML?
- Answer: The Document Type Definition (DTD) defines the structure and allowed elements of an XHTML document. It specifies the rules for which elements can be nested within others and which attributes are valid for each element. XHTML uses various DTDs, like XHTML 1.0 Strict, Transitional, and Frameset.
-
Explain XHTML 1.0 Strict, Transitional, and Frameset.
- Answer: These are three DTDs for XHTML 1.0. Strict is the most restrictive, allowing only elements conforming to the core XML specifications. Transitional allows some presentational elements from HTML 4.01, while Frameset supports the `
-
What are the advantages of using XHTML?
- Answer: Advantages include stricter validation leading to improved code quality and consistency, better compatibility with XML-based technologies, improved accessibility for users with disabilities, and easier data handling and manipulation.
-
What are the disadvantages of using XHTML?
- Answer: Disadvantages include stricter syntax requiring more attention to detail, potentially increased complexity in writing code, and reduced backward compatibility with older browsers that may not fully support XHTML.
-
How do you declare the DOCTYPE in XHTML?
- Answer: You declare the DOCTYPE at the beginning of the XHTML document, specifying the DTD used. For example, for XHTML 1.0 Strict: ``
-
What is the namespace in XHTML?
- Answer: A namespace is a way to avoid naming conflicts when using multiple XML vocabularies in a single document. In XHTML, the namespace declaration usually looks like this: `xmlns="http://www.w3.org/1999/xhtml"`. This clarifies that the document uses the XHTML vocabulary.
-
Explain the role of the root element in XHTML.
- Answer: The root element, ``, is the parent of all other elements in an XHTML document. It encapsulates the entire content of the page.
-
How do you create a link in XHTML?
- Answer: Using the `` tag with the `href` attribute specifying the URL. Example: `Example Link`
-
How do you embed an image in XHTML?
- Answer: Using the `` tag with the `src` attribute specifying the image path and the `alt` attribute providing alternative text. Example: ``
-
What is the purpose of the `` element in XHTML?
- Answer: The `` element contains meta-information about the HTML document, such as the title, character set, and links to external stylesheets and scripts.
-
What is the purpose of the `` element in XHTML?
- Answer: The `` element contains the visible page content, including text, images, and other elements that the user sees.
-
Explain the use of the `
` element.
- Answer: The `
` element represents a paragraph of text.
- Answer: The `
-
How do you create headings in XHTML?
- Answer: Using the `
` to `
` tags, with `
` representing the most important heading and `
` the least.
- Answer: Using the `
-
What is the purpose of the `
` and `` elements?- Answer: `` is a block-level element used for grouping content, while `` is an inline element used for styling or scripting a specific portion of text within a block.
How do you create a table in XHTML?
- Answer: Using the `
`, `
`, ` `, and ` ` elements. ` ` is the container, `
` defines rows, ` ` defines table data cells, and ` ` defines header cells. Explain the use of lists in XHTML (unordered, ordered, definition).
- Answer: Unordered lists (`
- `, `
- `) use bullet points, ordered lists (`
- `, `
- `) use numbers, and definition lists (`
- `, `
- `, `
- `) define terms and descriptions.
- `) use numbers, and definition lists (`
- `) use bullet points, ordered lists (`
-
How do you create a form in XHTML?
- Answer: Using the `
-
What are the different input types in XHTML forms?
- Answer: Common input types include `text`, `password`, `radio`, `checkbox`, `submit`, `button`, `file`, `image`, etc.
-
How do you add CSS to an XHTML document?
- Answer: Using the `` tag in the `` section to link to an external CSS file or using the `
- Answer: `