Home Web Front-end HTML Tutorial What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

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

Jul 27, 2018 pm 02:45 PM

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>
Copy after login

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>
Copy after login

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>
Copy after login
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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

See all articles