Skip to main content

Command Palette

Search for a command to run...

Top 100 HTML Interview Questions to Ace Your Frontend Interview

Updated
β€’44 min read
S
Full Stack Developer | AI Enthusiast | Builder πŸ› οΈ Currently focused on building high-performance products like ShortIQ (AI content engine) and Spectr (real-time analytics). I write about Next.js, backend architecture, and the journey of scaling modern web apps. Tech Stack: JavaScript/TypeScript, Next.js, Node.js, PostgreSQL, and AI integration (Gemini/Sarvam). Check out my work: subhashjha.me

01. What does HTML stand for?

Difficulty: Easy Answer: HTML stands for HyperText Markup Language.

Think of it this way πŸ’‘ HTML is like the skeleton of a webpage. It tells the browser what things are β€” "this is a heading", "this is a paragraph", "this is an image".

HyperText = links that connect pages together. Markup = using special tags to label your content. Language = a set of rules the browser understands.


02. What is the difference between an HTML tag and an HTML element?

Difficulty: Easy Answer:

Simple answer πŸ’‘ A tag is just the label part (like <p>). An element is the whole thing β€” the opening tag + content + closing tag.

Example πŸ‘‡ The tag is <p>. The element is <p>Hello!</p> β€” that's the full package.


03. What does do?

Difficulty: Easy Answer:

Simple answer πŸ’‘ It tells the browser "hey, this is an HTML5 page β€” please read it correctly!"

Without it, the browser might go into "quirks mode" β€” an old mode that can make your page look weird or broken. Always put <!DOCTYPE html> as the very first line of your HTML file.


04. What is the basic structure of an HTML page?

Difficulty: Easy Answer: Every HTML page has this basic shape:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>My Page</title>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

Easy way to remember πŸ’‘ <head> = stuff the browser needs to know (invisible to users). <body> = stuff the user actually sees on the page.


05. What is the difference between block and inline elements?

Difficulty: Easy Answer:

Simple answer πŸ’‘ Block elements take up the full width of the page and always start on a new line. Inline elements only take up as much space as their content needs and stay in the same line.

Real life example 🏠 Block = a whole shelf (takes the full row). Inline = a book on that shelf (only as wide as the book).

Block examples: <div>, <p>, <h1>. Inline examples: <span>, <a>, <strong>.


06. What are void elements (self-closing tags)?

Difficulty: Easy Answer:

Simple answer πŸ’‘ Void elements are tags that don't need a closing tag because they can't hold any content inside them.

Examples πŸ‘‡ <br> (line break), <img> (image), <input> (text box), <hr> (horizontal line), <meta>, <link>.

Think about it β€” an image tag shows a picture. What would you put inside it? Nothing! So it doesn't need a closing tag.


07. What is the difference between
and ?

Difficulty: Easy Answer:

Simple answer πŸ’‘ Both are empty containers with no meaning β€” just boxes to group things. The only difference: <div> is a big block box. <span> is a small inline box.

Analogy πŸ“¦ <div> = a cardboard box (holds a whole section). <span> = a sticky label (highlights just a few words in a sentence).


08. What is the difference between HTML attributes and properties?

Difficulty: Medium Answer:

Simple answer πŸ’‘ Attributes are written in the HTML code β€” they're the starting value. Properties are the live values in the browser as the user interacts with the page.

Example πŸ‘‡ You write <input value="hello">. That "hello" is the attribute. The user clears it and types "world". Now the property is "world" β€” but the attribute in your HTML still says "hello". They can be different!


Semantic HTML

09. What is semantic HTML and why does it matter?

Difficulty: Easy Answer:

Simple answer πŸ’‘ Semantic HTML means using tags that describe what the content is, not just how it looks.

Bad vs Good πŸ‘‡ ❌ Bad: <div>My Article</div> β€” tells nothing about the content. βœ… Good: <article>My Article</article> β€” tells everyone it's an article.

It helps: screen readers for blind users, Google for search rankings, and other developers reading your code.


10. What is the difference between
and
?

Difficulty: Easy Answer:

Quick test πŸ’‘ Ask yourself: "Could I copy this content and put it on another website and it would still make sense?" If YES β†’ use <article>. If NO β†’ use <section>.

Example πŸ“° A blog post = <article> (makes sense on its own anywhere). A chapter inside a book page = <section> (only makes sense as part of the book).


11. What do
,
,
, and

Difficulty: Medium Answer:

Think of a newspaper πŸ“° <header> = the newspaper's name and date at the top. <main> = the main news stories in the middle. <aside> = the sidebar with extra stuff (ads, related links). <footer> = the small print at the bottom (contact, copyright).

There should be only one <main> per page β€” it's the star of the show.


12. When do you use vs , and vs ?

Difficulty: Medium Answer:

