100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
HTML & CSS

Common HTML & CSS Interview Questions

A practical rundown of frequently asked HTML and CSS interview questions with clear, technically accurate answers.

Interview PrepIntermediate14 min readJul 8, 2026
Analogies

Overview

HTML and CSS interviews rarely ask you to memorize trivia; they test whether you understand how the browser actually renders and lays out a page. Interviewers repeatedly probe the same handful of concepts — the box model, specificity, layout systems, and semantic markup — because these come up daily in real front-end work. This topic collects the questions you are most likely to be asked, along with concise, accurate answers you can adapt in your own words.

🏏

Cricket analogy: Just as coaches don't quiz players on trivia but on reading the field and adjusting the line, interviewers don't ask HTML/CSS trivia but probe whether you understand how the browser actually lays out and renders a page.

Frequently Asked Questions

Q: What is the CSS box model, and what does box-sizing: border-box change about it?

The box model describes how every element's rendered size is calculated from four layers: content, padding, border, and margin. By default (content-box), width and height apply only to the content area, so padding and border are added on top, making the element visually larger than the declared width. With box-sizing: border-box, the declared width and height include padding and border, so the content area shrinks to accommodate them instead of growing the box — this makes sizing far more predictable, which is why most reset stylesheets set border-box globally.

🏏

Cricket analogy: The box model is like a batsman's protective gear: the content is the player, padding is the inner padding of the pads, the border is the outer shell, and margin is the space kept from the stumps; box-sizing: border-box keeps the total stance width fixed.

Q: How does CSS specificity work, and how is it calculated?

