wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CSS and JavaScript Quiz

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

What does the 'contain' property in CSS do?

a)

It clips the content to the container size

b)

It enables containment for performance optimizations

c)

It sets up a new stacking context

d)

It disables CSS inheritance

2.

What is the default stacking context in CSS?

a)

The root HTML element

b)

The body tag

c)

The first positioned element

d)

The first child element

3.

What happens if a flex container has `flex-wrap: wrap` and `align-content: stretch`?

a)

Lines stretch to fill the cross-axis

b)

Items stretch to fill the main axis

c)

Items collapse to fit the container

d)

All flex items stack vertically

4.

What does `isolation: isolate` do in CSS?

a)

Hides an element from the DOM

b)

Detaches from CSS inheritance

c)

Creates a new stacking context

d)

Applies a separate box model

5.

What is the specificity of the selector `div#app.container > p.text::first-letter`?

a)

1, 1, 2

b)

1, 1, 3

c)

0, 2, 3

d)

1, 2, 3

6.

Which pseudo-class only applies to form elements that have been modified?

a)

:valid

b)

:checked

c)

:target

d)

:dirty

7.

What does `all: unset` do?

a)

Resets all inheritable and non-inheritable properties

b)

Removes only inherited styles

c)

Removes inline styles

d)

Applies default browser styles

8.

In CSS Grid, what does `grid-auto-flow: dense` do?

a)

Packs grid items tightly to fill gaps

b)

Prevents item overlap

c)

Aligns items in rows

d)

Enables responsive layouts

9.

What is the difference between `em` and `rem` units?

a)

`em` is relative to parent, `rem` to root

b)

`rem` is always larger

c)

`em` only works in body

d)

They are always equal

10.

What does `clip-path: polygon(...)` allow?

a)

Crops images into rectangles

b)

Applies a mask

c)

Creates custom shapes

d)

Applies a border-radius

11.

What will `position: sticky` require to work?

a)

`top` must be set and `overflow: hidden` on parent

b)

The element must be inside a table

c)

A defined `top` and scrollable ancestor

d)

A z-index value

12.

What is the effect of `pointer-events: none`?

a)

Disables hover styles

b)

Makes element not clickable

c)

Applies only to SVGs

d)

Element ignores all mouse interactions

13.

What happens when you use `calc(100% - 10px)` in width?

a)

Throws a syntax error

b)

Calculates at runtime based on parent size

c)

Sets the width to 90px

d)

Works only in Chrome

14.

Which media feature allows checking if user prefers reduced motion?

a)

(device-width: 1000px)

b)

(prefers-color-scheme)

c)

(prefers-reduced-motion)

d)

(update-frequency)

15.

What is `backdrop-filter` used for?

a)

To add gradients

b)

To render shadows

c)

To apply filters behind an element

d)

To mask images

16.

What is the `overscroll-behavior` property used for?

a)

To control scroll chaining

b)

To disable scrolling

c)

To detect scroll velocity

d)

To set smooth scrolling

17.

Which CSS feature allows styling based on light/dark mode?

a)

`@style-mode`

b)

`@media theme`

c)

`@media (prefers-color-scheme)`

d)

`@media (theme-color)`

18.

What is `accent-color` in CSS?

a)

Applies to backgrounds

b)

Controls animation colors

c)

Applies to form elements like checkboxes

d)

Used in media queries

19.

What will `aspect-ratio: 1 / 1` do?

a)

Forces a square box

b)

Makes height twice the width

c)

Applies only to images

d)

Applies only to flex items

20.

What does `:has()` pseudo-class allow?

a)

Selecting parents of elements

b)

Style based on hover

c)

Select parent if it contains a specific child

d)

Apply styles after transition

21.

What is the output of this code? console.log(typeof NaN);

a)

number

b)

"number"

c)

"NaN"

d)

undefined

22.

Which method converts a JSON string into a JavaScript object?

a)

JSON.stringify()

b)

JSON.parse()

c)

JSON.objectify()

d)

JSON.toObject()

23.

What will this output? console.log("5" + 2);

a)

"52"

b)

7

c)

NaN

d)

Error

24.

What does the === operator check?

a)

Only value

b)

Value and type

c)

Only type

d)

Nothing, it's assignment

25.

What is the result of: console.log(Boolean(""));

a)

true

b)

false

c)

"false"

d)

Error

26.

Which of the following is a correct way to declare a function?

a)

function = myFunc() {}

b)

def myFunc() {}

c)

function myFunc() {}

d)

let myFunc: function {}

27.

What is the correct way to write an arrow function with one parameter x that returns x * 2?

a)

(x) => { return x * 2; }

b)

x => x * 2

c)

(x) -> x * 2

d)

function(x) => x * 2

28.

