HTML Interview Questions and Answers
HTML Interview Questions and Answers
✅ Basic Level
1. What is HTML?
HTML (HyperText Markup Language) is the standard language used to create and structure content on
the web.
2. What are HTML tags?
Tags are predefined keywords in angle brackets (e.g., <p>) used to define elements and structure in
HTML.
3. What is <!DOCTYPE html>?
It declares the document type and version of HTML being used. It helps browsers render the page
correctly.
4. Difference between HTML and XHTML?
XHTML is stricter than HTML and must be well-formed. It combines HTML and XML rules.
5. What are semantic HTML elements?
These elements clearly describe their meaning in a human- and machine-readable way (e.g., <article>,
<section>, <nav>).
6. How do you create a hyperlink in HTML?
Using the <a> tag:
html
CopyEdit
<a href="https://example.com">Visit</a>
html
CopyEdit
<img src="image.jpg" alt="Description">
✅ Intermediate Level
html
CopyEdit
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
</audio>
html
CopyEdit
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
html
CopyEdit
<a href="#"><img src="image.jpg"></a>
33. What are global attributes in HTML?
Attributes applicable to all elements, like id, class, style, title.
34. How to specify character encoding?
html
CopyEdit
<meta charset="UTF-8">
css
CopyEdit
selector {
property: value;
}
css
CopyEdit
margin: 0 auto;
css
CopyEdit
@media (max-width: 768px) {
/* Styles */
}
css
CopyEdit
div p {
color: blue;
}
css
CopyEdit
background-image: url("image.jpg");
html
CopyEdit
<iframe src="https://www.youtube.com/embed/VIDEO_ID" allowfullscreen></iframe>
81. What is the difference between relative and absolute positioning in CSS?
css
CopyEdit
@media print {
body { color: black; }
}
css
CopyEdit
width: calc(100% - 50px);
css
CopyEdit
position: sticky;
top: 0;
css
CopyEdit
img {
width: 100%;
height: auto;
}
css
CopyEdit
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
css
CopyEdit
@keyframes fade {
from { opacity: 0; }
to { opacity: 1; }
}
Minify CSS
Avoid deep selectors
Use shorthand
Use fewer rules
Here are 50 more HTML and CSS interview questions and answers, split into Basic (1–25) and
Intermediate (26–50) levels. These are fresh and not duplicates of the previous 100.
If you’d like, I can now combine all 150 Q&As into a formatted PDF or Word document for easy revision.
Would you like that?