HTML basics
The first questions in almost every frontend interview.
What is HTML?
HTML means HyperText Markup Language. It is not a programming language. It is a markup language, which means you use tags to describe what each piece of content is: a heading, a paragraph, an image, a link. The browser reads those tags and draws the page.
What is the difference between an element and a tag?
A tag is the text you type, like <p>. An element is the full thing: the opening tag, the content inside, and the closing tag. So <p>Hello</p> is one element made of two tags.
<p>Hello</p>
<!-- <p> and </p> are tags. The whole line is one element. -->
What is an attribute?
An attribute is extra information you put inside the opening tag. It always sits as name="value". For example href tells a link where to go, and src tells an image which file to load.
<a href="/pricing" title="See plans">Pricing</a>
<img src="/logo.png" alt="Company logo" />
What does <!DOCTYPE html> do?
It tells the browser that this page uses HTML5 and should be rendered in standards mode. If you forget it, the browser switches to quirks mode and copies old buggy behaviour from the 1990s, so your CSS box sizes can go wrong.
What is the basic structure of an HTML page?
Doctype first, then <html>, then <head> for information about the page, then <body> for the content people actually see.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My page</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
What is the difference between <head> and <body>?
<head> holds information about the page: the title, the character set, links to CSS, meta tags for SEO. Nothing in <head> is drawn on the screen. <body> holds everything the user sees and clicks.
Why do we write <meta charset="UTF-8">?
It tells the browser which character set to use when reading the file. UTF-8 supports almost every language and symbol, so names, rupee signs and emojis show correctly instead of turning into strange boxes.
What does the viewport meta tag do?
It tells a mobile browser to use the real device width instead of pretending to be a 980px desktop. Without it, your responsive CSS will not work properly on phones - the page will look zoomed out.
<meta name="viewport" content="width=device-width, initial-scale=1" />
What is the difference between block and inline elements?
A block element starts on a new line and takes the full width available, like <div>, <p> and <h1>. An inline element stays inside the line of text and takes only as much width as it needs, like <span>, <a> and <strong>.
What are void or self-closing elements?
They are elements that cannot have content inside them, so they have no closing tag. Common ones are <br>, <hr>, <img>, <input>, <meta> and <link>.
What is the difference between <div> and <span>?
Both have no meaning of their own - they are just containers. <div> is a block container used for layout sections. <span> is an inline container used to wrap a few words inside a sentence.
Why should a page have only one <h1>?
The <h1> is the main title of the page. Screen readers and search engines use it to understand what the page is about. Many <h1> tags make the structure confusing. Use <h2> and <h3> for the sections under it, in order, without skipping levels.
How do you write a comment in HTML?
You wrap the text between <!-- and -->. The browser ignores it, but remember that anyone can still read it in view-source, so never put secrets there.
<!-- This note is only for developers -->
What is the difference between id and class?
An id must be unique on the page and identifies one single element. A class can be repeated on many elements and is used to give the same style or behaviour to a group. In CSS, id uses # and class uses a dot.
What are data-* attributes?
They let you store your own custom data on an element without breaking HTML rules. JavaScript can read them through the dataset property. They are very handy for connecting a button to a record id.
<button data-user-id="42" data-role="admin">Edit</button>
<script>
const btn = document.querySelector("button");
console.log(btn.dataset.userId); // "42"
</script>
What is the difference between HTML and XHTML?
XHTML is a stricter version of HTML written using XML rules. Every tag must be closed, tags must be lowercase and attribute values must be quoted. One mistake breaks the whole page. HTML5 is forgiving, so XHTML is rarely used today.
Semantic HTML
Using the right tag for the right meaning.
What is semantic HTML?
Semantic HTML means choosing tags that describe the meaning of the content, not just how it looks. <header>, <nav>, <main>, <article>, <aside> and <footer> all say what a block is for. A screen reader, a search engine and a new developer can all understand the page faster.
<body>
<header>Logo and site title</header>
<nav>Menu links</nav>
<main>
<article>The blog post</article>
<aside>Related links</aside>
</main>
<footer>Contact and copyright</footer>
</body>
Why is semantic HTML better than using div everywhere?
Three reasons. Accessibility: screen readers can jump straight to the main content or the navigation. SEO: search engines understand the page structure. Maintenance: the code reads like a description of the page instead of a wall of divs.
What is the difference between <article> and <section>?
An <article> is a piece of content that makes sense on its own - a blog post, a news item, a product card. A <section> is a thematic group inside a bigger page, like the "Features" part of a landing page. If you could copy it out and publish it alone, it is an article.
When do you use <main>?
Once per page, around the main unique content. Things repeated on every page - the header, the sidebar menu, the footer - stay outside it. Browsers use it for the "skip to content" shortcut.
What is the difference between <strong> and <b>, or <em> and <i>?
<strong> and <em> carry meaning: strong importance and emphasis. A screen reader changes its tone for them. <b> and <i> only change how the text looks, with no extra meaning. Prefer <strong> and <em> when the meaning matters.
What is <figure> and <figcaption> for?
<figure> wraps content like an image, chart or code block that is referenced from the text. <figcaption> gives it a caption that stays connected to it, so the browser knows the caption belongs to that image.
<figure>
<img src="chart.png" alt="Sales grew 40 percent in 2025" />
<figcaption>Sales growth in 2025</figcaption>
</figure>
What does the <time> element do?
It marks a date or time in a machine-readable way. Humans read the text inside, and machines read the datetime attribute.
<time datetime="2026-03-14">14 March 2026</time>
What is the <template> element?
It holds HTML that the browser parses but does not render. You clone it with JavaScript when you need it. It is useful for repeating rows in a list without building strings by hand.
<template id="row">
<li class="item"></li>
</template>
<script>
const tpl = document.getElementById("row");
const node = tpl.content.cloneNode(true);
document.querySelector("ul").appendChild(node);
</script>
Forms and input
The part of HTML that interviewers dig into most.
What is the difference between GET and POST in a form?
GET puts the data in the URL, so it is visible, can be bookmarked and has a length limit. It suits searching. POST sends the data in the request body, so it is not visible in the URL and can be large. It suits creating or changing data.
Why should every input have a label?
A label tells the user and the screen reader what the field is for, and clicking the label focuses the field, which makes it easier to tap on mobile. Connect them with the for attribute matching the input id, or wrap the input inside the label.
<label for="email">Email</label>
<input id="email" name="email" type="email" />
What input types does HTML5 add?
email, url, tel, number, range, date, time, color, search and more. They give free validation and, on mobile, the right keyboard - a number pad for tel, an @ key for email.
What is the difference between the placeholder and the label?
A placeholder is a hint that disappears as soon as the user types, so it cannot be the only description. A label stays visible. Using a placeholder instead of a label is a common accessibility mistake.
How does built-in HTML form validation work?
Attributes like required, min, max, minlength, maxlength, pattern and type make the browser check the value before submitting and show a message. Add novalidate on the form if you want to handle everything in JavaScript.
<input
type="text"
name="pin"
required
pattern="[0-9]{6}"
title="Enter a 6 digit PIN code"
/>
What is the difference between disabled and readonly?
A disabled field cannot be focused, cannot be edited and is not sent when the form submits. A readonly field cannot be edited but can be focused, copied, and it is still sent with the form.
What does the name attribute do on an input?
It is the key used when the form data is sent to the server. Without a name, the value is simply not submitted. The id is only for labels and CSS or JavaScript.
How do radio buttons get grouped?
By sharing the same name attribute. Only one radio in a group can be selected. Checkboxes with the same name are all sent, so they behave like a multi-select list.
<input type="radio" name="plan" value="monthly" id="m" /><label for="m">Monthly</label>
<input type="radio" name="plan" value="yearly" id="y" /><label for="y">Yearly</label>
What is <fieldset> and <legend>?
<fieldset> groups related fields together and <legend> gives that group a title. Screen readers read the legend before each field in the group, which is very useful for a set of radio buttons.
How do you upload a file?
Use input type="file". The form must use method="post" and enctype="multipart/form-data", otherwise only the file name is sent, not the file. Add accept to filter file types and multiple to allow several files.
<form method="post" enctype="multipart/form-data">
<input type="file" name="resume" accept=".pdf,.docx" />
<button type="submit">Upload</button>
</form>
What is autocomplete and why does it matter?
It tells the browser what kind of value a field expects, so the browser can fill it from saved data. Correct values like autocomplete="email" or "one-time-code" make forms much faster to complete, especially on mobile.
What is the difference between <button> and <input type="submit">?
Both submit a form. <button> can contain HTML inside it, like an icon plus text, so it is more flexible. Remember that a <button> inside a form defaults to type="submit"; set type="button" if it should not submit.
What is the <datalist> element?
It gives an input a list of suggestions while still allowing any typed value. It behaves like an autocomplete dropdown without any JavaScript.
<input list="cities" name="city" />
<datalist id="cities">
<option value="Bengaluru"></option>
<option value="Pune"></option>
</datalist>
Tables and lists
Small topics that still show up in interviews.
What are the main parts of a table?
<table> wraps everything, <caption> names it, <thead> holds the header row, <tbody> holds the data rows and <tfoot> holds totals. Header cells use <th> and data cells use <td>.
<table>
<caption>Monthly sales</caption>
<thead>
<tr><th scope="col">Month</th><th scope="col">Total</th></tr>
</thead>
<tbody>
<tr><td>March</td><td>12,000</td></tr>
</tbody>
</table>
What does the scope attribute do on <th>?
It says whether that header describes a column or a row. Screen readers use it to announce the right header while moving between cells, so a blind user knows that "12,000" is the March total.
Why should tables not be used for page layout?
Tables mean "this is tabular data". Using them for layout confuses screen readers, makes responsive design very hard and produces messy HTML. Use CSS grid or flexbox for layout.
What are the three list types in HTML?
<ul> for an unordered list where order does not matter, <ol> for an ordered list where order matters and items get numbers, and <dl> for a description list of term and definition pairs using <dt> and <dd>.
How do colspan and rowspan work?
colspan makes one cell stretch across several columns, and rowspan makes it stretch down several rows. They are used for merged header cells.
Accessibility
A topic that separates a junior from a mid-level candidate.
What is web accessibility?
It means building pages that people with disabilities can use - people using a screen reader, people who cannot use a mouse, people with low vision or colour blindness. Good accessibility usually also improves SEO and usability for everyone.
What is ARIA?
ARIA stands for Accessible Rich Internet Applications. It is a set of extra attributes such as role, aria-label and aria-expanded that describe custom widgets to assistive technology. The first rule of ARIA is: do not use ARIA if a normal HTML element already does the job.
What is aria-label used for?
It gives an element an accessible name when there is no visible text. A button that contains only an X icon should have aria-label="Close dialog", otherwise a screen reader just says "button".
<button aria-label="Close dialog">
<svg aria-hidden="true">...</svg>
</button>
What does tabindex do?
tabindex="0" puts an element into the normal keyboard tab order. tabindex="-1" makes it focusable only from JavaScript, which is useful for moving focus into a modal. Positive numbers break the natural order and should be avoided.
What is a skip link?
A link at the very top of the page that jumps straight to the main content. Keyboard users otherwise have to tab through the whole menu on every page. It is usually hidden until it receives focus.
<a class="skip-link" href="#main">Skip to main content</a>
...
<main id="main">...</main>
Why is semantic HTML the easiest accessibility win?
Because native elements already come with keyboard support, focus behaviour and correct announcements. A real <button> can be pressed with Enter and Space and is announced as a button. A <div onclick> gives you none of that until you rebuild it by hand.
What is aria-hidden?
It removes an element from the accessibility tree, so screen readers ignore it. Use it for decorative icons. Never put it on something the user can focus, or a keyboard user will land on an element that is silent.