{}const=>[]async()letfn</>var
DevelopmentWeb

Frequently asked questions about HTML and CSS in interviews for front-end developer vacancies

Are you preparing for a frontend position interview? You can already imagine how you will talk about cool React hooks and TypeScript generics, but the interviewer suddenly asks: "What is the difference between inline and inline-block?" And you're like: surprised_pikachu.jpg. Let's go through the very questions that make even seniors nervously google before the interview.

К

Kodik

Author

calendar_today
schedule7 min read

Hello, future victim of a technical interview! 👋

Are you preparing for a frontend position interview? You can already imagine how you'll talk about cool React hooks and TypeScript generics, but the interviewer suddenly asks: "What is the difference between inline and inline-block?" And you're like: surprised_pikachu.jpg

Yes, yes, even in 2026, they like to go over the basics at job interviews. And you know what? That's right. Because a person who does not understand the box model, but tries to explain the virtual DOM is like a driver who does not know where the brake pedal is, but talks about quantum engines.

Let's go through the very questions that make even seniors nervously google before the interview.

1. Box Model — a classic of the genre

Question: What does a block model consist of?

Answer for the interviewer:
Each element is a layered pie of:

  • Content - the content itself

  • Padding - indentation inside the element

  • Border — frame

  • Margin - external indentation

What to say next (to look smart):
"By default, width and height apply only to content. But if you use box-sizing: border-box, the dimensions will include padding and border. This saves you from unexpected overflows and has long been the standard in CSS-reset."

Why they ask:
99% of layout bugs are when you forget about margin or padding. Or when box-sizing is not the right one.

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

2. Positioning: Static, Relative, Absolute, Fixed, Sticky

Question: What is the difference between the types of positioning?

Short answer:

  • Static — normal behavior (as if position is not specified at all)

  • Relative - displacement relative to its normal position

  • Absolute — positioning relative to the nearest positioned parent

  • Fixed — relative to the viewport (sticks when scrolling)

  • Sticky — a hybrid of relative and fixed (sticks when the point is reached)

Pitfall:
The absolute element is looking for a parent with position: relative/absolute/fixed. If it does not find it, it is positioned relative to <body>. This is the very reason why the modal sometimes flies off into space.

3. Flexbox — a favorite of all layout designers

Question: How to center a div vertically and horizontally?

Response in 2026:

.container {
  display: flex;
  justify-content: center; /* по горизонтали */
  align-items: center; /* по вертикали */
}

Additional points:
"There is also Grid with place-items: center, but flex is easier for single-axis layouts."
If someone at the interview talks about margin: 0 auto and tables, they are either stuck in 2010 or checking if you are stuck. 😄

4. Grid vs Flexbox — the eternal debate

Question: When to use Grid and when to use Flexbox?

Correct answer:

  • Flexbox — for one-dimensional layouts (row OR column)

  • Grid — for two-dimensional layouts (rows and columns simultaneously)

Example:

  • Navigation, cards in a row → Flexbox

  • Whole page layout, complex grid → Grid

5. Specificity of selectors

Question: What style will be applied?

#header .nav li { color: red; }
.nav li { color: blue; }
li { color: green; }

Answer:
Red, because the specificity is counted as (ID, Class, Tag):

  • First: (1, 1, 1) = 111

  • Second: (0, 1, 1) = 11

  • Third: (0, 0, 1) = 1

Life hack:
!important interrupts everything, but using it is like writing code on CAPS LOCK. It works technically, but everyone will look askance.

6. Semantic HTML is not just a buzzword

Question: Why do we need semantic tags?

<header>, <nav>, <article>, <section>, <footer> are not just stylish <div>.

Advantages:

  1. SEO — search engines understand the structure

  2. Accessibility - screen readers know what is where

  3. Code readability — understand what is happening faster

Anti-pattern:

<div class="header">
  <div class="nav">...</div>
</div>

It's like naming a variable var1, var2 — it works, but why?

7. Pseudoclasses vs Pseudoelements

Question: What is the difference?

Pseudo-classes (single colon):

a:hover { }
li:first-child { }
input:focus { }

Selects elements in a certain state.

Pseudo-elements (two colons):

p::before { content: "👉 "; }
p::after { content: " 👈"; }

They create virtual elements.

8. Z-index and overlay context

Question: Why is my element with z-index: 9999 still under another element?

Answer:
z-index works only within its stacking context.

Create a new context:

  • position: absolute/relative/fixed + z-index

  • opacity < 1

  • transform

  • filter

  • And about 10 more properties
    If you see z-index: 99999 in the code, know that someone desperately fought with the bug and lost.

9. Units of measurement: px, em, rem, vh, vw

Question: What difference does it make?

Cheat Sheet:

  • px - absolute pixels

  • em — relative to the font size of the parent (cascaded!)

  • rem — regarding the font size <html> (not cascaded)

  • vh/vw - percentage of viewport height/width

  • % - relative to the parent
    rem is the best choice for modern adaptive layout. Change font-size to html - everything is scaled.

10. Display: none vs Visibility: hidden vs Opacity: 0

Question: What is the difference?

Answer:

Property

Occupies space

Available for events

Animated

display: none

visibility: hidden

opacity: 0

When to use:

  • Completely remove — display: none

  • Hide and save space — visibility: hidden

  • Smooth appearance/disappearance — opacity

11. Adaptability: Media Queries

Question: How to make a website adaptive?

Basic syntax:

/* Mobile first подход */
.container { width: 100%; }

@media (min-width: 768px) {
  .container { width: 750px; }
}

@media (min-width: 1200px) {
  .container { width: 1170px; }
}

Modern trend:
Use clamp() for smooth scaling:

font-size: clamp(1rem, 2vw, 2rem);

12. CSS variables (Custom Properties)

Question: How do CSS variables work?

Example:

:root {
  --primary-color: #3498db;
  --spacing: 16px;
}

.button {
  background: var(--primary-color);
  padding: var(--spacing);
}

Advantages over Sass variables:

  • Can be changed via JavaScript

  • Support inheritance

  • Work natively in the browser

13. Vertical margin collapse

Question: Why is the margin not added between the two blocks?

Answer:
Vertical margins collapse (the larger one is taken). This is called margin collapse.

Example:

.block1 { margin-bottom: 20px; }
.block2 { margin-top: 30px; }
/* Расстояние между ними = 30px, а не 50px */

How to disable:

  • Flexbox/Grid container

  • overflow: hidden on the parent

  • padding or border on the parent

14. Inline vs Inline-block vs Block

Question: What is the difference?

Truth table:

Type

Width/Height

On a new line

Margin/padding is allowed

inline

Horizontal only

inline-block

✅ All

block

✅ All

Life example:
<span> — inline, <div> — block, and <button> by default — inline-block.

15. Pseudo-class :nth-child() and its friends

Question: How to select every third element?

Answer:

li:nth-child(3n) { /* Каждый третий */ }
li:nth-child(odd) { /* Нечетные */ }
li:nth-child(even) { /* Четные */ }
li:nth-child(3n+1) { /* 1, 4, 7, 10... */ }

Pitfall:
:nth-child() counts all neighbors, even different types. If you only need certain ones, use :nth-of-type().

🚀 And now about training (without being boring)

Okay, you've read all these questions, maybe even jotted something down. But let's be honest — in a week, half of them will fly out of your head. That's how our brain works.

Problem: Theory without practice is like watching a video on how to learn to swim. It's clear, but try not to drown.

Solution: Practice, practice, practice. And not just "open the editor and write three lines", but systematically.

Here's where you can really level up:

Code — a mobile application for learning programming, where:

  • The theory is dosed a little (without overload)

  • Immediate practice in interactive tasks

  • You can study right on your phone (on the subway, in line, anywhere)

  • Courses in Python, JavaScript, HTML/CSS and other technologies

The trick is that you don't just read "how flexbox works", but immediately create real elements. Muscle memory is formed, and at the job interview, your hands will remember the syntax themselves.

Bonus - Kodik Telegram channel — a community where we share useful posts and life hacks, discuss fresh features of languages and frameworks, and help you figure things out if something is not clear.

Conclusion: How not to screw up at the interview?

Three golden rules:

  1. Don't panic if you don't know the answer. It is better to honestly say "I'm not sure, but I suppose..." and reason logically than to talk nonsense.

  2. Practice is more important than cramming. Make pet projects, copy your favorite sites, break and fix. Doing things with your hands is the best way to remember.

  3. Understanding > Memorizing. Knowing that display: flex makes elements flex is not enough. Understanding why and when to use it is what you need.

Good luck at the interview! May the flex be with you. 🚀

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card