HTML | Width Attribute - GeeksforGeeks

Skip to content geeksforgeeks
  • Tutorials
    • Python Tutorial
      • Python Data Types
      • Python Loops and Control Flow
      • Python Data Structures
      • Python Exercises
    • Java
      • Java Programming Language
        • OOPs Concepts
      • Java Collections
      • Java Programs
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
      • System Design Tutorial
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
      • Linked List
      • Tree
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • Courses
    • DSA Courses
    • Programming Languages
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App HTML <th> width Attribute Last Updated : 12 Jan, 2024 Improve Improve Like Article Like Save Share Report

The HTML <th> width Attribute is used to specify the width of a table header cell. If the width attribute is not set then it takes the default width according to the content.

Note: It is not supported by HTML 5.

Syntax:

<th width="pixels | %">

Attribute Values:

Attributes values

Description

pixels

It sets the width of the table header cell in terms of pixels.

%

It sets the width of the table header cell in terms of percentage (%).

Example: The implementation of th width

HTML

<!DOCTYPE html> <html> <head> <title> HTML th width Attribute </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>HTML th width Attribute</h2> <table border="1" width="500"> <tr> <th width="50%">NAME</th> <th width="20%">AGE</th> <th width="30%">BRANCH</th> </tr> <tr> <td>BITTU</td> <td>22</td> <td>CSE</td> </tr> <tr> <td>RAKESH</td> <td>25</td> <td>EC</td> </tr> </table> </body> </html>

Output:

Example: The implementation of th width.

HTML

<!DOCTYPE html> <html> <head> <title>Table with th Width Attribute</title> <style> body { display: flex; justify-content: center; align-items: center; flex-direction: column; } </style> </head> <body> <h1 style="color: green;">GeeksforGeeks</h1> <table border="1"> <tr> <th width="100">Header 1</th> <th width="200">Header 2</th> <th>Header 3</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table> </body> </html>

Output:

Screenshot-2023-12-18-173919

Output

author jit_t Follow Improve Next Article HTML <td> width Attribute

Please Login to comment...

Similar Reads

HTML width/height Attribute vs CSS width/height Property In HTML 5, few elements follow the width and height attributes and maximum elements do not follow this attribute. Like img, iframe, canvas, and svg kind of elements follow the width and height attributes but div, span, article and section type of elements don't follow them.The width and height attributes are affected in img, svg tags, those are wea 3 min read Difference Between css(‘width’) and width() methods In jQuery In jQuery, we have two ways to change the width of any HTML element. The jQuery css() method and width() method, below both the methods are described properly with the example. jQuery CSS('width') Method: It is a method present in jQuery which is used to get or set the property on the matched element. It is a property used to get or set the width o 3 min read How to add Background-Color for Text Width Instead of Entire Element Width using CSS ? In this article, we will see how to add background color for the text width instead of the entire element width using CSS. The display: inline or display: inline-block property is used to set the background color of the text width. Syntax: display: inline; display: inline-block; Approach: We will create an element and then apply the display: inline 2 min read How to make a grid with two columns where 1st column has 20% of width and 2nd one 80% width in Tailwind CSS ? Tailwind CSS simplifies the process of making complex UI designs. It has a lot of predefined styles in form of classes, which can be applied to any HTML element in the code. Also, one advantage of Tailwind CSS is that during the production build, it analyzes the HTML components, and removes any unused CSS, hence decreasing the overall size of the C 4 min read What is the difference between 'width: 100%' and 'width: 100vw' in CSS ? The CSS width Property is used to set the width of the text and images. The width can be assigned to the text and images in the form of pixels(px), percentages (%), centimeters (cm), etc. The width: 100% sets an element's width relative to its containing block, making it responsive within its parent. The width: 100% responds to the container's size 1 min read HTML | &lt;iframe&gt; width Attribute The HTML &lt;iframe&gt; width attribute is used to specify the width of the &lt;iframe&gt; in terms of pixels. Syntax: &lt;iframe width="pixels"&gt; Attribute Values: It contains single value pixel which specifies the width of the iframes in terms of pixels. Below example illustrates the use of &lt;iframe&gt; width attribute in HTML: Example: C/C++ 1 min read HTML &lt;canvas&gt; width Attribute The HTML &lt;canvas&gt; width Attribute is used to specify the width of the &lt;canvas&gt; in terms of pixels. Syntax: &lt;canvas width="pixels"&gt; Attribute Values: It contains the value i.e pixels which specify the width of the canvas in terms of pixel. It has a Default value which is 300. Example: This Example illustrates the use of width attri 1 min read HTML | &lt;input&gt; width Attribute The HTML &lt;input&gt; width Attribute is used to specify the width of the &lt;input&gt; element. This Attribute is only used for input type="image". Syntax: &lt;input width="pixels"&gt; Attribute Values: It contains the value i.e pixels which specify the width of the input Element. Example: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body st 1 min read HTML | &lt;hr&gt; width Attribute The HTML &lt;hr&gt; width attribute is used to specify the width of the horizontal line in terms of pixels or percent. Syntax: &lt;hr width="pixels|%"&gt; Attribute Values: pixels: It sets the width of &lt;hr&gt; attribute in terms of pixels. %: It sets the width of &lt;hr&gt; attribute in terms of percentage (%). Note: The &lt;hr&gt; width attribu 1 min read HTML | &lt;col&gt; width Attribute The HTML &lt;col&gt; width Attribute is used to specify the width of &lt;col&gt; element. It sets the fixed width of column element. In general, the width of &lt;col&gt; element is the width needed to display its content. Syntax: &lt;col width="pixels | % | relative_length"&gt; Attribute Values: pixels: It sets the width of &lt;col&gt; attribute in 1 min read View More Articles Article Tags :
  • HTML-Attributes
  • HTML
  • Web Technologies
Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Please go through our recently updated Improvement Guidelines before submitting any improvements. This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab. You will be notified via email once the article is available for improvement. Thank you for your valuable feedback! Suggest changes Please go through our recently updated Improvement Guidelines before submitting any improvements. Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes Suggestion[CharLimit:2000] Create Improvement

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences Can't choose a topic to write? click here for suggested topics Write and publish your own Article

Từ khóa » Html Table Header Column Width