Friday, May 2, 2025

25 multiple-choice questions (MCQs) covering HTML, CSS, and JavaScript for practice

 Here are 25 multiple-choice questions (MCQs) covering HTML, CSS, and JavaScript for practice:


HTML Questions (1-8)

  1. What does HTML stand for?
    a) Hyper Text Markup Language
    b) High Tech Markup Language
    c) Hyperlinks and Text Markup Language
    d) Home Tool Markup Language
    Answer: a) Hyper Text Markup Language

  2. Which tag is used to define an unordered list in HTML?
    a) <ol>
    b) <ul>
    c) <li>
    d) <list>
    Answer: b) <ul>

  3. What is the correct HTML element for inserting a line break?
    a) <break>
    b) <lb>
    c) <br>
    d) <line>
    Answer: c) <br>

  4. Which attribute is used to specify a unique ID for an HTML element?
    a) class
    b) id
    c) name
    d) type
    Answer: b) id

  5. Which HTML5 element is used for playing video files?
    a) <media>
    b) <video>
    c) <movie>
    d) <play>
    Answer: b) <video>

  6. What is the purpose of the <meta> tag in HTML?
    a) To define a paragraph
    b) To store data for server-side use
    c) To provide metadata about the document
    d) To create a hyperlink
    Answer: c) To provide metadata about the document

  7. Which HTML tag is used to define a table row?
    a) <tr>
    b) <td>
    c) <th>
    d) <table>
    Answer: a) <tr>

  8. What does the alt attribute in an <img> tag do?
    a) Sets the image alignment
    b) Provides alternative text if the image fails to load
    c) Defines the image source
    d) Specifies image dimensions
    Answer: b) Provides alternative text if the image fails to load


CSS Questions (9-16)

  1. What does CSS stand for?
    a) Computer Style Sheets
    b) Creative Style Sheets
    c) Cascading Style Sheets
    d) Colorful Style Sheets
    Answer: c) Cascading Style Sheets

  2. Which property is used to change the text color of an element?
    a) font-color
    b) text-color
    c) color
    d) text-style
    Answer: c) color

  3. How do you select an element with the ID "header" in CSS?
    a) #header
    b) .header
    c) header
    d) *header
    Answer: a) #header

  4. Which CSS property controls the space between elements' borders?
    a) padding
    b) margin
    c) spacing
    d) border-space
    Answer: b) margin

  5. What is the default value of the position property in CSS?
    a) fixed
    b) absolute
    c) relative
    d) static
    Answer: d) static

  6. Which CSS property is used to make text bold?
    a) font-weight
    b) text-bold
    c) bold
    d) font-style
    Answer: a) font-weight

  7. How do you apply a style to all <p> elements inside a <div>?
    a) div + p
    b) div.p
    c) div p
    d) div > p
    Answer: c) div p

  8. Which CSS property is used to add rounded corners?
    a) border-radius
    b) corner-radius
    c) round-corner
    d) border-style
    Answer: a) border-radius


JavaScript Questions (17-25)

  1. Which keyword is used to declare a variable in JavaScript?
    a) var
    b) let
    c) const
    d) All of the above
    Answer: d) All of the above

  2. What will console.log(typeof 42) output?
    a) "number"
    b) "string"
    c) "integer"
    d) "float"
    Answer: a) "number"

  3. Which method adds an element to the end of an array?
    a) array.push()
    b) array.pop()
    c) array.shift()
    d) array.unshift()
    Answer: a) array.push()

  4. What does the === operator check?
    a) Value only
    b) Value and type
    c) Type only
    d) Neither
    Answer: b) Value and type

  5. How do you write an if statement in JavaScript?
    a) if (x == 5)
    b) if x = 5
    c) if x == 5 then
    d) if x === 5
    Answer: a) if (x == 5)

  6. What is the output of "5" + 2 in JavaScript?
    a) 7
    b) "52"
    c) Error
    d) "7"
    Answer: b) "52" (string concatenation)

  7. Which event occurs when a user clicks an HTML element?
    a) onhover
    b) onclick
    c) onchange
    d) onload
    Answer: b) onclick

  8. What does document.getElementById("demo") do?
    a) Gets an element with class "demo"
    b) Gets an element with ID "demo"
    c) Gets all elements with tag "demo"
    d) None of the above
    Answer: b) Gets an element with ID "demo"

  9. How do you declare a function in JavaScript?
    a) function myFunction() {}
    b) def myFunction() {}
    c) func myFunction() {}
    d) function = myFunction() {}
    Answer: a) function myFunction() {}


These questions cover fundamental concepts in HTML, CSS, and JavaScript and are great for practice!

No comments:

Post a Comment