Which array method adds an element to the end?

a)

shift()

b)

push()

c)

pop()

d)

unshift()

29.

What is the result of this? [1, 2, 3].length

a)

3

b)

2

c)

1

d)

undefined

30.

What keyword is used to declare a constant in JavaScript?

a)

static

b)

const

c)

let

d)

final

31.

What is the default return value of a function that doesn't return anything?

a)

undefined

b)

null

c)

""

d)

0

32.

How can you stop a loop immediately?

a)

stop;

b)

break;

c)

return;

d)

exit();

33.

What will this print? console.log(typeof []);

a)

"object"

b)

"array"

c)

"list"

d)

"undefined"

34.

Which method removes the first element of an array?

a)

shift()

b)

pop()

c)

slice()

d)

splice()

35.

Which of these is NOT a primitive type in JavaScript?

a)

string

b)

boolean

c)

array

d)

number

36.

What does the setTimeout function do?

a)

Delays a function call forever

b)

Calls a function after a set time

c)

Repeats a function forever

d)

Stops code execution

37.

How do you create a JavaScript object?

a)

let obj = { name: "John", age: 30 };

b)

let obj = (name: "John", age: 30);

c)

let obj = [name = "John", age = 30];

d)

let obj = ;

38.

Which of the following is falsy?

a)

""

b)

"false"

c)

[]

d)

{}

39.

What will this return? typeof undefined

a)

"undefined"

b)

"null"

c)

"object"

d)

Error

40.

How can you check if a variable x is not equal to 5?

a)

x !== 5

b)

x =! 5

c)

x = 5

d)

x !=== 5

41.

What does `display: flex` do?

a)

Hides the element

b)

Enables flexbox layout

c)

Creates grid columns

d)

Floats the element

42.

Which property changes the text color of an element?

a)

background-color

b)

border-color

c)

color

d)

font-color

43.

What is the result of `margin: 10px 20px;`?

a)

10px top & bottom, 20px left & right

b)

10px all sides

c)

20px top & bottom, 10px left & right

d)

Only top margin is 10px

44.

Which unit is relative to the font size of the root element?

a)

em

b)

rem

c)

%

d)

px

45.

What does `position: relative` do?

a)

Positions the element relative to its normal position

b)

Fixes it to the screen

c)

Removes it from the document flow

d)

Makes it stack behind all elements

46.

Which value of `z-index` will make an element appear on top?

a)

0

b)

-1

c)

1

d)

A higher positive number

47.

How do you center an element horizontally using flexbox?

a)

text-align: center;

b)

justify-content: center;

c)

align-items: center;

d)

margin: auto;

48.

What does `overflow: hidden` do?

a)

Hides content that overflows the box

b)

Scrolls content automatically

c)

Makes box invisible

d)

Disables overflow detection

49.

What is the correct syntax for a class selector in CSS?

a)

#classname

b)

.classname

c)

classname

d)

:classname

50.

What does the `:hover` pseudo-class do?

a)

Applies styles when the user hovers over an element

b)

Animates the element

c)

Detects clicks

d)

Applies style to visited links

51.

Which CSS property changes the background image of an element?

a)

image

b)

src

c)

background-image

d)

content

52.

How do you make text bold in CSS?

a)

font-weight: normal;

b)

font-weight: bold;

c)

font-style: bold;

d)

text-style: bold;

53.

Which property controls the space between lines of text?

a)

A. letter-spacing

b)

B. line-height

c)

C. word-spacing

d)

D. text-indent

54.

What does `box-sizing: border-box;` do?

a)

A. Includes padding and border in the total width and height

b)

Ignores padding

c)

Removes border

d)

Sets default box model

55.

Which of these properties sets the size of the text?

a)

A. font-style

b)

B. font-weight

c)

C. font-size

d)

D. font-family

56.

How can you apply the same style to multiple classes?

a)

A. .class1, .class2 { ... }

b)

B. .class1 .class2 { ... }

c)

C. #class1.class2 { ... }

d)

D. .class1 & .class2 { ... }

57.

What does `max-width: 100%` do?

a)

A. Forces image to always be 100px wide

b)

B. Prevents element from exceeding container width

c)

Breaks layout

d)

Centers element

58.

What will `visibility: hidden` do?

a)

A. Removes the element

b)

B. Hides and disables the element

c)

C. Hides it but still takes up space

d)

D. Collapses the layout

59.

Which property adds space inside the border of an element?

a)

A. margin

b)

B. spacing

c)

C. padding

d)

D. indent

60.

Which of these creates a media query for screens smaller than 600px?

a)

A. @media screen > 600px

b)

B. @media screen and (min-width: 600px)

c)

C. @media screen and (max-width: 600px)

d)

D. @media (width: <600px)