MCQs On Class 8
Introduction to Tables
1. Which HTML tag is used to create a table?
- A) <table>
- B) <tab>
- C) <tbl>
- D) <tr>
Answer: A) <table>
2. What is the purpose of the <th> tag in an HTML table?
- A) To create a table row
- B) To define a table header cell
- C) To create a table data cell
- D) To group table rows
Answer: B) To define a table header cell
3. How can you make a table cell span across multiple columns?
- A) rowspan
- B) colspan
- C) span
- D) merge
Answer: B) colspan
4. What attribute is used to specify the number of rows a cell should span?
- A) colspan
- B) rowspan
- C) span
- D) merge
Answer: B) rowspan
5. How can you apply a border to a table in HTML?
- A) Using the border attribute in the <table> tag
- B) Using the border property in CSS
- C) Using the border attribute in the <td> tag
- D) Both A and B
Answer: D) Both A and B
6. Which CSS property is used to change the background color of table headers?
- A) background-color
- B) border-color
- C) color
- D) text-color
Answer: A) background-color
7. To ensure a table is responsive on smaller screens, which CSS property can you use?
- A) overflow: hidden;
- B) display: block;
- C) overflow-x: auto;
- D) display: none;
Answer: C) overflow-x: auto;
8. What does the rowspan attribute do in an HTML table?
- A) Merges multiple columns into one
- B) Merges multiple rows into one
- C) Adds a border to the cell
- D) Specifies the width of the cell
Answer: B) Merges multiple rows into one
9. How do you add spacing within table cells?
- A) Using the padding property in CSS
- B) Using the spacing attribute in the <td> tag
- C) Using the margin property in CSS
- D) Using the cellspacing attribute in the <table> tag
Answer: A) Using the padding property in CSS
10. Which HTML tag is used to define a row in a table?
- A) <tr>
- B) <td>
- C) <th>
- D) <table>
Answer: A) <tr>
11. What is the default border style of a table when no CSS is applied?
- A) Solid
- B) Dashed
- C) None
- D) Double
Answer: C) None
12. Which tag is used to group a set of table rows in HTML?
- A) <thead>
- B) <tfoot>
- C) <tbody>
- D) <tr>
Answer: C) <tbody>
13. How do you center-align text within a table cell using CSS?
- A) text-align: center;
- B) vertical-align: center;
- C) align: center;
- D) center: true;
Answer: A) text-align: center;
14. What does the border-collapse: collapse; CSS property do?
- A) Merges the borders of adjacent table cells
- B) Adds space between table cells
- C) Hides table borders
- D) Applies a border to table headers
Answer: A) Merges the borders of adjacent table cells
15. Which HTML attribute allows you to add a caption to a table?
- A) caption
- B) <caption>
- C) title
- D) header
Answer: B) <caption>
16. Which HTML element is used to add a caption to a table?
- A) <header>
- B) <caption>
- C) <footer>
- D) <summary>
Answer: B) <caption>
17. What attribute is used to specify the width of a table cell in HTML?
- A) width
- B) size
- C) length
- D) dimension
Answer: A) width
18. In an HTML table, which tag is used to define a data cell?
- A) <th>
- B) <tr>
- C) <td>
- D) <thead>
Answer: C) <td>
19. Which attribute would you use to merge two or more columns in an HTML table cell?
- A) colspan
- B) rowspan
- C) merge
- D) span
Answer: A) colspan
20. What CSS property is used to set the border style of a table?
- A) border-style
- B) border-color
- C) border-width
- D) border
Answer: D) border
21. How do you add space between the cells of an HTML table using HTML attributes?
- A) cellpadding
- B) spacing
- C) margin
- D) padding
Answer: A) cellpadding
22. Which CSS property is used to align the content of table cells vertically?
- A) vertical-align
- B) align
- C) text-align
- D) justify-content
Answer: A) vertical-align
23. How can you ensure that a table header row is always visible at the top when scrolling through a long table?
- A) Use position: sticky; with top: 0; on the <th> elements.
- B) Use overflow: scroll; on the <table> element.
- C) Add a <thead> element and use position: fixed; on it.
- D) Add JavaScript to lock the header position.
Answer: A) Use position: sticky; with top: 0; on the <th> elements.
24. Which tag is used to define the footer section of an HTML table?
- A) <tfoot>
- B) <tfoot>
- C) <tfoot>
- D) <footer>
Answer: A) <tfoot>
25. How can you create a table with alternate row colors for better readability?
- A) Use the nth-child pseudo-class in CSS
- B) Add background colors manually to each row
- C) Use the alternate attribute in the <tr> tag
- D) Apply the striped class to the table
Answer: A) Use the nth-child pseudo-class in CSS
26. In an HTML table, what does the scope attribute in the <th> tag define?
- A) The number of columns the header should span
- B) The number of rows the header should span
- C) The type of content (row or column) the header applies to
- D) The alignment of the header content
Answer: C) The type of content (row or column) the header applies to
27. What attribute is used to specify the amount of space between the table cells?
- A) cellpadding
- B) cellspacing
- C) spacing
- D) border-spacing
Answer: B) cellspacing
28. Which HTML tag defines the body section of a table?
- A) <tbody>
- B) <tfoot>
- C) <thead>
- D) <tr>
Answer: A) <tbody>
29. What does the border-collapse: separate; CSS property do?
- A) Collapses the borders of adjacent cells into a single border
- B) Adds space between the borders of adjacent cells
- C) Hides all borders in the table
- D) Adds a border to the entire table
Answer: B) Adds space between the borders of adjacent cells
30. Which attribute specifies the alignment of text within a table cell?
- A) align
- B) text-align
- C) vertical-align
- D) justify
Answer: B) text-align
31. What is the purpose of the <thead> tag in an HTML table?
- A) To define the body section of the table
- B) To group header content in the table
- C) To define the footer section of the table
- D) To group table rows
Answer: B) To group header content in the table
32. How can you set the width of a table in HTML using CSS?
- A) table-width
- B) table-size
- C) width
- D) table-layout
Answer: C) width
33. Which CSS property is used to set the spacing between cells in a table?
- A) cell-spacing
- B) border-spacing
- C) cell-padding
- D) border-width
Answer: B) border-spacing
34. How can you apply different background colors to alternating rows of a table using CSS?
- A) Use nth-of-type selector
- B) Use nth-child selector
- C) Apply inline styles to each row
- D) Use nth-row selector
Answer: B) Use nth-child selector
35. What is the effect of using border-collapse: collapse; in CSS for tables?
- A) Separates the borders of adjacent cells
- B) Hides the borders of the table
- C) Collapses the borders of adjacent cells into a single border
- D) Applies a solid border to the entire table
Answer: C) Collapses the borders of adjacent cells into a single border
36. How can you add a border to a specific table cell in HTML using CSS?
- A) Apply border property to the <td> or <th> tag
- B) Use cell-border property in CSS
- C) Apply border property to the <table> tag
- D) Use cell-padding property in CSS
Answer: A) Apply border property to the <td> or <th> tag
37. Which CSS property allows you to control the alignment of content in table cells horizontally?
- A) align
- B) vertical-align
- C) text-align
- D) content-align
Answer: C) text-align
38. What does the colspan attribute do in an HTML table?
- A) Merges multiple rows into one
- B) Sets the alignment of a cell
- C) Merges multiple columns into one
- D) Sets the width of a column
Answer: C) Merges multiple columns into one
39. How do you make a table responsive on small screens using CSS?
- A) Use overflow-x: auto; on the table
- B) Use display: flex; on the table
- C) Use width: 100%; on the table
- D) Use position: relative; on the table
Answer: A) Use overflow-x: auto; on the table
40. What does the align attribute do in an HTML table?
- A) Aligns the table itself within the page
- B) Aligns the content within table cells
- C) Aligns the table header
- D) Aligns the borders of the table
Answer: B) Aligns the content within table cells
41. Which attribute can be used to provide a summary of a table's content for accessibility?
- A) alt
- B) summary
- C) title
- D) description
Answer: B) summary
42. What CSS property is used to set the color of the table borders?
- A) border-color
- B) border-style
- C) border-width
- D) border
Answer: A) border-color
43. Which HTML element defines a single row of cells in a table?
- A) <td>
- B) <th>
- C) <tr>
- D) <tfoot>
Answer: C) <tr>
44. How can you center-align a table within its container using CSS?
- A) text-align: center;
- B) margin: auto;
- C) align: center;
- D) display: block;
Answer: B) margin: auto;
45. Which HTML tag is used to group the footer content of a table?
- A) <tfoot>
- B) <tfoot>
- C) <footer>
- D) <tfoot>
Answer: A) <tfoot>
46. What does the border-spacing CSS property control?
- A) The width of the table border
- B) The spacing between the borders of adjacent cells
- C) The space between the content and the cell border
- D) The width of the table itself
Answer: B) The spacing between the borders of adjacent cells
47. Which CSS property can be used to set the height of a table row?
- A) row-height
- B) height
- C) line-height
- D) row-span
Answer: B) height
48. How can you apply a border to all the cells in a table using CSS?
- A) Apply the border property to the <table> element
- B) Apply the border property to the <tr> element
- C) Apply the border property to the <td> and <th> elements
- D) Apply the border property to the <thead> element
Answer: C) Apply the border property to the <td> and <th> elements
49. What is the default value for the border-collapse CSS property?
- A) separate
- B) collapse
- C) none
- D) hidden
Answer: A) separate
50. Which attribute specifies the alignment of the table on the page?
- A) align
- B) justify
- C) text-align
- D) margin
Answer: A) align
51. How can you add a caption to a table in HTML?
- A) Add a <caption> element directly inside the <table> element
- B) Add a <header> element directly inside the <table> element
- C) Use a <figcaption> element with a <figure> tag surrounding the table
- D) Use the title attribute on the <table> tag
Answer: A) Add a <caption> element directly inside the <table> element
52. What is the effect of the empty-cells CSS property?
- A) Hides empty cells in a table
- B) Adds a border around empty cells
- C) Sets the color of empty cells
- D) Defines the width of empty cells
Answer: A) Hides empty cells in a table
53. Which CSS property controls the width of a table column?
- A) width
- B) column-width
- C) table-width
- D) cell-width
Answer: A) width
54. How do you align the content of a table cell vertically to the top using CSS?
- A) vertical-align: top;
- B) text-align: top;
- C) align-items: flex-start;
- D) justify-content: flex-start;
Answer: A) vertical-align: top;
55. Which HTML tag is used to define a table header row?
- A) <tr>
- B) <thead>
- C) <th>
- D) <tfoot>
Answer: B) <thead>
56. What is the purpose of the colgroup element in HTML tables?
- A) To group columns for styling and layout purposes
- B) To group rows in the table
- C) To define the table header
- D) To create a table footer
Answer: A) To group columns for styling and layout purposes
57. How do you merge two or more rows in an HTML table cell?
- A) Use the colspan attribute
- B) Use the rowspan attribute
- C) Use the merge attribute
- D) Use the span attribute
Answer: B) Use the rowspan attribute
58. Which CSS property is used to add space inside table cells, between the content and the border?
- A) padding
- B) margin
- C) border-spacing
- D) cell-spacing
Answer: A) padding
59. How do you ensure that a table’s width adjusts to fit its content?
- A) Set table-layout: fixed;
- B) Set table-layout: auto;
- C) Set width: auto;
- D) Set width: 100%;
Answer: B) Set table-layout: auto;
60. What is the default alignment of text in a table cell?
- A) Left
- B) Right
- C) Center
- D) Justify
Answer: A) Left
61. Which attribute is used to define the number of columns a cell should span in an HTML table?
- A) rowspan
- B) colspan
- C) span
- D) width
Answer: B) colspan
62. How can you center-align the text in a table header using CSS?
- A) text-align: center;
- B) align: center;
- C) vertical-align: center;
- D) justify-content: center;
Answer: A) text-align: center;
63. Which element is used to define a single table cell in an HTML table?
- A) <tr>
- B) <th>
- C) <td>
- D) <tfoot>
Answer: C) <td>
64. What is the purpose of the scope attribute in the <th> element?
- A) To define the alignment of the header cell
- B) To specify whether the header cell applies to rows, columns, or groups of rows/columns
- C) To set the width of the header cell
- D) To provide additional styling for the header cell
Answer: B) To specify whether the header cell applies to rows, columns, or groups of rows/columns
65. How can you specify a table's border style using CSS?
- A) border-style
- B) border-width
- C) border-color
- D) border
Answer: A) border-style
66. Which CSS property is used to remove the default border around a table?
- A) border: none;
- B) border-width: 0;
- C) border-style: none;
- D) border-color: transparent;
Answer: A) border: none;
67. What is the effect of setting border-collapse: separate; in CSS for a table?
- A) Borders of adjacent cells are collapsed into a single border
- B) Borders of adjacent cells are kept separate
- C) Cell borders are hidden
- D) The border of the entire table is applied to each cell
Answer: B) Borders of adjacent cells are kept separate
68. Which CSS property can be used to add space between the table cells and their borders?
- A) padding
- B) margin
- C) border-spacing
- D) cell-padding
Answer: A) padding
69. How do you specify the alignment of a table cell's content vertically using CSS?
- A) align-items
- B) vertical-align
- C) text-align
- D) justify-content
Answer: B) vertical-align
70. What does the caption-side CSS property control?
- A) The position of the table caption (top or bottom of the table)
- B) The side of the table where captions should be displayed
- C) The alignment of the table caption
- D) The font size of the table caption
Answer: A) The position of the table caption (top or bottom of the table)
71. What does the table-layout: fixed; CSS property do?
- A) Allows table width to adjust based on content
- B) Sets a fixed width for the table columns
- C) Automatically adjusts column widths based on content
- D) Hides the table layout from view
Answer: B) Sets a fixed width for the table columns
72. Which attribute can be used to add a summary of a table’s purpose for screen readers?
- A) summary
- B) alt
- C) description
- D) title
Answer: A) summary
73. How can you ensure that a table does not overflow its container and maintains responsiveness?
- A) Use overflow: hidden; on the table
- B) Use max-width: 100%; on the table
- C) Use table-layout: fixed; on the table
- D) Use display: block; on the table
Answer: B) Use max-width: 100%; on the table
74. Which CSS property allows you to set the color of the text in table cells?
- A) color
- B) text-color
- C) border-color
- D) cell-color
Answer: A) color
75. How can you make a table more accessible by specifying column headers?
- A) Use the <th> element for headers
- B) Use the <caption> element
- C) Use the scope attribute in <td> elements
- D) Use the summary attribute in the <table> element
Answer: A) Use the <th> element for headers
76. Which HTML element is used to define a table footer section?
- A) <tfoot>
- B) <tfoot>
- C) <tfoot>
- D) <tfoot>
Answer: A) <tfoot>
77. What is the correct HTML tag to define a group of one or more columns in a table for formatting?
- A) <colgroup>
- B) <col>
- C) <columns>
- D) <column-group>
Answer: A) <colgroup>
78. What attribute is used to control the alignment of content in table cells?
- A) align
- B) vertical-align
- C) text-align
- D) content-align
Answer: B) vertical-align
79. How can you merge two or more cells horizontally in a table?
- A) Use the rowspan attribute
- B) Use the colspan attribute
- C) Use the merge attribute
- D) Use the span attribute
Answer: B) Use the colspan attribute
80. Which CSS property is used to set the border width of a table cell?
- A) border-width
- B) cell-border-width
- C) border-size
- D) cell-border-size
Answer: A) border-width
81. How do you center a table horizontally within its container using CSS?
- A) margin: auto;
- B) text-align: center;
- C) align: center;
- D) display: center;
Answer: A) margin: auto;
82. Which attribute of the <table> element can be used to specify whether table borders should be collapsed into a single border or kept separate?
- A) border-collapse
- B) border-style
- C) border-width
- D) border-spacing
Answer: A) border-collapse
83. Which CSS property is used to set the space between the table border and its content?
- A) padding
- B) margin
- C) border-spacing
- D) cell-padding
Answer: A) padding
84. How do you add space between the cells of a table using CSS?
- A) border-spacing
- B) padding
- C) margin
- D) cell-spacing
Answer: A) border-spacing
85. What is the purpose of the <caption> element in HTML tables?
- A) To provide a caption or title for the table
- B) To add a description to each table cell
- C) To specify the color of the table border
- D) To define a table header
Answer: A) To provide a caption or title for the table
86. Which attribute would you use to specify the height of a table cell in HTML?
- A) height
- B) cell-height
- C) row-height
- D) size
Answer: A) height
87. What is the default alignment of table cells?
- A) Left
- B) Center
- C) Right
- D) Justify
Answer: A) Left
88. How do you ensure that a table maintains its layout when the page is resized?
- A) Use table-layout: fixed;
- B) Use overflow: auto;
- C) Use display: block;
- D) Use width: 100%;
Answer: A) Use table-layout: fixed;
89. What is the effect of using border-collapse: collapse; in CSS?
- A) Borders of adjacent cells are kept separate
- B) Borders of adjacent cells are merged into a single border
- C) Cell borders are hidden
- D) The table border is applied to each cell
Answer: B) Borders of adjacent cells are merged into a single border
90. Which HTML element is used to group rows in a table?
- A) <tbody>
- B) <tr>
- C) <thead>
- D) <tfoot>
Answer: A) <tbody>
91. Which HTML element is used to define a table header?
- A) <th>
- B) <header>
- C) <thead>
- D) <h1>
Answer: A) <th>
92. What is the purpose of the scope attribute in the <th> element?
- A) To define the header cell's text color
- B) To specify the width of the header cell
- C) To indicate whether the header cell applies to a row, column, or group of rows/columns
- D) To add a caption to the header cell
Answer: C) To indicate whether the header cell applies to a row, column, or group of rows/columns
93. Which CSS property is used to set the background color of table cells?
- A) background-color
- B) cell-background
- C) bgcolor
- D) color
Answer: A) background-color
94. What attribute is used to set the border color of a table in HTML?
- A) border-color
- B) color
- C) border-style
- D) border
Answer: A) border-color
95. Which CSS property adjusts the width of table columns?
- A) column-width
- B) width
- C) cell-width
- D) border-width
Answer: B) width
96. What is the correct HTML tag to define a row in a table?
- A) <row>
- B) <tr>
- C) <td>
- D) <tbody>
Answer: B) <tr>
97. Which CSS property is used to add a border to a table cell?
- A) border
- B) cell-border
- C) border-style
- D) cell-style
Answer: A) border
98. What attribute of the <table> element specifies the distance between the table's border and the content inside?
- A) border-spacing
- B) padding
- C) cellspacing
- D) border-width
Answer: A) border-spacing
99. Which HTML element is used to group table headers?
- A) <thead>
- B) <tr>
- C) <header>
- D) <colgroup>
Answer: A) <thead>
100. How can you add space between rows in a table using CSS?
- A) margin
- B) border-spacing
- C) padding
- D) row-gap
Answer: B) border-spacing
101. What does the border-collapse: separate; CSS property do?
- A) Collapses borders of adjacent cells into a single border
- B) Keeps borders of adjacent cells separate
- C) Hides all table borders
- D) Applies a border only to the table itself
Answer: B) Keeps borders of adjacent cells separate
102. Which HTML element is used to define the bottom section of a table?
- A) <tfoot>
- B) <tbody>
- C) <tr>
- D) <tfoot>
Answer: A) <tfoot>
103. Which CSS property can you use to add padding to a table cell?
- A) padding
- B) cell-padding
- C) spacing
- D) cell-spacing
Answer: A) padding
104. What does the table-layout: auto; CSS property do?
- A) Allows the table width to adjust based on the content
- B) Sets a fixed width for the table columns
- C) Collapses table borders into a single border
- D) Specifies the height of the table
Answer: A) Allows the table width to adjust based on the content
105. Which attribute of the <table> element is used to set the alignment of the table on the page?
- A) align
- B) table-align
- C) position
- D) layout
Answer: A) align
