This collection of 100 HTML MCQs is specifically designed to assist individuals in preparing for government job tests. These multiple-choice questions cover various aspects of HTML (Hypertext Markup Language), which is fundamental for web development. By practicing these MCQs, aspiring candidates can enhance their knowledge and improve their chances of success in government job exams, fpsc test preparation that assess HTML proficiency. You can prepare of pakmcqs really well.
Read the question carefully and try to figure out the answer by looking at the options below. Decide an answer which you feel correct, and then click on "Show Answer" option to verify it.
Question 1:
What does HTML stand for?
a) Hyper Text Markup Language
b) Home Tool Markup Language
c) High-level Text Markup Language
d) Hyperlink and Text Markup Language
Show Answer
Correct Answer: a) Hyper Text Markup Language
Question 2:
What is the correct way to include an external JavaScript file?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 3:
Which CSS property is used to change the text color of an element?
a) color
b) font-color
c) text-color
d) text-style
Show Answer
Correct Answer: a) color
Question 4:
Which tag is used to create an unordered list in HTML?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 5:
What is the correct way to write a comment in JavaScript?
a) //This is a comment
b)
c) /*This is a comment*/
d)
Show Answer
Correct Answer: a) //This is a comment
Question 6:
Which of the following is NOT a valid JavaScript data type?
a) boolean
b) string
c) number
d) character
Show Answer
Correct Answer: d) character
Question 7:
What is the correct way to select an element with the id "myElement" using CSS?
a) #myElement
b) .myElement
c) $myElement
d) *myElement
Show Answer
Correct Answer: a) #myElement
Question 8:
What is the purpose of the "box-sizing" CSS property?
a) It controls the appearance of scrollbars.
b) It sets the background color of an element.
c) It adjusts the spacing between letters in a text.
d) It includes or excludes the padding and border in the total width and height of an element.
Show Answer
Correct Answer: d) It includes or excludes the padding and border in the total width and height of an element.
Question 9:
Which event is triggered when a form element loses focus?
a) onchange
b) onblur
c) onfocus
d) onsubmit
Show Answer
Correct Answer: b) onblur
Question 10:
What does CSS stand for?
a) Cascading Style Sheets
b) Creative Style Sheets
c) Computer Style Sheets
d) Colorful Style Sheets
Show Answer
Correct Answer: a) Cascading Style Sheets
Question 11:
Which HTML tag is used to define an image?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 12:
What is the correct way to add a background color to an HTML element using CSS?
a) background-color: #FF0000;
b) color: #FF0000;
c) background: #FF0000;
d) bgcolor: #FF0000;
Show Answer
Correct Answer: a) background-color: #FF0000;
Question 13:
Which CSS property is used to control the spacing between lines of text?
a) line-height
b) text-spacing
c) line-spacing
d) spacing
Show Answer
Correct Answer: a) line-height
Question 14:
What is the correct way to comment out multiple lines in CSS?
a) /* This is a comment */
b) // This is a comment //
c) // This is a comment
d)
Show Answer
Correct Answer: a) /* This is a comment */
Question 15:
Which attribute is used to specify the target URL of a link in HTML?
a) href
b) src
c) target
d) link
Show Answer
Correct Answer: a) href
Question 16:
What is the correct way to declare a variable in JavaScript?
a) var myVariable;
b) variable myVariable;
c) myVariable = var;
d) myVariable var;
Show Answer
Correct Answer: a) var myVariable;
Question 17:
What does the "typeof" operator in JavaScript do?
a) It checks if a variable is defined.
b) It determines the type of a variable.
c) It converts a value to a string.
d) It performs arithmetic operations.
Show Answer
Correct Answer: b) It determines the type of a variable.
Question 18:
What is the result of the following JavaScript expression: "5" + 2?
a) 52
b) "52"
c) 7
d) "52"
Show Answer
Correct Answer: d) "52"
Question 19:
Which built-in method removes the last element from an Array and returns that element in JavaScript?
a) pop()
b) push()
c) join()
d) shift()
Show Answer
Correct Answer: a) pop()
Question 20:
What is the output of the following JavaScript code?
console.log(2 + "2" - 1);
a) 22
b) 3
c) 21
d) NaN
Show Answer
Correct Answer: c) 21
Question 21:
Which selector targets an element with a specific id in CSS?
a) .class
b) #id
c) *element
d) element.class
Show Answer
Correct Answer: b) #id
Question 22:
What is the purpose of the CSS box-sizing property?
a) It specifies the padding of an element.
b) It specifies the width of an element.
c) It specifies the box model used for sizing an element.
d) It specifies the margin of an element.
Show Answer
Correct Answer: c) It specifies the box model used for sizing an element.
Question 23:
Which event is triggered when a user clicks on an HTML element?
a) onclick
b) onhover
c) onkeydown
d) onsubmit
Show Answer
Correct Answer: a) onclick
Question 24:
What is the purpose of the JavaScript Array map() method?
a) It adds an element to the end of an array.
b) It removes an element from an array.
c) It creates a new array by applying a function to each element of an existing array.
d) It sorts the elements of an array in alphabetical order.
Show Answer
Correct Answer: c) It creates a new array by applying a function to each element of an existing array.
Question 25:
Which method is used to retrieve the value of a cookie in JavaScript?
a) getCookie()
b) retrieveCookie()
c) readCookie()
d) document.cookie
Show Answer
Correct Answer: d) document.cookie
Question 26:
What is the purpose of the CSS property "float"?
a) It specifies the position of an element.
b) It creates a floating effect on an element.
c) It clears the floating effect on an element.
d) It aligns an element to the left or right of its container.
Show Answer
Correct Answer: d) It aligns an element to the left or right of its container.
Question 27:
Which HTML element is used to define a hyperlink?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 28:
What does the CSS property "position: fixed;" do?
a) It positions an element relative to its nearest positioned ancestor.
b) It positions an element relative to the viewport, even when the page is scrolled.
c) It positions an element absolutely within its parent container.
d) It positions an element statically in its default position.
Show Answer
Correct Answer: b) It positions an element relative to the viewport, even when the page is scrolled.
Question 29:
What is the purpose of the JavaScript Array splice() method?
a) It adds elements to the beginning of an array.
b) It removes elements from an array and optionally replaces them with new elements.
c) It reverses the order of the elements in an array.
d) It sorts the elements of an array in descending order.
Show Answer
Correct Answer: b) It removes elements from an array and optionally replaces them with new elements.
Question 30:
What is the purpose of the HTML "meta" tag?
a) It defines a section in a document.
b) It specifies the character encoding of a document.
c) It adds a line break in the content of a document.
d) It defines a clickable button in a form.
Show Answer
Correct Answer: b) It specifies the character encoding of a document.
Question 31:
Which CSS property is used to control the appearance of text within an element?
a) color
b) background-color
c) font-family
d) border
Show Answer
Correct Answer: c) font-family
Question 32:
What does the CSS property "display: none;" do?
a) It hides an element without affecting the layout of the page.
b) It removes an element from the DOM.
c) It sets an element's display to its default value.
d) It shows an element with a smooth animation.
Show Answer
Correct Answer: a) It hides an element without affecting the layout of the page.
Question 33:
What is the purpose of the JavaScript Math.random() function?
a) It generates a random number between 0 and 1.
b) It rounds a number to the nearest integer.
c) It calculates the square root of a number.
d) It returns the value of pi (π).
Show Answer
Correct Answer: a) It generates a random number between 0 and 1.
Question 34:
Which HTML element is used to define a table row?
a)
b)
c)
d)
Show Answer
Correct Answer: b)
Question 35:
Which CSS property is used to add space between the content of an element and its border?
a) padding
b) margin
c) border
d) space
Show Answer
Correct Answer: a) padding
Question 36:
What is the purpose of the JavaScript Array push() method?
a) It removes the last element from an array.
b) It adds an element to the beginning of an array.
c) It adds one or more elements to the end of an array.
d) It reverses the order of the elements in an array.
Show Answer
Correct Answer: c) It adds one or more elements to the end of an array.
Question 37:
What does the CSS property "text-align: center;" do?
a) It aligns an element to the left of its container.
b) It aligns an element to the right of its container.
c) It aligns an element to the center of its container.
d) It aligns an element to both the left and right of its container.
Show Answer
Correct Answer: c) It aligns an element to the center of its container.
Question 38:
What is the purpose of the JavaScript typeof operator?
a) It checks if a variable is of a specific type.
b) It converts a value to a string.
c) It performs a mathematical operation.
d) It assigns a value to a variable.
Show Answer
Correct Answer: a) It checks if a variable is of a specific type.
Question 39:
Which HTML element is used to define the title of a document?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 40:
What is the purpose of the CSS "box-sizing" property?
a) It specifies the size of the content box.
b) It specifies the size of the padding box.
c) It specifies the size of the border box.
d) It specifies the size of the margin box.
Show Answer
Correct Answer: c) It specifies the size of the border box.
Question 41:
Which CSS property is used to control the spacing between lines of text?
a) line-height
b) letter-spacing
c) word-spacing
d) text-indent
Show Answer
Correct Answer: a) line-height
Question 42:
What is the purpose of the JavaScript parseFloat() function?
a) It parses a string and returns an integer.
b) It parses a string and returns a floating-point number.
c) It converts a value to a string.
d) It performs a mathematical operation.
Show Answer
Correct Answer: b) It parses a string and returns a floating-point number.
Question 43:
What is the purpose of the HTML "alt" attribute in an image tag?
a) It specifies the image source URL.
b) It defines the width of the image.
c) It provides alternative text for the image.
d) It sets the alignment of the image.
Show Answer
Correct Answer: c) It provides alternative text for the image.
Question 44:
Which JavaScript function is used to add an event listener to an element?
a) addEventListener()
b) attachEvent()
c) addEvent()
d) bindEvent()
Show Answer
Correct Answer: a) addEventListener()
Question 45:
What is the purpose of the CSS "float" property?
a) It specifies how an element should be positioned within its parent container.
b) It removes an element from the normal flow of the document.
c) It applies a clear floating behavior to an element.
d) It controls the visibility of an element.
Show Answer
Correct Answer: b) It removes an element from the normal flow of the document.
Question 46:
What does the JavaScript "this" keyword refer to?
a) It refers to the current HTML document.
b) It refers to the parent function of the current function.
c) It refers to the global object.
d) It refers to the object on which the current method is being called.
Show Answer
Correct Answer: d) It refers to the object on which the current method is being called.
Question 47:
Which HTML element is used to create a hyperlink?
a)
b)
c)
d)
Show Answer
Correct Answer: b)
Question 48:
What is the purpose of the CSS "position" property?
a) It sets the width and height of an element.
b) It specifies how an element should be positioned within its parent container.
c) It applies a clear floating behavior to an element.
d) It controls the visibility of an element.
Show Answer
Correct Answer: b) It specifies how an element should be positioned within its parent container.
Question 49:
Which JavaScript function is used to remove the first element from an array?
a) shift()
b) unshift()
c) pop()
d) push()
Show Answer
Correct Answer: a) shift()
Question 50:
What is the purpose of the HTML "target" attribute in an anchor tag?
a) It specifies the URL of the linked page.
b) It sets the alignment of the anchor tag.
c) It specifies where to open the linked page.
d) It defines the display style of the anchor tag.
Show Answer
Correct Answer: c) It specifies where to open the linked page.
Question 51:
Which CSS property is used to apply a shadow effect to an element?
a) box-shadow
b) text-shadow
c) shadow-effect
d) element-shadow
Show Answer
Correct Answer: a) box-shadow
Question 52:
What is the purpose of the JavaScript Array map() method?
a) It adds new elements to an array.
b) It removes elements from an array.
c) It creates a new array with the results of calling a provided function on every element in the original array.
d) It sorts the elements of an array.
Show Answer
Correct Answer: c) It creates a new array with the results of calling a provided function on every element in the original array.
Question 53:
Which HTML element is used to define the structure of a table?
a)
b)
c)
d)
Show Answer
Correct Answer: a)
Question 54:
Which JavaScript method is used to convert a string to uppercase letters?
a) toUpperCase()
b) toLowerCase()
c) convertToUpperCase()
d) convertToLowerCase()
Show Answer
Correct Answer: a) toUpperCase()
Question 55:
What is the purpose of the CSS "display" property?
a) It sets the width and height of an element.
b) It specifies how an element should be positioned within its parent container.
c) It controls the visibility of an element.
d) It defines the display behavior of an element.
Show Answer
Correct Answer: d) It defines the display behavior of an element.
Question 56:
Which JavaScript method is used to remove the last element from an array?
a) pop()
b) push()
c) shift()
d) unshift()
Show Answer
Correct Answer: a) pop()
Question 57:
What is the purpose of the HTML "src" attribute in an image tag?
a) It specifies the alternative text for the image.
b) It sets the source URL of the image.
c) It defines the width of the image.
d) It controls the visibility of the image.
Show Answer
Correct Answer: b) It sets the source URL of the image.
Question 58:
Which CSS property is used to change the text color of an element?
a) color
b) font-color
c) text-color
d) text-style
Show Answer
Correct Answer: a) color
Question 59:
Which JavaScript function is used to round a number to the nearest integer?
a) Math.round()
b) Math.floor()
c) Math.ceil()
d) Math.random()
Show Answer
Correct Answer: a) Math.round()
Question 60:
What is the purpose of the HTML "type" attribute in an input tag?
a) It specifies the type of input to display (e.g., text, number, email, etc.).
b) It sets the initial value of the input field.
c) It defines the width of the input field.
d) It controls the visibility of the input field.
Show Answer
Correct Answer: a) It specifies the type of input to display (e.g., text, number, email, etc.).
Question 61:
Which CSS property is used to change the background color of an element?
a) background-color
b) color
c) background
d) background-style
Show Answer
Correct Answer: a) background-color
Question 62:
What is the purpose of the JavaScript Array reduce() method?
a) It adds new elements to an array.
b) It removes elements from an array.
c) It returns the first element that satisfies a provided condition.
d) It applies a function against an accumulator and each element in the array to reduce it to a single value.
Show Answer
Correct Answer: d) It applies a function against an accumulator and each element in the array to reduce it to a single value.
Question 63:
Which HTML element is used to create a hyperlink?
a)
b)
c)
d)
Show Answer
Correct Answer: c)
Question 64:
Which JavaScript method is used to add new elements to the beginning of an array?
a) push()
b) unshift()
c) pop()
d) shift()
Show Answer
Correct Answer: b) unshift()
Question 65:
What is the purpose of the CSS "margin" property?
a) It sets the width and height of an element.
b) It specifies how an element should be positioned within its parent container.
c) It controls the visibility of an element.
d) It defines the space around an element.
Show Answer
Correct Answer: d) It defines the space around an element.
Question 66:
Which JavaScript method is used to check if an element exists in an array?
a) includes()
b) indexOf()
c) find()
d) filter()
Show Answer
Correct Answer: a) includes()
Question 67:
What is the purpose of the HTML "placeholder" attribute in an input tag?
a) It specifies the type of input to display (e.g., text, number, email, etc.).
b) It sets the initial value of the input field.
c) It defines the width of the input field.
d) It provides a hint or example text to be displayed in the input field.
Show Answer
Correct Answer: d) It provides a hint or example text to be displayed in the input field.
Question 68:
Which CSS property is used to change the font style of an element?
a) font-family
b) font-style
c) font-size
d) font-weight
Show Answer
Correct Answer: b) font-style
Question 69:
Which JavaScript method is used to remove the first element from an array?
a) pop()
b) push()
c) shift()
d) unshift()
Show Answer
Correct Answer: c) shift()
Question 70:
What is the purpose of the CSS "padding" property?
a) It sets the width and height of an element.
b) It specifies how an element should be positioned within its parent container.
c) It defines the space around an element.
d) It controls the visibility of an element.
Show Answer
Correct Answer: c) It defines the space around an element.