HTML Quick Interview Review
HTML Basics
- HTML (HyperText Markup Language) structures web content.
- Uses tags: <tagname>content</tagname>
- Example:
<!DOCTYPE html>
<html>
<head><title>Title</title></head>
<body><h1>Hello</h1></body>
</html>
Common Tags
<h1> to <h6> - Headings
<p> - Paragraph
<a href=""> - Link
<img src=""> - Image
<ul>, <ol>, <li> - Lists
<div> - Block container
<span> - Inline container
<br> - Line break
<form>, <input>, <label>, <button> - Form elements
Attributes
Used inside tags to add functionality:
- href, src, alt, id, class, style, title
Example: <img src="logo.png" alt="Logo" width="100">
Forms
<form action="/submit" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required />
<button type="submit">Submit</button>
</form>
- 'action' is the URL to send form data.
- 'method' is usually GET or POST.
- Use 'label' with 'for' matching input 'id' for accessibility.
Semantic HTML
Semantic elements provide meaning to content:
<header>, <nav>, <main>, <section>, <article>, <aside>, <footer>, <figure>, <figcaption>
- Helps with SEO and screen readers.
HTML Quick Interview Review
Block vs Inline Elements
Block Elements: Take full width (e.g., <div>, <p>, <h1>, <ul>)
Inline Elements: Stay in line with text (e.g., <span>, <a>, <img>)
Common Interview Questions
1. Difference between HTML and XHTML?
- XHTML is stricter and XML-based; HTML5 is more flexible.
2. What are void elements?
- Elements that do not have a closing tag (e.g., <img>, <br>, <input>).
3. What is the DOM?
- Document Object Model: browser's representation of the page structure.
4. What is the difference between id and class?
- 'id' is unique per page; 'class' can be reused for multiple elements.
5. What are some accessibility practices?
- Use semantic elements, <label> for inputs, 'alt' attributes on images, ARIA roles where needed.