CSS Fundamentals Questions with Answers

25 practice questions on CSS Fundamentals (HTML & CSS) with answers and step-by-step solutions. Try 10 samples below, then practise all 25 free in the AptiNest app.

Sample questions

Question 1Easy

Which symbol is used to select an id in CSS?

  1. . (dot)
  2. & (ampersand)
  3. # (hash)
  4. $ (dollar)

Answer: C. # (hash)

Explanation

#header selects the element with id="header".

Step-by-step solution

  1. #header selects the element with id="header".
  2. So the answer is: # (hash).

Why the other options are wrong

  • A. Dot selects a class.
  • B. Ampersand is not a selector.
  • D. Dollar is not a selector.

Question 2Easy

Which property changes the text colour?

  1. color
  2. font-color
  3. text-color
  4. foreground

Answer: A. color

Explanation

color sets the foreground colour of text.

Step-by-step solution

  1. color sets the foreground colour of text.
  2. So the answer is: color.

Why the other options are wrong

  • B. font-color is not valid CSS.
  • C. text-color is not valid CSS.
  • D. foreground is not valid CSS.

Question 3Easy

The language that controls how HTML elements look is written in files called

  1. Cascading Style Sheets
  2. Creative Style Sheets
  3. Computer Style Sheets
  4. Colourful Style System

Answer: A. Cascading Style Sheets

Explanation

CSS describes the look of HTML elements.

Step-by-step solution

  1. CSS describes the look of HTML elements.
  2. So the answer is: Cascading Style Sheets.

Why the other options are wrong

  • B. The "C" stands for Cascading, not Creative.
  • C. The "C" stands for Cascading, not Computer.
  • D. CSS is not a colour system.

Question 4Easy

Which symbol is used to select a class in CSS?

  1. # (hash)
  2. . (dot)
  3. * (asterisk)
  4. @ (at)

Answer: B. . (dot)

Explanation

.menu selects elements with class="menu".

Step-by-step solution

  1. .menu selects elements with class="menu".
  2. So the answer is: . (dot).

Why the other options are wrong

  • A. Hash selects an id.
  • C. Asterisk is the universal selector.
  • D. At begins an at-rule like @media.

Question 5Medium

Which pseudo-element inserts content before an element's content?

  1. ::before
  2. :first
  3. :start
  4. ::first-line

Answer: A. ::before

Explanation

::before with the content property inserts generated content.

Step-by-step solution

  1. ::before with the content property inserts generated content.
  2. So the answer is: ::before.

Why the other options are wrong

  • B. Not valid.
  • C. Not valid.
  • D. ::first-line styles the first line.

Question 6Medium

Which flexbox property aligns items along the main axis?

  1. align-items
  2. flex-wrap
  3. order
  4. justify-content

Answer: D. justify-content

Explanation

justify-content distributes items along the main axis.

Step-by-step solution

  1. justify-content distributes items along the main axis.
  2. So the answer is: justify-content.

Why the other options are wrong

  • A. align-items works on the cross axis.
  • B. flex-wrap controls wrapping.
  • C. order sets item sequence.

Question 7Medium

Which CSS rule applies different styles for different screen widths?

  1. @import
  2. @media
  3. @font-face
  4. @keyframes

Answer: B. @media

Explanation

Media queries make a layout responsive.

Step-by-step solution

  1. Media queries make a layout responsive.
  2. So the answer is: @media.

Why the other options are wrong

  • A. @import loads another stylesheet.
  • C. @font-face loads fonts.
  • D. @keyframes defines animations.

Question 8Medium

Which CSS feature creates two-dimensional layouts with rows and columns?

  1. Float
  2. Grid
  3. Inline-block
  4. Table-layout

Answer: B. Grid

Explanation

display: grid defines rows and columns.

Step-by-step solution

  1. display: grid defines rows and columns.
  2. So the answer is: Grid.

Why the other options are wrong

  • A. Float is for wrapping text around elements.
  • C. Inline-block flows inline.
  • D. Table-layout is for tables.

Question 9Hard

With box-sizing: content-box, an element has width 200px, padding 20px on each side and border 5px on each side. Its total rendered width is

  1. 200px
  2. 240px
  3. 250px
  4. 225px

Answer: C. 250px

Explanation

Total = 200 + (20 x 2) + (5 x 2) = 250px.

Step-by-step solution

  1. Total = 200 + (20 x 2) + (5 x 2) = 250px.
  2. So the answer is: 250px.

Why the other options are wrong

  • A. 200px ignores padding and border.
  • B. 240px forgets the border.
  • D. 225px counts only one side.

Question 10Hard

The specificity of the selector "#nav .item a" is written as (ids, classes, elements)

  1. (0, 1, 1)
  2. (1, 1, 1)
  3. (1, 0, 1)
  4. (1, 1, 0)

Answer: B. (1, 1, 1)

Explanation

One id (#nav), one class (.item) and one element (a) give (1, 1, 1).

Step-by-step solution

  1. One id (#nav), one class (.item) and one element (a) give (1, 1, 1).
  2. So the answer is: (1, 1, 1).

Why the other options are wrong

  • A. It includes an id.
  • C. It includes a class.
  • D. It includes an element.

Practise all 25 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all HTML & CSS topics · All topics