Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

HTML Table Colgroup

Posted on March 4, 2023April 1, 2023 By shani No Comments on HTML Table Colgroup

The HTML colgroup element is used to group a set of one or more columns in an HTML table. It is often used in conjunction with the col element to define properties that apply to multiple columns.

The colgroup element is a container element that is placed within the table element, before the thead, tbody, or tfoot element(s). It can contain one or more col elements, which define the properties for each column in the group.

Here’s an example of how to use the colgroup element to set the width and background color of two columns in a table:

<table>
  <colgroup>
    <col style="width: 50px; background-color: #f2f2f2;">
    <col style="background-color: #fff;">
  </colgroup>
  <tr>
    <td>Column 1</td>
    <td>Column 2</td>
  </tr>
</table>

In this example, the colgroup element contains two col elements. The first col element sets the width to 50 pixels and the background color to #f2f2f2, while the second col element sets the background color to #fff. These properties are applied to the first and second columns of the table, respectively.

You can also use the span attribute on a col element to specify the number of columns it should span. For example:

<table>
  <colgroup>
    <col style="width: 50px; background-color: #f2f2f2;">
    <col span="2" style="background-color: #fff;">
  </colgroup>
  <tr>
    <td>Column 1</td>
    <td>Column 2</td>
    <td>Column 3</td>
  </tr>
</table>

In this example, the second col element has a span attribute of 2, which means it spans two columns. This causes the background color to be applied to the second and third columns of the table.

HTML

Post navigation

Previous Post: HTML Table Styling
Next Post: HTML List

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

HTML Tutorial

  • HTML History
  • HTML Editors
  • What is an HTML Element?
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Styles
  • HTML Text Formatting
  • HTML Quotation and Citation Elements
  • HTML Comments
  • HTML Colors
  • HTML Styles – CSS
  • HTML Links
  • HTML images
  • HTML Favicon
  • HTML Tables
    • HTML Table Colgroup
    • HTML Table Colspan and Rowspan
    • HTML Table Headers
    • HTML Table Padding and Spacing
    • HTML Table Sizes
    • HTML Table Styling
  • HTML List
  • HTML Ordered Lists
  • HTML Unordered List
  • HTML other lists
  • HTML Block and Inline Elements
  • HTML class Attribute
  • HTML id Attribute
  • HTML Iframes
  • HTML JavaScript
  • HTML File Paths
  • HTML – The Head Element
  • HTML Layout Elements and Techniques
  • HTML Responsive Web Design
  • HTML Computer Code Elements
  • HTML Semantic Elements
  • HTML Style Guide
  • HTML Entities
  • HTML Symbols
  • HTML Emojis
  • HTML Encoding (Character Sets)
  • HTML Uniform Resource Locators(URL)
  • HTML Versus XHTML
  • HTML Forms
  • HTML Form Attributes
  • HTML Form Elements
  • HTML Form Target Attribute
  • HTML Input Attributes
  • HTML Input form Attributes
  • HTML Input Types
  • HTML Canvas Graphics
  • HTML SVG Graphics
  • HTML Multimedia
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML YouTube Videos
  • HTML Geolocation API
  • HTML Drag and Drop API
  • HTML Web Storage API
  • HTML Web Workers API
  • HTML SSE API
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme