HTML CSS
HTML CSS
1. What is HTML?
Answer:
HTML (HyperText Markup Language) is the standard markup language for
creating web pages. It defines the structure of a webpage using elements (tags)
that browsers render into visible or functional content.
2. What are HTML tags and elements?
Answer:
• HTML Tags: Keywords enclosed in angle brackets (< >), e.g., <p>, <div>.
• HTML Elements: Tags + content + closing tag (if required), e.g., <p>Hello
World</p>.
3. What is the basic structure of an HTML document?
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
</body>
</html>
4. What is the <!DOCTYPE html> declaration?
Answer:
It tells the browser that the document is an HTML5 document. It must be the
first line in an HTML file.
5. What are void elements in HTML?
Answer:
Void elements (self-closing tags) do not require a closing tag,
e.g., <br>, <img>, <hr>, <input>.
6. What is the difference between <div> and <span>?
Answer:
• <div> is a block-level element (takes full width, starts on a new line).
• <span> is an inline element (takes only necessary width, stays in line
with text).
7. What are semantic HTML elements?
Answer:
Semantic elements clearly describe their meaning to browsers and developers,
e.g.:
• <header>, <footer>, <article>, <section>, <nav>, <aside>.
8. What is the difference between <strong> and <b>?
Answer:
• <strong> indicates strong importance (semantic, used for screen
readers).
• <b> simply makes text bold (visual styling only).
9. What is the difference between <em> and <i>?
Answer:
• <em> indicates emphasis (semantic, screen readers stress it).
• <i> is for italic styling (visual only, e.g., icons, foreign words).
10. What is the purpose of the <meta> tag?
Answer:
It provides metadata about the HTML document, such as:
• Character encoding (<meta charset="UTF-8">)
• Viewport settings (<meta name="viewport" content="width=device-
width, initial-scale=1.0">)
• SEO descriptions (<meta name="description" content="...">)
11. What is the difference between id and class attributes?
Answer:
• id is unique (only one per page, used for JavaScript targeting).
• class can be reused (multiple elements can have the same class).
12. What is the purpose of the <iframe> tag?
Answer:
It embeds another HTML page within the current page, e.g., for videos, maps,
or ads.
<iframe src="https://example.com" width="500" height="300"></iframe>
Run HTML
13. What are HTML forms and their common elements?
Answer:
Forms collect user input. Common elements:
<form action="/submit" method="POST">
<input type="text" placeholder="Name">
<input type="email" required>
<input type="password">
<input type="checkbox">
<input type="radio">
<select><option>Option 1</option></select>
<textarea></textarea>
<button type="submit">Submit</button>
</form>
14. What is the difference between GET and POST methods in forms?
Answer:
GET POST
localStorage sessionStorage
<input list="browsers">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
</datalist>
<video controls>
<source src="movie.mp4" type="video/mp4">
Your browser doesn't support HTML5 video.
</video>
34. What is the difference between <canvas> and <svg>?
Answer:
Canvas SVG
// worker.js
onmessage = (e) => postMessage('Worker received: ' + e.data);
36. What is Geolocation API in HTML5?
Answer:
Gets user's geographical location:
navigator.geolocation.getCurrentPosition(
(position) => console.log(position.coords),
(error) => console.error(error)
);
37. What is the Drag and Drop API?
Answer:
Native HTML5 feature for drag-and-drop interactions:
<script>
document.getElementById('dragme').addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text', e.target.id);
});
</script>
localStorage.setItem('key', 'value');
const data = localStorage.getItem('key');
39. What is the difference between cookies and Web Storage?
Answer:
<picture>
<source media="(min-width: 800px)" srcset="large.jpg">
<source media="(min-width: 400px)" srcset="medium.jpg">
<img src="small.jpg" alt="Fallback">
</picture>
50. How do you optimize a website for SEO using HTML?
Answer:
Key techniques:
• Semantic HTML5 tags
• Proper <title> and <meta> descriptions
• <h1> to <h6> hierarchy
• alt text for images
• Mobile-friendly viewport
• Schema markup
• Clean URL structure
<meta name="description" content="Page description for SEO">
<meta name="keywords" content="HTML, CSS, JavaScript">
CSS Interview Questions
1. What is CSS?
Answer:
CSS (Cascading Style Sheets) is a style sheet language used to describe the
presentation of HTML documents — including layout, colors, and fonts.
10. What is the difference between visibility: hidden and display: none?
Answer:
• visibility: hidden: Element is invisible but occupies space
• display: none: Element is removed from layout