Simple rule πŸ’‘ <strong> = This is important, pay attention! (screen readers may say it louder) <b> = Just make it look bold, no special importance.

<em> = stress this word (changes the meaning of the sentence) <i> = just make it look italic (book titles, foreign words).

Example πŸ—£οΈ "Do not touch that!" β€” the emphasis changes the meaning. "Read Harry Potter" β€” just styling a book title.


13. What are
and
used for?

Difficulty: Medium Answer:

Simple answer πŸ’‘ <figure> is a container for an image (or chart or code) that goes with the text but could be moved without breaking the page. <figcaption> is the caption label under it.

<figure>
  <img src="cat.jpg" alt="A cat">
  <figcaption>My cat loves boxes.</figcaption>
</figure>

It's like a photo in a magazine β€” the picture and its caption belong together.


14. What is the

Difficulty: Easy Answer:

Simple answer πŸ’‘ <nav> wraps your main navigation menu β€” the links people use to move around your website.

It tells blind users (using screen readers) "here's the navigation, you can jump to it or skip it." Only use it for major navigation, not every group of links on the page.


Forms & Input

15. What is the difference between GET and POST in a form?

Difficulty: Easy Answer:

Simple answer πŸ’‘ GET = puts the data in the website address (URL). You can see it, bookmark it, share it. POST = sends data secretly, hidden from the URL. Better for passwords and private info.

Real life πŸ›’ GET is like writing your shopping list on a postcard β€” anyone can read it. POST is like putting it in a sealed envelope β€” more private.


16. What does the element do?

Difficulty: Easy Answer:

Simple answer πŸ’‘ A label tells the user what an input field is for. It also makes the input easier to click β€” clicking the label text focuses the input!

<label for="email">Your Email:</label>
<input type="email" id="email">

The for attribute connects the label to the input via the input's id. Screen readers will say "Your Email" when the user focuses on that input β€” very important for accessibility.


17. What new input types did HTML5 add?

Difficulty: Medium Answer: HTML5 gave us many new input types so we don't always need JavaScript:

New input types πŸ†• email β€” checks for @ sign number β€” only allows numbers date β€” shows a date picker color β€” shows a color picker range β€” shows a slider tel β€” phone number keyboard on mobile url β€” checks for valid web address

The browser handles the validation for you β€” no extra code needed!


18. What is the difference between and ?

Difficulty: Medium Answer:

Simple answer πŸ’‘ Both can submit a form. But <button> is more powerful β€” you can put HTML inside it (like an icon + text). <input type="submit"> can only show plain text.

Example πŸ‘‡ ❌ <input type="submit" value="Send"> β€” plain text only. βœ… <button>πŸš€ Send Message</button> β€” can include emojis, icons, formatted text!

Important: a <button> inside a form submits by default. If you don't want that, use type="button".


19. What do name, id, and placeholder do on an input?

Difficulty: Medium Answer:

Each one does something different πŸ’‘ name = the label for the data when you submit the form (the server uses this). id = a unique name for CSS/JavaScript to target, and to link with a <label>. placeholder = hint text inside the box that disappears when you start typing.

Analogy πŸ“¬ name = the address label on a package (tells the server what data it is). id = a unique tracking number (so JS/CSS can find it exactly). placeholder = the "write your message here" hint inside a text box.


20. What are and ?

Difficulty: Medium Answer:

Simple answer πŸ’‘ <fieldset> draws a box around a group of related form fields. <legend> is the title of that group, shown at the top of the box.

<fieldset>
  <legend>Delivery Address</legend>
  <input type="text" placeholder="Street">
  <input type="text" placeholder="City">
</fieldset>

It helps users (especially screen reader users) understand that these fields belong together.


21. How does HTML5 form validation work?

Difficulty: Hard Answer:

Simple answer πŸ’‘ HTML5 can check if a form is filled correctly before it's sent β€” no JavaScript needed!

You add special attributes to your inputs:

Common validation attributes πŸ‘‡ required β€” field can't be empty minlength="5" β€” must be at least 5 characters max="100" β€” number can't be more than 100 pattern="[A-Z]+" β€” must match this pattern type="email" β€” must look like an email address

When the user clicks Submit, the browser checks everything and shows error messages automatically. Add novalidate to the form if you want to turn this off and do it yourself with JavaScript.


22. What is enctype="multipart/form-data" and when do you need it?

Difficulty: Hard Answer:

Simple answer πŸ’‘ Whenever your form lets users upload a file, you must add enctype="multipart/form-data" to your form tag. Without it, the file won't actually be sent!

<form method="POST" enctype="multipart/form-data">
  <input type="file" name="photo">
  <button>Upload</button>
</form>

The default encoding only handles text. "multipart/form-data" packages the file as a proper upload that servers can read.


23. What is the alt attribute on images and why is it important?

