HTML Col Attribute - Stack Overflow

    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Explore Teams Create a free Team
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs HTML <th> col attribute Ask Question Asked 11 years, 8 months ago Modified 11 years, 8 months ago Viewed 3k times 6

I was just wondering if that by default a HTML <table> element implicitly applies the attribute scope="col" to the first group of <th> elements contained within the <thead> element?

When I render the first set of HTML below in a browser it seems to automatically detect that the <th> cells for Jan, Feb, March, April etc are headers for a column. So is it the case the scope="col" does not need adding to the markup as it will be automatically rendered this way?

<table> <caption>2009 Employee Sales by Department</caption> <thead> <tr> <th></th> <th>Jan</th> <th>Feb</th> <th>March</th> <th>April</th> <th>May</th> <th>June</th> </tr> </thead> <tbody> <tr> <th scope="row">Firefox</th> <td>37.1</td> <td>36.6</td> <td>36.3</td> <td>35.8</td> <td>35.2</td> <td>34.4</td> </tr> </tr> </tbody> </table>

This second set of markup includes scope="col" added to the tags for Jan, feb, March April etc. Is it necessary? As the example above seems to render these <th> as columns anyway without scope"col".

I am aware that the scope attribute has no visual effect in ordinary web browsers, but can be used by screen readers. So should it be added for the purpose of better semantic markup and accessibility?

<table> <caption>2009 Employee Sales by Department</caption> <thead> <tr> <th scope="col"></th> <th scope="col">Jan</th> <th scope="col">Feb</th> <th scope="col">March</th> <th scope="col">April</th> <th scope="col">May</th> <th scope="col">June</th> </tr> </thead> <tbody> <tr> <th scope="row">Firefox</th> <td>37.1</td> <td>36.6</td> <td>36.3</td> <td>35.8</td> <td>35.2</td> <td>34.4</td> </tr> </tr> </tbody> </table> Share Improve this question Follow edited Oct 16, 2012 at 8:59 user1554264 asked Oct 16, 2012 at 8:53 user1554264's user avatar user1554264user1554264 1,2143 gold badges23 silver badges50 bronze badges Add a comment |

2 Answers 2

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 4

According to the HTML5 spec, the scope attribute defaults to auto:

The scope attribute's missing value default is the auto state.

This value is characterized by

The auto state makes the header cell apply to a set of cells selected based on context.

So I assume, that screenreaders will be able to detect the context properly, which in turn means, that you do not have to explicitly define the attribute, unless you have some special instances or usecases for rowgroup and colgroup values.

Share Improve this answer Follow answered Oct 16, 2012 at 9:03 Sirko's user avatar SirkoSirko 73.6k19 gold badges152 silver badges187 bronze badges 1
  • 4 Although it's horribly unclear what "based on context" means, and the example in the spec is nowhere near as helpful as it could be, your assumption seems reasonable. +1 – Alohci Commented Oct 16, 2012 at 16:20
Add a comment | 0

You can just specify the meaning of the table more with the scope attrribute. In normal tables, i wouldn't even use it, but if your table has a meaning on your page, and people want to take it over, it would be handy to use it, especially on a reader. However, if you just add tables to do minor stuff in it, leave it out. Personally this is something you should only look into if the table becomes really expanded.

The definition is as followed:

Definition and Usage

The scope attribute specifies whether a header cell is a header for a column, row, or group of columns or rows.

this comes from the W3 website, btw.

Share Improve this answer Follow answered Oct 16, 2012 at 9:07 Dorvalla's user avatar DorvallaDorvalla 5,2124 gold badges28 silver badges46 bronze badges Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • Featured on Meta
  • We spent a sprint addressing your requests — here’s how it went
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • The [lib] tag is being burninated
  • What makes a homepage useful for logged-in users
0 Is there an equivalent of the cols attribute for tds? 1 <th> for column headers 0 Is there a row alternative for <th> in HTML? 5 How to use class attribute in html col 8 <th> for a column instead of row? 1 How to target the <td>'s that falls under <th> with a colspan? 0 How to make styles work for <col> tag? 1 Different number of TH's compared to columns in table 0 Is the <th> tag the same as <td>? 5 Why use both <thead> and <th scope="col">

Hot Network Questions

  • Dual citizenship with USA & South Africa and exited South Africa on wrong passport (USA). What passport do I use to reenter SA?
  • Recommend an essay, article, entry, author, or branch of philosophy that addresses the futility of arguing for or against free will
  • If Biden steps back or is replaced, until when must he do it?
  • Would it be moral for Danish resitance in WW2 to kill collaborators?
  • Transhumans, posthumans, and AI attacked by baseline humans
  • 11 trees in 6 rows with 4 trees in each row
  • Single-qubit quantum channel from the CNOT gate
  • Is "sinnate" a word? What does it mean?
  • Using 50 Ω coax cable instead of passive probe
  • Why are Probability Generating Functions important?
  • If the alien nest was under the primary heat exchangers, why didn't the marines just blow them up or turn them off so they freeze?
  • How to photograph the lettering on a bronze plaque?
  • "Though Fancy's casket were unlock'd to choose" in John Keats's "Lamia"
  • Interpreting interaction term
  • Different letters, different grids
  • How can one apply to graduate school if their undergraduate university is uncooperative in providing the required information?
  • Would this telescope be capable to detect Middle Ages Civilization?
  • What caused the builder to change plans midstream on this 1905 library in New England?
  • The rise and fall of oval chainrings?
  • When selling a machine with proprietary software that links against an LGPLv3 library, do I need to give the customer root access?
  • Transferring at JFK: How is passport checked if flights arrive at/depart from adjacent gates?
  • Minimum number of select-all/copy/paste steps for a string containing n copies of the original
  • What makes Python better suited to quant finance than Matlab / Octave, Julia, R and others?
  • Why are responses to an attack in a cycling race immediate?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Table Scope Col