- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - scope Attribute
The scope is an HTML attribute that is used to define the header cell. It is used for the header row, column, colgroup, or rowgroup.
The <th> element specifies a cell as the header of a group of table cells. The scope and headers attributes specify the nature of this group.
If the scope attribute is not defined or its value for row, col, rowgroup, or colgroup, then browsers automatically select the group of cells to which the header cell applies.
Syntax
Following is the syntax of the scope attribute −
<th scope=" col | row | colgroup | rowgroup " >
Attribute values
- row − the header relates to all cells of the row it belongs to.
- col − the header relates to all cells of the column it belongs to.
- rowgroup − the header belongs to a rowgroup and relates to all of its cells.
- colgroup − the header belongs to a colgroup and relates to all its cells.
Example
In the following example, let’s illustrate the usage of the scope attribute within the <th> tag, as follows −
<!DOCTYPE html> <html> <head> <title>HTML th scope Attribute</title> <style> td, th { border: 1px solid rgb(190, 190, 190); padding: 10px; } td { text-align: center; } tr:nth-child(even) { background-color: #eee; } th[scope='col'] { background-color: #696969; color: #fff; } th[scope='row'] { background-color: #d7d9f2; } caption { padding: 10px; caption-side: bottom; } table { border-collapse: collapse; border: 2px solid rgb(200, 200, 200); letter-spacing: 1px; font-family: sans-serif; font-size: 0.8rem; } </style> </head> <body> <h1 style="color: green;"> tutorials <span style="color: black">point</span> </h1> <table> <caption>Alien football stars</caption> <tr> <th scope="col">Player</th> <th scope="col">Gloobles</th> <th scope="col">Za'taak</th> </tr> <tr> <th scope="row">TR-7</th> <td>7</td> <td>4,569</td> </tr> <tr> <th scope="row">Khiresh Odo</th> <td>7</td> <td>7,223</td> </tr> <tr> <th scope="row">Mia Oolong</th> <td>9</td> <td>6,219</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up displaying the table on the webpage.
Example
Considering the another scenario, where we are going to use the scope attribute with its value col.
<!DOCTYPE html> <html> <head> <title>HTML th scope Attribute</title> </head> <body> <h1 style="color: green;"> tutorials <span style="color: black">point</span> </h1> <table border="1" width="500"> <tr> <th scope="col">Name</th> <th scope="col">Company</th> <th scope="col">Roles</th> </tr> <tr> <td>Aman</td> <td>tutorialspoint</td> <td>Technical content Engineer</td> </tr> <tr> <td>Vivek</td> <td>tutorialspoint</td> <td>Developer</td> </tr> </table> </body> </html>
When we run the above code, it will generate an output consisting of the text along with a table displayed on the webpage.
Example
Let's look into the following example, where we are going to use the two types of scope attribute one is of colgroup and another is rowgroup.
<!DOCTYPE html> <html> <head> <title>HTML th scope Attribute</title> </head> <body> <h1 style="color: green;"> tutorials <span style="color: black">point</span> </h1> <table border="1"> <tr> <th scope="colgroup">Name</th> <th scope="colgroup">Company</th> <th scope="colgroup">Roles</th> </tr> <tr> <th scope="rowgroup">Aman</th> <td>tutorialspoint</td> <td>Technical content Engineer</td> </tr> <tr> <th scope="rowgroup">Vivek</th> <td>tutorialspoint</td> <td>Developer</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up displaying the table on the webpage.
To Continue Learning Please Login
Login with Google