Difficulty: Easy Answer:

Simple answer πŸ’‘ alt is a text description of the image. It's shown when the image can't load, and read out loud by screen readers to blind users.

Rules πŸ‘‡ βœ… Useful image: alt="A golden retriever playing in the park" βœ… Decorative image (ignore it): alt="" (empty is correct!) ❌ Never: alt="image" or alt="photo123.jpg" β€” that's useless.

Google also reads alt text to understand your images β€” it helps with SEO too!


24. What is the difference between absolute and relative URLs?

Difficulty: Easy Answer:

Simple answer πŸ’‘ Absolute URL = the full address, like a full home address including country. Relative URL = a shortcut address, like "the room next door".

Example πŸ—ΊοΈ Absolute: https://mysite.com/images/logo.png β€” works from anywhere. Relative: images/logo.png β€” works only from pages on the same site.

Use relative URLs for your own site's files (easier to move the site later). Use absolute URLs when linking to other websites.


25. What does target="_blank" do and what danger does it create?

Difficulty: Medium Answer:

Simple answer πŸ’‘ target="_blank" opens the link in a new browser tab. The danger is that the new page can control your original page unless you stop it!

The fix πŸ”’ Always add rel="noopener noreferrer" alongside it: <a href="..." target="_blank" rel="noopener noreferrer">

This blocks the new page from accessing your page. Without this, a sneaky site could redirect your original tab to a fake login page.


26. How do you add video and audio to a page in HTML5?

Difficulty: Medium Answer:

Simple answer πŸ’‘ HTML5 has built-in <video> and <audio> tags β€” no Flash plugin needed anymore!

<video controls width="500">
  <source src="myvideo.mp4" type="video/mp4">
  Your browser can't play this video.
</video>

Useful attributes 🎬 controls β€” show play/pause buttons autoplay β€” start playing automatically muted β€” start without sound loop β€” keep repeating


27. What is the srcset attribute on images?

Difficulty: Medium Answer:

Simple answer πŸ’‘ srcset lets you provide multiple versions of an image. The browser picks the right one based on screen size β€” so phones don't download a huge desktop image!

<img
  src="small.jpg"
  srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
  alt="A landscape photo">

Analogy πŸ“± Like a restaurant offering small, medium, and large coffees. The browser orders just the right size it needs β€” no waste!


28. What is the element and when do you use it?

Difficulty: Hard Answer:

Simple answer πŸ’‘ <picture> lets you show a completely different image on small screens vs big screens β€” not just a smaller version, but a different photo altogether (different crop, different scene).

<picture>
  <source media="(max-width: 600px)" srcset="portrait.jpg">
  <source media="(min-width: 601px)" srcset="landscape.jpg">
  <img src="landscape.jpg" alt="Our team">
</picture>

When to use it πŸ“Έ Imagine a team photo. On desktop: wide group shot. On mobile: just the faces, cropped close-up. That's when <picture> shines β€” srcset alone can't do this.


Tables

29. What is the correct way to build an HTML table?

Difficulty: Easy Answer:

<table>
  <caption>Student Scores</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Score</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>95</td>
    </tr>
  </tbody>
</table>

Parts of a table πŸ’‘ <caption> = title of the table <thead> = header row <tbody> = data rows <th> = header cell (bold by default) <td> = regular data cell <tr> = one row


30. What is the difference between colspan and rowspan?

Difficulty: Medium Answer:

Simple answer πŸ’‘ colspan = stretch a cell across multiple columns (sideways). rowspan = stretch a cell across multiple rows (downward).

Analogy 🏠 colspan = knocking down the wall between two rooms side by side (one big wide room). rowspan = knocking down the floor/ceiling between two rooms above each other (a tall double-height room).


31. Why should you NOT use tables for page layout?

Difficulty: Medium Answer:

Simple answer πŸ’‘ Tables are for data (like spreadsheets), not for placing things on a page. Using tables for layout is like using a fork to eat soup β€” technically possible but the wrong tool!

Problems with using tables for layout:

Why it's bad 🚫 πŸ”‡ Screen readers get confused β€” they read table cells as if they're data. πŸ“± Tables don't work well on small screens β€” they're rigid. 🐌 Tables are slow β€” the browser waits to download the whole table before drawing it.

βœ… Use CSS Flexbox or CSS Grid for layout instead!


Metadata & The

32. What does the viewport meta tag do?

Difficulty: Easy Answer:

Simple answer πŸ’‘ It tells phones and tablets "fit this page to my screen β€” don't zoom out so everything looks tiny!"

<meta name="viewport" content="width=device-width, initial-scale=1">

Without this tag 😱 Mobile browsers will pretend the screen is 980px wide and zoom way out, making your text super tiny. With this tag, the page fits the actual screen. That's why every responsive website needs it.


33. Should go in and

1 views