The best HTML interview questions check one thing: do you know what your markup means to the browser, to a search engine and to a person using a screen reader? Learning tag names is not enough. This page gives you 24 questions with answers you can say aloud.
Freshers should start with Q1 to Q12. If you have worked on live sites, focus on Q13 to Q24. New to the language? Take the HTML tutorial first.
How to use these HTML interview questions
Cover the answer, speak for 30 seconds, then compare. If you can say what a tag does but not why it matters, read the extra lines.
| Round | What is tested | Good preparation |
|---|---|---|
| Fresher screening | Tags, forms, page structure | Write one page from memory |
| Practical task | Valid, readable markup | Build a form with labels |
| Experienced round | Speed, access, security | Review a real page and fix it |
HTML interview questions and answers for freshers
These are the HTML interview questions for freshers that cover the first web round. Keep one small page open in your editor so you can test each answer.
Q1. What is HTML, and is it a programming language?
30-second answer: HTML stands for HyperText Markup Language. It describes the structure and meaning of a web page. It is a markup language, not a programming language, because it has no variables, loops or conditions.
The browser reads HTML and builds a tree called the DOM. CSS styles that tree and JavaScript changes it.
Q2. What does the doctype do?
30-second answer: <!DOCTYPE html> tells the browser to use standards mode. Without it, the browser may use quirks mode and copy the layout bugs of very old browsers.
It is not an HTML tag. Put it at the top of the file.
Q3. What are the main parts of an HTML page?
30-second answer: The html element holds everything. The head holds information about the page, such as the title and stylesheets. The body holds what the user sees.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Student list</title>
</head>
<body>
<h1>Students</h1>
</body>
</html>
Notice lang. It helps a screen reader choose the right pronunciation.
Q4. What is the difference between an element, a tag and an attribute?
30-second answer: A tag is the marker, such as <p>. An element is the opening tag, the content and the closing tag together. An attribute gives extra information, such as href on a link.
Some elements, such as img, br and input, have no content and no closing tag. They are called void elements.
Q5. What is semantic HTML?
30-second answer: Semantic HTML means choosing a tag for its meaning. Examples are header, nav, main, article and footer. A div has no meaning, so use it only when nothing else fits.
Semantic tags let screen reader users jump between parts of a page. They also help search engines find the main content.
Interview note: Expect the follow-up "section or article?" An article makes sense on its own, such as a blog post. A section is one part of a larger page.
Q6. What is the difference between block and inline elements?
30-second answer: A block element, such as p, starts on a new line and fills the available width. An inline element, such as a, sits inside the line and takes only the space it needs.
This is default display behaviour, and CSS can change it. It does not change what may go inside what: a p still cannot contain a div.
Q7. What is the difference between id and class?
30-second answer: An id must be unique on the page. A class can be reused on many elements. Use classes for styling and ids for labels, page links or one exact element.
One element can have many classes, separated by spaces, but only one id.
Q8. How do ordered, unordered and description lists differ?
30-second answer: Use ol when order matters, ul when it does not and dl for pairs of names and descriptions.
A recipe's steps fit ol. Its ingredients fit ul. A glossary fits dl, with dt for the term and dd for the meaning.
Q9. How do you build a correct form?
30-second answer: Put fields in a form, join every field to a label, pick the right input type and give each field a name. Fields without a name are not sent when the form is submitted.
<form action="/apply" method="post">
<label for="email">Email</label>
<input id="email" name="email" type="email"
autocomplete="email" required>
<button type="submit">Apply</button>
</form>
The label's for matches the input's id. Clicking the label now focuses the field.
Common mistake: Using placeholder text in place of a label. It disappears as soon as the user types.
Q10. When should you use GET and POST in a form?
30-second answer: GET puts the data in the URL, so it suits searches and filters. POST puts it in the request body, so it suits actions that change data.
POST does not make data safe on its own. You still need HTTPS. See GET vs POST for the details.
Q11. What makes good alt text?
30-second answer: Good alt text gives the purpose of the image in its context. If the image is only decoration, use an empty value, alt="", so screen readers skip it.
For a search icon inside a button, "Search" is better than "magnifying glass". If you leave out alt completely, some screen readers may read the file name.
Q12. How do you make an accessible table?
30-second answer: Use a table only for data, not page layout. Add a caption, mark header cells with th and use scope to say whether a header belongs to a row or a column.
Group rows with thead and tbody. In a practical task, writing scope="col" without being asked is a good sign.
HTML interview questions and answers for experienced developers
At this level, the interviewer wants causes and trade-offs. Give a real example from your work if you have one.
Q13. What is the difference between async and defer?
30-second answer: Both let an external script download while the HTML is read. async runs the script as soon as it arrives, in any order. defer waits until the document is parsed and keeps the order.
| Script | Blocks HTML parsing | Order kept |
|---|---|---|
| Normal | Download and run | Yes |
async |
Only while running | No |
defer |
No | Yes |
Use defer for app code that depends on the page. Use async for independent scripts, such as some analytics. A script with type="module" is deferred by default.
Q14. How do you serve responsive images?
30-second answer: Use srcset and sizes to offer the same image at different widths. Use picture when the crop or file format must change.
<img src="campus-800.jpg"
srcset="campus-400.jpg 400w, campus-800.jpg 800w"
sizes="(max-width: 600px) 100vw, 800px"
width="800" height="450" alt="Students in a lab">
Width and height let the browser reserve space, so text does not jump. Add loading="lazy" to images below the first screen, but not to the main image at the top.
Q15. What happens between receiving HTML and showing a page?
30-second answer: The browser turns HTML into the DOM and CSS into the CSSOM. It joins them into a render tree, works out sizes and positions, then paints.
A normal script stops parsing. CSS blocks rendering and can also delay a script that follows it. That is why script and style order affects loading.
Q16. What is ARIA, and when should you avoid it?
30-second answer: ARIA adds roles and states for assistive tools. Use a native element first. Add ARIA only when HTML cannot express the control.
<button> already supports focus, Enter and Space. A div role="button" supports none of those until you add code. Wrong ARIA can be worse than no ARIA.
Q17. How would you make a custom dialog accessible?
30-second answer: I would start with the dialog element and open it using showModal(). I would give it a title, set a sensible first focus, support Escape and check that focus returns when it closes.
The native modal dialog handles much of this. Still test it with only a keyboard, then with a screen reader.
Q18. What is the difference between local storage, session storage and cookies?
30-second answer: Local storage stays until cleared. Session storage lasts for one tab's session. Cookies are sent with matching requests and can have security flags.
JavaScript can read web storage, so a script attack can steal a token kept there. An HttpOnly cookie cannot be read by JavaScript, though it needs protection against cross-site requests.
Q19. How do you embed an iframe safely?
30-second answer: Add sandbox and give back only the permissions needed. Set a clear title, use referrerpolicy where useful and load it lazily if it is below the first screen.
Be careful with allow-scripts and allow-same-origin together on content from your own origin. That content can then remove its own sandbox.
Q20. How does HTML affect SEO?
30-second answer: A clear title, one main heading, sensible heading levels, real links and useful alt text help search engines understand a page. A canonical link names the preferred URL when copies exist.
Use <a href> for navigation. Crawlers may not follow a clickable div. Google Search ignores the meta keywords tag, so do not suggest it as a fix.
Q21. What are data attributes?
30-second answer: Attributes that start with data- hold custom values on an element. JavaScript reads them through dataset.
<button data-course-id="27">View</button>
<script>
const button = document.querySelector('button');
console.log(button.dataset.courseId); // "27"
</script>
Values are strings. Never store secrets there because anyone can inspect the page.
Q22. What is the difference between SVG and canvas?
30-second answer: SVG keeps shapes as elements, so it scales well and shapes can have events. Canvas draws pixels with JavaScript and suits scenes with very many moving objects.
A company logo fits SVG. A fast game fits canvas. Canvas content needs a separate accessible alternative.
Q23. How do you stop user content from becoming a script attack?
30-second answer: Escape user text before placing it in HTML. Use textContent instead of innerHTML for plain text. If users may write HTML, clean it with a trusted sanitizer and add a content security policy.
Client-side checks help users, but attackers can skip them. The server must validate too.
Q24. How would you review a page that loads slowly and jumps around?
30-second answer: I would measure first, then check large images, missing dimensions, blocking scripts, fonts and late banners. I would fix the largest cause and measure again.
Say what you would look for and how you would prove the fix. "Add lazy loading everywhere" is weak because it can delay the most important image.
Interview note: In HTML interview questions and answers for experienced candidates, a clear checking method says more than a long list of tricks.
A small practical task to try
Build a job application page in 30 minutes. Include a heading, navigation, three required fields, a resume upload and one table of job details.
Then check:
- Can you complete it using only the keyboard?
- Does every field have a label?
- Does the W3C validator report no errors?
- Does it work on a narrow phone screen?
Next, break the page on purpose. Remove one label, swap a button for a div and delete the image size. Try the page again and note what got worse. This gives you real examples to use in your answers.
Pro tip: Explain one choice as you build. "This is a button because it performs an action" shows understanding in one line.
How to prepare for the HTML round
Spend day one on structure and semantic tags. Use day two for forms and tables. On day three, test a page with a keyboard. Keep day four for images and scripts, then repeat missed HTML interview questions and answers on day five.
Next, practise CSS interview questions and DOM and event questions. If you want a teacher-led path with backend skills, see the Java full stack course.
Frequently Asked Questions
Which HTML topics should a fresher learn first?
Is HTML enough to get a web developer job?
Will I be asked to write HTML by hand?
Do experienced developers still get HTML questions?
What is the best way to remember HTML tags?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — See the Java Full Stack course in Hyderabad