Specificity determines which rule wins when multiple selectors target the same element. It is calculated as a tuple of (inline styles, ID selectors, class/attribute/pseudo-class selectors, element/pseudo-element selectors). Inline styles beat any selector; an ID (#id) beats any number of classes; a class (.class), attribute ([type]), or pseudo-class (:hover) beats an element selector (div); and !important overrides normal specificity entirely (and should be avoided). When specificity ties, the rule declared later in the source wins.

🏏

Cricket analogy: Specificity is like team selection hierarchy: an ID selector is the captain's decision that overrides the coach's suggestion (class), which overrides a generic team policy (element), and !important is like a board directive that trumps everyone, best avoided.

Q: What is the difference between Flexbox and CSS Grid, and when would you use each?

Flexbox is a one-dimensional layout model — it lays items out along a single row or column and excels at distributing space, aligning items, and handling content that can wrap or reflow, such as navbars or button groups. Grid is a two-dimensional layout model that lets you define rows and columns simultaneously, making it better for full page layouts, card grids, or any design where items need to align on both axes at once. In practice, many UIs use Grid for the overall page skeleton and Flexbox for aligning content within individual components.

🏏

Cricket analogy: Flexbox arranging items in one row is like setting a batting order along a single line-up card, while Grid is like laying out the entire fielding positions on the ground in both rows and columns simultaneously.

Q: Why use semantic HTML instead of generic divs and spans?

Semantic elements (header, nav, main, article, section, aside, footer, button) describe the meaning of content, not just its appearance. This improves accessibility because screen readers use these landmarks to let users navigate a page quickly; it improves SEO because search engines weigh semantic structure when indexing content; and it improves maintainability because developers can understand a document's purpose at a glance instead of parsing a wall of unlabeled divs.

🏏

Cricket analogy: Semantic elements are like an official scorecard using labeled fields for batsman, bowler, and overs instead of a blank notebook, so anyone reading it, including a commentator relying on structure, instantly understands what each part means.

Q: What is the difference between block, inline, and inline-block elements?

Block elements (div, p, section) start on a new line, stretch to fill the available width by default, and accept width, height, and vertical margin/padding. Inline elements (span, a, strong) flow within a line of text, do not start a new line, and ignore width/height and vertical margin. Inline-block elements flow inline like text but, like block elements, accept width, height, and vertical margin/padding — useful for things like navigation links that need padding without breaking onto their own line.

🏏

Cricket analogy: Block elements are like full overs that must complete before the next begins, inline elements are like individual deliveries that flow within an over without breaking it, and inline-block is like a delivery that can be padded with extra review time yet still sits within the over.

Q: What are the possible values of the CSS position property, and how do they differ?

static is the default; the element follows normal document flow and top/left/etc. have no effect. relative positions the element relative to its own normal position, without removing it from flow. absolute removes the element from flow and positions it relative to its nearest positioned ancestor (any ancestor with a position other than static), or the viewport if none exists. fixed positions relative to the viewport and stays put during scrolling. sticky behaves like relative until a scroll threshold is crossed, then behaves like fixed within its containing block.

🏏

Cricket analogy: static is like a fielder in their default position, relative is like a fielder shifted slightly for a batsman without leaving the field, absolute is like a substitute fielder placed anywhere relative to the boundary rope (nearest positioned ancestor), fixed is like the umpire staying put regardless of play, and sticky is like a fielder who holds position until the ball crosses a line, then chases it.

Q: What is the difference between em, rem, %, px, and viewport units?

px is an absolute unit that does not scale with user font-size preferences. em is relative to the font-size of the element itself (or its parent for non-font properties), which means em values can compound unpredictably when nested. rem is relative to the root (html) element's font-size, giving consistent scaling regardless of nesting. Percentages are relative to a parent property (often width or font-size). Viewport units (vw, vh) are relative to the viewport's width or height, useful for full-screen sections or fluid typography.

🏏

Cricket analogy: px is like a fixed boundary distance marked in meters regardless of ground size, em is like a batsman's stride length relative to their own height that compounds oddly when copying a teammate's stance, rem is like a distance measured against the pitch length (root) for consistency, and vw/vh are like sizing a boundary rope relative to the whole ground's dimensions.

Q: What is the CSS cascade, and how does the browser decide which style wins?

The cascade is the algorithm the browser uses to resolve conflicting rules. It considers, in order: origin and importance (user !important, author !important, author normal, user-agent default), then specificity, then source order (later rules win ties). Understanding the cascade explains why a highly specific rule declared earlier can still lose to a less specific !important rule, and why simply reordering CSS can 'fix' a style that specificity alone can't.

🏏

Cricket analogy: The cascade is like match rules precedence: ICC playing conditions (origin/importance) are checked first, then which team's specific ground rule applies (specificity), then whichever instruction was given most recently by the umpire (source order) settles any tie.

Q: What is the difference between visibility: hidden, display: none, and opacity: 0?

display: none removes the element from the layout entirely — it takes up no space and is not accessible to screen readers or keyboard focus. visibility: hidden keeps the element's space in the layout but makes it invisible and unfocusable, though it can be restored on children with visibility: visible. opacity: 0 makes the element fully transparent but keeps it in the layout, fully interactive, and focusable, which can cause invisible-but-clickable elements if not handled carefully.

🏏

Cricket analogy: display: none is like a player being dropped from the squad entirely, taking no space on the team sheet; visibility: hidden is like a player named as twelfth man, still on the sheet but not playing; opacity: 0 is like a player on the field who's been told to stand invisible but can still be tackled or interact.

Q: How would you center a div both horizontally and vertically?

The modern, most robust approach is Flexbox: set display: flex, justify-content: center, and align-items: center on the parent. Grid offers an equally concise alternative with display: grid; place-items: center. An older technique uses position: absolute with top: 50%; left: 50%; transform: translate(-50%, -50%) when the parent is positioned. Interviewers often want you to name multiple approaches and explain their trade-offs.

🏏

Cricket analogy: Centering with Flexbox's justify-content and align-items is like a fielding captain placing a fielder dead center using two simple directives, while the older absolute-positioning-with-transform trick is like manually pacing out fifty percent of the pitch and adjusting by half a fielder's width.

Q: What is a stacking context, and how does z-index actually work?

z-index only has an effect on elements with a position value other than static, and it only compares elements within the same stacking context. A new stacking context is created by properties like position with a z-index, opacity less than 1, transform, filter, or will-change. Because stacking contexts nest, a child with a very high z-index can still be visually buried beneath a sibling if its parent's stacking context is layered below that sibling's — a common source of 'z-index isn't working' bugs.

🏏

Cricket analogy: z-index only mattering within the same stacking context is like a fielder's positioning priority only applying within their own team's formation; a star fielder positioned deep in a weak formation can still be effectively 'buried' behind a rival team's stronger overall setup.

Quick Reference

  • Box model order: content → padding → border → margin.
  • box-sizing: border-box includes padding and border inside the declared width/height.
  • Specificity order: inline style > ID > class/attribute/pseudo-class > element.
  • Flexbox = one-dimensional layout; Grid = two-dimensional layout.
  • Semantic HTML improves accessibility, SEO, and maintainability.
  • Block elements start new lines and accept full box sizing; inline elements do not.
  • position: absolute is relative to the nearest positioned ancestor, not always the viewport.
  • rem scales from the root font-size; em can compound through nested elements.
  • The cascade resolves ties using origin/importance, then specificity, then source order.
  • display: none removes layout space; visibility: hidden and opacity: 0 do not.
  • z-index only compares elements within the same stacking context.
  • Flexbox or Grid with center alignment is the modern way to center content.

Key Takeaways

  • Most HTML/CSS interview questions test conceptual understanding of rendering and layout, not memorized syntax.
  • The box model and box-sizing are foundational — get comfortable explaining them precisely.
  • Know when to reach for Flexbox versus Grid and be able to justify the choice.
  • Semantic HTML and accessibility are treated as core skills, not optional extras.
  • Understanding specificity, the cascade, and stacking contexts prevents most 'CSS isn't working' debugging sessions.

Practice what you learned

Was this page helpful?

Topics covered

#HTMLCSS#HTMLCSSStudyNotes#WebDevelopment#CommonHTMLCSSInterviewQuestions#Common#HTML#CSS#Interview#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse