InterviewQs

Top 25 CSS Interview Coding Questions

Carefully curated, high-frequency CSS coding questions used in real frontend and UI/UX developer interviews.

1.Basic CSS syntax

h1 {
  color: red;
  font-size: 24px;
}

2.Apply CSS class

.box {
  width: 200px;
  height: 100px;
  background-color: blue;
}

3.Inline vs block

span {
  display: inline;
}
div {
  display: block;
}

4.Center a div using flexbox

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

5.Center a div using margin

.box {
  width: 200px;
  margin: 0 auto;
}

6.Responsive media query

@media (max-width: 768px) {
  body {
    background: lightgray;
  }
}

7.CSS box model

.box {
  padding: 10px;
  border: 2px solid black;
  margin: 15px;
}

8.Position absolute

.child {
  position: absolute;
  top: 10px;
  left: 20px;
}

9.Position relative

.parent {
  position: relative;
}

10.Z-index usage

.modal {
  position: absolute;
  z-index: 1000;
}

11.Flexbox layout

.container {
  display: flex;
  gap: 10px;
}

12.Grid layout

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

13.Hover effect

button:hover {
  background-color: black;
  color: white;
}

14.Transition effect

.box {
  transition: all 0.3s ease;
}

15.CSS animation

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.box {
  animation: fade 1s;
}

16.Hide element

.hidden {
  display: none;
}

17.Opacity vs visibility

.box1 { opacity: 0; }
.box2 { visibility: hidden; }

18.Sticky header

header {
  position: sticky;
  top: 0;
}

19.Custom font

@font-face {
  font-family: MyFont;
  src: url('font.woff');
}

20.Text center

p {
  text-align: center;
}

21.Background image

body {
  background-image: url('bg.jpg');
  background-size: cover;
}

22.CSS variables

:root {
  --main-color: blue;
}

.box {
  color: var(--main-color);
}

23.Responsive image

img {
  max-width: 100%;
  height: auto;
}

24.Overflow control

.box {
  overflow: hidden;
}

25.Cursor pointer

button {
  cursor: pointer;
}
InterviewQs – Professional Footer