Tables: colspan MCQs Quiz | Class 10

This quiz covers Class X Computer Applications (Code 165), Unit 2: HTML, focusing on the Topic: Tables: colspan MCQs Quiz | Class 10, specifically covering Column spanning cells. Test your knowledge on merging table columns. Submit your answers and then download a PDF of your results for review.

Understanding `colspan`: Merging Columns in HTML Tables

HTML tables are essential for displaying tabular data. Sometimes, you need a cell to stretch across multiple columns, perhaps for a title or a category header. This is where the `colspan` attribute comes into play. It’s a powerful tool for creating more complex and visually organized table layouts.

What is `colspan`?

The `colspan` attribute, short for “column span,” is an attribute used in `` (table data) or `` (table header) tags within an HTML table. Its primary function is to define the number of columns a cell should span or occupy horizontally. This effectively merges multiple adjacent cells in the same row into a single, wider cell.

  • Purpose: To merge cells horizontally.
  • Placement: Used within `` or `` tags.
  • Value: An integer greater than or equal to 1, representing the number of columns the cell should span. The default value is 1.

How `colspan` Works

When you use `colspan=”N”` on a `` or `` cell, that cell will take up the space of `N` normal columns in that row. This means you need to reduce the number of subsequent `` or `` tags in that row by `N-1` to maintain a consistent column count across the table. If you don’t adjust the subsequent cells, your table structure might become misaligned.

Example: Basic `colspan`

Consider a simple table to display student scores with a header spanning across multiple subjects.

Student Name Subject Scores Total
Math Science
Alice 90 85 175
Bob 78 92 170

In this example, <th colspan="2">Subject Scores</th> makes the “Subject Scores” header span across the “Math” and “Science” columns. Notice how the second row of headers only needs two subject headers because the first row’s “Subject Scores” already covered two.

Key Considerations and Best Practices

  • Maintaining Table Structure: Always ensure that the total number of “logical” columns (sum of all `colspan` values + non-colspan cells) in each row remains consistent with the maximum number of columns defined by other rows. Mismatched column counts can lead to unexpected table layouts.
  • Accessibility: When using `colspan` (and `rowspan`), consider how screen readers interpret the table. Provide clear header scopes and potentially use ARIA attributes if the table structure becomes very complex, although for basic `colspan` use, it’s usually well-handled.
  • Visual Clarity: Use `colspan` to enhance the readability and organization of your data, not to create complex, unreadable designs. It’s great for grouping related data or adding general captions.
  • Responsive Design: While `colspan` structures the table, remember to apply CSS for responsive table design if your tables need to adapt to different screen sizes.

Quick Revision Points

  • `colspan` merges cells horizontally.
  • It is an attribute of `` and `` tags.
  • Its value is a number indicating how many columns the cell should span.
  • Default `colspan` value is 1 (no spanning).
  • Used to create wider cells, often for headings or categories.
  • Careful planning is needed to avoid table misalignment.

Extra Practice Questions

  1. Question: What is the HTML attribute used to merge cells vertically?
  2. Question: If a `` has `colspan=”4″`, how many individual columns does it effectively replace in its row?
  3. Question: Is `colspan=”0″` a valid declaration? Explain why or why not.
  4. Question: In a table with three columns, if the first `` in a row has `colspan=”2″`, how many more `` elements are required in that row for it to have a total of three columns?
  5. Question: Describe a scenario where using `colspan` would be beneficial in a real-world table.

Author

  • CBSE Quiz Editorial Team

    Content created and reviewed by the CBSE Quiz Editorial Team based on the latest NCERT textbooks and CBSE syllabus. Our goal is to help students practice concepts clearly, confidently, and exam-ready through well-structured MCQs and revision content.