All HTML Interview Questions & Answers
All HTML interview questions with simple answers. Covers tags and elements, attributes, links, images, lists, tables, forms, meta tags, semantic elements, HTML5 and web accessibility.
What is the full form of HTML?
The full form of HTML is HyperText Markup Language.
- HyperText means text that has links to other text. You click a link and go to another page.
- Markup means marking parts of the content with tags, like heading, paragraph or image.
- Language means it has its own rules (syntax) that the browser understands.
HTML is not a programming language, because it has no logic like conditions and loops. It only describes the structure of a page. Read more in HTML Introduction.
How to add comments in HTML?
Write the comment between <!-- and -->. The browser ignores it and does not show it on the page.
<!-- This is a single-line comment -->
<h1>Welcome</h1>
<!--
This is a
multi-line comment
-->
You can also use a comment to switch off a piece of code for a while. In most editors the shortcut is Ctrl + /.
Comments are not secret, because anyone can see them in “View page source”. Do not write passwords in them. Learn more in HTML Comments.
How do you create links to sections within the same page?
Give the section an id, and then link to it with href="#id". This is useful for a table of contents on a long page.
<a href="#html">HTML</a> | <a href="#css">CSS</a>
<h2 id="html">HTML</h2>
<p>HTML content...</p>
<h2 id="css">CSS</h2>
<p>CSS content...</p>
<a href="#top">Back to top</a>
- The id must be unique on the page.
- The link starts with
#followed by the id. - A link to
#top(or#only) takes the visitor to the top of the page.
To jump to a section of another page, see how to jump to a specific part of a page.
Do all HTML tags require both a begin and end tag?
No. Most elements have an opening and a closing tag, like <p>...</p>. But empty (void) elements have no content, so they have no closing tag.
<!-- with closing tag -->
<p>Hello</p>
<!-- empty elements: no closing tag -->
<br>
<hr>
<img src="photo.jpg" alt="Photo">
<input type="text">
<meta charset="UTF-8">
HTML also lets you leave out the closing tag of some elements, like <li> and <p>, but it is a bad habit. Always close the tags that need it. See HTML Elements and Tags.
How to add the copyright symbol to a web page?
Use the HTML entity ©. You can also use the number code ©. Both show the © symbol.
<footer>
<p>© 2025 Tutorials Class. All rights reserved.</p>
</footer>
© 2025 Tutorials Class. All rights reserved.
If your page is saved as UTF-8 you can also type the © character directly. Other useful symbols are ® (®) and ™ (™). See HTML Symbols.
What is HTML?
HTML (HyperText Markup Language) is the standard language for creating web pages. It uses tags to tell the browser what each part of the content is: a heading, a paragraph, an image, a link and so on.
<h1>Hello, World!</h1>
<p>This is a paragraph.</p>
Hello, World!
This is a paragraph.
HTML gives the structure, CSS gives the style and JavaScript gives the behaviour. HTML is a markup language, not a programming language. Learn more in HTML Introduction.
What is the difference between HTML tags and elements?
A tag is only the label written in angle brackets, like <p> and </p>. An element is the complete thing: the opening tag, the content and the closing tag together.
| Part | Example |
|---|---|
| Opening tag | <p> |
| Content | Hello |
| Closing tag | </p> |
| Element | <p>Hello</p> |
Empty elements like <br> have only one tag. In daily talk people use both words for the same thing. See HTML Elements and Tags.
What is the HTML page structure? Explain with example
Every HTML page has the same basic structure: a DOCTYPE, then the html element, which has a head (information about the page) and a body (the visible content).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
</head>
<body>
<h1>Hello</h1>
<p>Page content.</p>
</body>
</html>
<!DOCTYPE html>tells the browser it is HTML5.<head>has the title, charset, styles and scripts. It is not shown on the page.<body>has everything the visitor sees.
More in HTML Page Structure.
What is an attribute in HTML?
An attribute gives extra information about an HTML element. It is written inside the opening tag as name="value".
<a href="https://example.com" target="_blank">Visit</a>
<img src="photo.jpg" alt="A photo" width="200">
Here href, target, src, alt and width are attributes. Some common ones are id, class, style and title. Boolean attributes like disabled and required have no value. See HTML Attributes.
What is the difference between DIV, SPAN and paragraph tag in HTML?
All three are used to hold content, but they are different.
| Tag | Type | Use |
|---|---|---|
<div> | Block | Generic container to group sections and for layout |
<span> | Inline | Generic container to style a small part of text |
<p> | Block | A paragraph of text, with a meaning |
<div class="card">
<p>My favourite colour is <span style="color:red">red</span>.</p>
</div>
My favourite colour is red.
div and span have no meaning of their own, while p tells that the text is a paragraph. See HTML Div and Span.
What do you mean by HTML links?
An HTML link (hyperlink) is a clickable text or image that takes the visitor to another page, a file, an email app or a part of the same page. It is created with the <a> tag, and the address is written in the href attribute.
<a href="https://www.example.com">Visit Example</a>
<a href="about.html">About us</a>
<a href="mailto:info@example.com">Email us</a>
<a href="https://www.example.com" target="_blank" rel="noopener">Open in new tab</a>
Learn more in HTML Links.
How to create a link to jump to a specific part of a page in HTML?
Give the target element an id, and put #id in the link. This works for the same page and for another page.
<!-- same page -->
<a href="#pricing">See pricing</a>
<h2 id="pricing">Pricing</h2>
<!-- another page -->
<a href="plans.html#pricing">Pricing on the plans page</a>
For a smooth scroll instead of a sudden jump, add this CSS.
<style>
html { scroll-behavior: smooth; }
</style>
See also links to sections within the same page and HTML class and id.
What are different tags to list items in HTML?
HTML has three kinds of lists.
| Tag | List type | Item tag |
|---|---|---|
<ul> | Unordered list (bullets) | <li> |
<ol> | Ordered list (numbers) | <li> |
<dl> | Description list | <dt> term and <dd> description |
<ul>
<li>Apple</li>
<li>Mango</li>
</ul>
<ol>
<li>Step one</li>
<li>Step two</li>
</ol>
<dl>
<dt>HTML</dt>
<dd>Structure of a page</dd>
</dl>
- Apple
- Mango
- Step one
- Step two
- HTML
- Structure of a page
Lists can be nested. See HTML Lists.
What are void (empty) elements in HTML?
Void elements (also called empty elements) are HTML elements that have no content, so they have no closing tag. They only have attributes.
<br>
<hr>
<img src="photo.jpg" alt="Photo">
<input type="text" name="name">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
Common void elements are br, hr, img, input, meta, link, source and col. In HTML5 you write them without the slash. In XHTML they were written as <br />. See HTML Elements and Tags.
What is the difference between HTML and HTML5?
HTML5 is the latest major version of HTML. It added new elements and features, so many things that needed plugins can now be done with plain HTML.
| Point | HTML 4 | HTML5 |
|---|---|---|
| Doctype | Long and complex | <!DOCTYPE html> |
| Layout tags | Only div | header, nav, main, footer and more |
| Media | Needed Flash | audio and video |
| Graphics | Images only | canvas and inline SVG |
| Forms | Few input types | email, date, number, range and more |
| Old tags | font, center, frame allowed | Removed. Use CSS |
| Storage | Cookies only | localStorage and sessionStorage |
Read HTML5 Introduction.
What are semantic elements in HTML5? Give examples
Semantic elements are tags whose name tells what the content is. For example <nav> holds navigation links and <footer> is the bottom part of a page. A <div> tells nothing.
header,nav,main,footersection,article,asidefigure,figcaption,time
<header>Site title</header>
<nav>Menu</nav>
<main>
<article>Blog post</article>
<aside>Related links</aside>
</main>
<footer>Copyright</footer>
They help SEO, accessibility and make the code easy to read. See HTML Semantic Elements.
What is the difference between id and class in HTML?
An id must be unique, so it identifies only one element on the page. A class can be used on many elements, and one element can have many classes.
| Point | id | class |
|---|---|---|
| Elements | Only one | Many |
| CSS selector | #name | .name |
| Many on one element | No | Yes, separated by a space |
<style>
#title { color: navy; }
.note { background: #fff3cd; }
</style>
<h1 id="title">Heading</h1>
<p class="note">Note one</p>
<p class="note">Note two</p>
An id is also used as the target of a link (#id). See HTML Class and ID.
What is the alt attribute in HTML and why is it important?
The alt attribute of the <img> tag gives a short text description of the image.
<img src="bike.jpg" alt="Red bicycle near a wall">
- It is shown when the image cannot load.
- Screen readers read it, so blind visitors know what the image is.
- Search engines use it to understand the image, so it helps SEO.
Write what the image shows, in a few words, and do not start with “image of”. For decorative images use an empty alt="". See HTML Images.
What is the difference between strong and b tag in HTML?
Both make text bold. The difference is in the meaning. <strong> means the text is important, and screen readers read it with stress. <b> only draws attention without extra importance, like a product name.
<p><strong>Warning:</strong> do not touch this.</p>
<p>Try the <b>Pro</b> plan.</p>
The same difference is between <em> (emphasis) and <i> (italic for a technical term or a thought). Prefer strong and em for normal text. See HTML Formatting.
How do you create a table in HTML?
Use the <table> tag. Inside it, each row is a <tr>, header cells are <th> and data cells are <td>.
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Robin</td>
<td>85</td>
</tr>
</table>
| Name | Marks |
|---|---|
| Robin | 85 |
Add borders with CSS. See HTML Tables.