search

HTML Colspan

Sep 04, 2024 pm 04:47 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

HTML Colspan is the attribute used in the table for diving columns into the cell. It allows users to divide single table cells into the width of one or more either cell or column. This attribute of HTML works as a merge cell option included in the spreadsheet, same as excel. This attribute used to describe an actual number of columns divided by individual columns.

colspan table attribute used in both table elements like

and . The value we are going to define within the colspan attribute must be a positive integer number always. It was going to support attributes like textarea as well as frameset elements.

colspan attribute in HTML can be used as follows:

Syntax:

<td colspan="value">table content…</td>
  • Above syntax status that tag used to define no of the column going to span. The value attribute in the syntax is used to evaluate the count of columns that are used to fill cells.
  • The value must be a positive integer.
  • Syntax:

    <th colspan="value">table content…</th>
    • The above syntax is used when users want to use the colspan attribute with tag. It defines the number of header cells going to be span.
    • This attributed work as an inline attribute in HTML code.
    • HTML cols attribute going to support different attributes like textarea and frameset elements.
    • Syntax:

      <elementname cols="value">……………….</elementname>
      • In the above syntax, ElementName is a kind of element that is supported by the HTML element. Value is the attribute that defines multi-length value for the frameset attribute, whereas the number is for textarea.

      How to Implement Colspan in HTML?

      The code implementation of colspan in HTML is explained below.

      1. Colspan in HTML using Tag

      Code:

      
      
      <title>HTML colspan Attribute with <td> tag
      <style>
      table, th, td {
      border: 2 px solid blue;
      border-collapse: collapse;
      padding: 5px;
      text-align:left;
      }
      </style>
      
      
      <center>
      <h1 id="State-With-it-s-capital">State With it’s capital </h1>
      <h2 id="HTML-colspan-Attribute">HTML colspan Attribute</h2>
      <table>
      <tr>
      <th>State </th>
      <th>Capital </th>
      </tr>
      <tr>
      <td>Andhra Pradesh</td>
      <td>Hyderabad</td>
      </tr>
      <tr>
      <td>Bihar </td>
      <td>Patna</td>
      </tr>
      <tr>
      <td>Goa </td>
      <td>Panaji</td>
      </tr>
      <tr>
      <td>Maharashtra </td>
      <td>Mumbai </td>
      </tr>
      <tr>
      <td>Nagaland</td>
      <td>Kohima </td>
      </tr>
      <tr>
      <td>Punjab </td>
      <td>Chandigarh </td>
      </tr>
      <tr>
      <td> Gujarat</td>
      <td> Gandhinagar</td>
      </tr>
      <tr>
      <td>Haryana </td>
      <td>Chandigarh </td>
      </tr>
      <tr>
      <td colspan="2">India</td>
      </tr>
      </table>
      </center>
      
      
      <p><strong>Output:</strong></p>
      <p><img  src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172543967689731.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="HTML Colspan" ></p>
      <h4>2. Colspan in HTML using <th> Tag
      <p><strong>Code:</strong></p>
      <pre class="brush:php;toolbar:false">
      
      
      <title>HTML colspan Attribute</title>
      <style>
      table,
      th,
      td {
      border: 3px solid red;
      border-collapse: collapse;
      }
      </style>
      
      
      <center>
      <h1 id="Population">Population</h1>
      <h2>HTML colspan Attribute with <th> tag
      <table>
      <tr>
      <th colspan="2">Gender</th>
      </tr>
      <tr>
      <td>Male</td>
      <td>18</td>
      </tr>
      <tr>
      <td>Female</td>
      <td>24</td>
      </tr>
      </table>
      
      
      
      <p><strong>Output:</strong></p>
      <p><img  src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172543967913067.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="HTML Colspan" ></p>
      <h3 id="Examples-of-HTML-Colspan">Examples of HTML Colspan</h3>
      <p>Following are the different examples.</p>
      <h4 id="Example">Example #1</h4>
      <p>This example status that colspan attribute is going to use with table header along with </p>
      </th>
      <th> tag. It divides the column into 2 parts, as shown in the example below:
      <p><strong>HTML Code:</strong></p>
      <pre class="brush:php;toolbar:false">
      
      
      <style>
      table,
      th,
      td {
      border: 2px solid blue;
      border-collapse: collapse;
      padding:5px;
      }
      </style>
      
      
      

      Employee Details

      Software Hardware Marketing HR Others
      Department .NET JAVA Embedded Mechanical Indoor Outdoor Onside Offside Accounts Assets Canteen
      Head Person John Disuja Kartik Gary Sreja Divya Sandesh Krutika P. Roy Mohan Joggy
      Experience(in years) 17 12 8 7 12 11 5 9 7 12 5
      No of Teams 5 5 7 7 3 2 2 2 5 5 5
      Assigned Projects/Task 18 15 7 11 5 5 2 2 4 10 6
      No of employees 182 150 75 82 34 25 2 5 4 10 6
      Weekly standup Monday Monday Friday Friday Tuseday Tuseday Everyday Everyday Friday Friday Friday
      Appriasal Month March March March March June June March March June June June

      Output:

      HTML Colspan

      Example #2

      In this example, we are going to explain how column can be divided using colspan tag and what will the actual output by using colspan tag is going to be generated as follows:

      HTML Code:

      
      
      <title>HTML colspan Attribute</title>
      <style>
      table,
      th,
      td {
      border: 1px solid black;
      border-collapse: collapse;
      padding:8px;
      }
      </style>
      
      
      <center>
      <h1 id="Weather-in-India">Weather in India</h1>
      <table>
      <tr>
      <th> Temperature  (in degree Celsius)</th>
      </tr>
      <tr>
      <td>Agartala</td>
      <td>17</td>
      </tr>
      <tr>
      <td>Amritsar</td>
      <td>23</td>
      </tr>
      <tr>
      <td>Aurangabad</td>
      <td>26</td>
      </tr>
      <tr>
      <td>Bangalore</td>
      <td>23</td>
      </tr>
      <tr>
      <td>Bhopal</td>
      <td>13</td>
      </tr>
      <tr>
      <td>Chennai</td>
      <td>25</td>
      </tr>
      <tr>
      <td>Delhi</td>
      <td>11</td>
      </tr>
      <tr>
      <td>Haridwar</td>
      <td>8</td>
      </tr>
      <tr>
      <td>Hubbali</td>
      <td>25</td>
      </tr>
      <tr>
      <td>Indore</td>
      <td>15</td>
      </tr>
      <tr>
      <td>Kanyakumari</td>
      <td>28</td>
      </tr>
      <tr>
      <td>Katra</td>
      <td>8</td>
      </tr>
      <tr>
      <td>Mumbai</td>
      <td>26</td>
      </tr>
      <tr>
      <td colspan="2"><b>Average Temperature = 19.07</b></td>
      </tr>
      </table>
      </center>
      
      

      Output:

      HTML Colspan

      Example #3

      In this example we are going to use colspan HTML tag in both

      and tag. This attribute allows using both tags together too. Here is the code for the example, and output will generate for the same.

      HTML Code:

      
      
      <title>HTML colspan Attribute</title>
      <style>
      table,
      th,
      td {
      border: 2px solid black;
      border-collapse: collapse;
      padding:8px;
      }
      </style>
      
      
      <center>
      <h1 id="Pune-Highlights">Pune Highlights</h1>
      <table>
      <tr>
      <th colspan="2"> Famous Area in Pune</th>
      </tr>
      <tr>
      <td colspan="1">Koregaon Park</td>
      <td>Kalyani nagar</td>
      </tr>
      <tr>
      <td colspan="1">PMC</td>
      <td>PCMC</td>
      </tr>
      <tr>
      <td colspan="2">Kothrud</td>
      </tr>
      <tr>
      <td colspan="2">Chakan</td>
      </tr>
      <tr>
      <td colspan="1">Vishrantwadi</td>
      <td>Lohgaon</td>
      </tr>
      <tr>
      <td colspan="1">Hadpsar</td>
      <td>Swargate</td>
      </tr>
      <tr>
      <td colspan="1">Decan</td>
      <td>Baner</td>
      </tr>
      <tr>
      <td colspan="1">Bavdhan</td>
      <td>Wakad</td>
      </tr>
      <tr>
      <td colspan="1">Pimpri Chinchwad</td>
      <td>Akurdi</td>
      </tr>
      <tr>
      <td colspan="2">Vimannagar </td>
      </tr>
      <tr>
      <td colspan="1">Wagholi</td>
      <td>Katraj</td>
      </tr>
      <tr>
      <td colspan="1">Hinjewadi</td>
      <td>Khadkwasla</td>
      </tr>
      <tr>
      <td colspan="1">Camp</td>
      <td>Laxmi Road</td>
      </tr>
      </table>
      </center>
      
      

      Output:

      HTML Colspan

      Conclusion

      • From all the above information, we came to know that HTML colspan is the attribute that is going to be used within a table as well as text area and frameset attributes.
      • It divides the table column into one or more cells as per user requirement. This attribute is going to support both and tag. The value included in it always be a positive integer.

The above is the detailed content of HTML Colspan. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool