HTML & CSS Junior interview questions and answers
75 questions for a HTML & CSS (Junior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.Why do HTML documents start with
<!DOCTYPE html>? - 2.Which set contains only HTML5 semantic elements?
- 3.How many visible
<main>elements can a page have, and what is it for? - 4.How does
<div>differ from<span>by default? - 5.You set
width: 200px; height: 50pxon a<span>with no other styles. What happens? - 6.How does
display: inline-blockdiffer frominline? - 7.How do you read the value of the
data-user-id="42"attribute in JavaScript? - 8.What is the main difference between the
idandclassattributes? - 9.Why add
rel="noopener noreferrer"to a link withtarget="_blank"? - 10.What is the default
typeof a<button>inside a<form>? - 11.Why link a
<label>to an<input>withforandid? - 12.What
altshould a purely decorative image (e.g. a divider ornament) have? - 13.What does
box-sizing: border-boxdo? - 14.How does
paddingdiffer frommargin? - 15.Two blocks are stacked. The top one has
margin-bottom: 20px, the bottom onemargin-top: 30px. What is the gap between them? - 16.Both selectors set
coloron the same link. Which wins:#nav aor.menu .item a.link? - 17.Which of these properties is inherited by child elements by default?
- 18.How does
display: nonediffer fromvisibility: hidden? - 19.How does an element with
position: relative; top: 10pxbehave? - 20.What is an element with
position: absolutepositioned relative to? - 21.How does
position: sticky; top: 0work? - 22.Which elements does
z-indexapply to? - 23.How does
remdiffer fromem? - 24.What is
50vwequal to? - 25.How are media queries usually written with a mobile-first approach?
- 26.Why do you need
<meta name="viewport" content="width=device-width, initial-scale=1">? - 27.Along which axis does
justify-contentalign items in a flex container? - 28.A container has
display: flex; flex-direction: column; justify-content: center. How are its children aligned? - 29.What does
flex-wrap: wrapdo? - 30.What's the simplest way to space flex items evenly without adding space after the last one?
- 31.Which approach correctly centers a block horizontally and vertically inside its parent?
- 32.What does
grid-template-columns: repeat(3, 1fr)define? - 33.How do you make a grid item span the full width of the grid regardless of the number of columns?
- 34.How does a pseudo-class differ from a pseudo-element?
- 35.How do you make the last item of a list of any length red without JavaScript?
- 36.Why doesn't a
::beforewith onlywidth,heightandbackgroundshow up? - 37.How do you correctly declare and use a CSS variable?
- 38.What do the last two digits in the color
#3366ff80mean? - 39.When is it better to use
<img>rather thanbackground-image? - 40.Why have heading levels
<h1>–<h6>if size can be set with CSS? - 41.When should you use
<a>and when<button>? - 42.What is the
<dl>list for? - 43.A form is submitted with the
GETmethod. Where does the field data go? - 44.What does
<input type="email">give you compared withtype="text"? - 45.What does the
requiredattribute do on a form field? - 46.What is the utility-first approach in Tailwind CSS about?
- 47.What does the
md:flexclass mean in Tailwind? - 48.What does
p-4equal in Tailwind with the default configuration? - 49.How do you change a button's background on hover in Tailwind?
- 50.How does the
dark:variant work by default in Tailwind v4? - 51.When should you use
<article>rather than<section>? - 52.How does
<strong>differ from<b>? - 53.What happens if you put a
<div>inside a<p>in HTML? - 54.When is
<table>the right choice? - 55.What is sent to the server for an unchecked checkbox?
- 56.Why isn't
placeholdera replacement for<label>? - 57.How should a group of related radio buttons be marked up?
- 58.What are
<figure>and<figcaption>for? - 59.How does
overflow: autodiffer fromoverflow: scroll? - 60.Why doesn't
text-align: centercenter a<div>with a fixed width inside its parent? - 61.Why is a unitless
line-height: 1.5usually better thanline-height: 24px? - 62.How does
opacity: 0.5on a card differ frombackground: rgb(0 0 0 / 0.5)? - 63.How do you apply hover styles only on devices that can actually hover?
- 64.What is the difference between
.menu aand.menu > a? - 65.Which element does
h2 + pselect? - 66.What does
input[type="email"]select? - 67.Why is
img { max-width: 100%; height: auto; }a common base rule? - 68.What does
margin: 10px 20pxset? - 69.How do you make a square avatar image a circle?
- 70.Why end a
font-familylist with a generic family likesans-serif? - 71.What is the accessibility risk of reordering flex items with
order? - 72.Why do flex items in a row have equal height by default?
- 73.Which style wins: a rule in a stylesheet or the inline
styleattribute? - 74.What does
class="hidden md:block"do in Tailwind? - 75.Why set the
langattribute on<html>?