search
HomeWeb Front-endHTML TutorialWhat are the HTML table attributes? Summary of 10 basic attributes of HTML tables

HTML table attribute settings are widely used in HTML web pages and are also crucial. Therefore, in this next article, I will share with you a summary of the 10 basic attributes of HTML tables. Let’s look at them below. Take a look at the introduction and specific codes of these 10 table attributes.

1. HTML table attribute


is used to define HTML tables. It has the local attribute border to represent the border. The value of the border attribute must be 1 or the empty string (""). This attribute does not control the style of the border, but is controlled by CSS

table elements can have tr, th, td, thead, tbody, tfoot, colgroup elements

table tags The basic attributes are as follows:

border: The possible values ​​are 1 and 0, 1 means there is a border, and 0 means there is no border.

bordercolor: You can set the color of the border, the value is the color value.

bgcolor: Set the background color of the table

background: Set the background image

2, html tr attribute

Used to define a row of the table. Since HTML tables are row-oriented, each row must be represented separately.

tr elements can be used within table, thead, tbody and tfoot elements.

tr elements can contain one or more tds. Or th element

its align, bgcolor and other attributes are obsolete. If you want to set attributes, please use CSS settings

3, HTML td attribute

Used to define the header of the table and the wrapper of the header. You can define one or more rows, which are column labels of the table element

Without thead element, all tr ​​are assumed to belong to the main body of the table

6, HTML tbody attribute

Used to define the body of the table

7, HTML tfoot attribute

Used to define the footer of the marked table

Note:

##, tags must have the tag inside

and tags are placed in

Used to define table cells, which can be used with colspan, rowspan, and headers local attributes

(1) colspan: column span, this attribute specifies the number of columns that the cell can span. The value of the attribute must be an integer

 (2)rowspan: row span, this attribute specifies the number of rows that the cell can span, the value of this attribute must be an integer

 (3)headers : The value of this attribute is the ID attribute value of one or more cells, associates the cells with column headers, and can be used with screen readers

Note:Each table must contain The above three elements

4. The html th attribute

is used to define the title cell, allowing us to effectively distinguish data and its description

It has the same local attributes as the

element. The difference between the two is as follows:

represents the header tag, usually located in the first row or column. Moreover, the text in will be bolded by default, but will not.

is a data mark, indicating the specific data of the cell

The valign attribute can be set to th and td, and can take the value Top or Bottom.

callpadding: the distance between the content and the cell border

cellspacing: preventing the text from exceeding the border

If you want to make the cell cross rows or columns, use the attributes colspan and rowspan .

5. HTML thead attribute

Whichever position within the label will be determined to be the head and bottom of the table respectively.

can appear before or after or .

Before html5, the
element must appear before the element. In html5, the element can be placed on the or the last element. Behind


8, html colgroup attribute

is used to define table column groups, which can be used to style Applied to a certain column, of course you can also use the col element

mentioned below. The
with the local attribute span indicates the number of columns that the column group should span. The default is one column, that is, setting the style for one column of the table

 
can contain one or more elements

9, HTML col attribute

Used to represent a single column of the table, it is recommended to use to wrap the element instead of to directly set the span attribute to define the group

 
It also has the local attribute span

.
is placed inside the element of . The instance of represents a column in the group. Use this tag to apply styles to a group of columns and a single column of the group

10, html caption attribute

Used to define the title of the table. Each table can only contain one

element

11. Example code:

<body>
    <table border="1" bordercolor="red" bgcolor="#ff4646">
        <caption>表格示例</caption>
        <tr align="center">
            <th>标题1</th>
            <th>标题2</th>
            <th>标题3</th>
        </tr>
        <tr>
            <td align="left">左</td>
            <td align="center">中</td>
            <td align="right">右</td>
        </tr>
        <tr>
            <td valign="top">top</td>
            <td>center</td>
            <td valign="bottom">bottom</td>
        </tr>
    </table>
</body>

Run result:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

##Cell across rows

<table border="1" bordercolor="#1f1fff">
       <caption>单元格的跨行</caption>
       <tr>
           <th>姓名</th>
           <th colspan="2">电话</th>
       </tr>
       <tr>
           <td>php中文网</td>
           <td>123456   654321</td>
       </tr>
   </table>

Run result:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

Cells across columns

<table border="1">
     <caption>单元格跨列</caption>
     <tr>
         <th>姓名</th>
         <th>电话</th>
     </tr>
     <tr>
         <td rowspan="2">php中文网</td>
         <td>123456</td>
     </tr>
     <tr>
         
         <td>654231</td>
     </tr>
 </table>

Run results:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

Related recommendations:

htmlTable attributes_html/css_WEB -ITnose

Detailed explanation of the frame and rules attributes of table tables in HTML

The above is the detailed content of What are the HTML table attributes? Summary of 10 basic attributes of HTML tables. 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 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.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

How to implement multi-project carousel in Bootstrap 4?How to implement multi-project carousel in Bootstrap 4?Apr 30, 2025 pm 03:24 PM

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

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 Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

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

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment