

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set table width in HTML?
To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width. HTML5 do not support the width attribute of <table>, so the CSS property width is used with the style attribute to set table width.
Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.
Example
You can try to run the following code to set table width in HTML. We’re also using the <style> tag and the style attribute to style the table borders
<!DOCTYPE html> <html> <head> <style> th, td { border: 1px solid black; } </style> </head> <body> <h1>Programming Languages</h1> <table style="width:100px; border: 1px solid black"> <tr> <th>Language</th> <th>Release Year</th> </tr> <tr> <td>Java</td> <td>1995</td> </tr> <tr> <td>Pascal</td> <td>1970</td> </tr> </table> </body> </html>
Output
- Related Questions & Answers
- How to set cell width and height in HTML?
- Set width between table cells with CSS
- Set the width of the element in HTML
- Flex container width when flex-flow is set to column wrap in HTML
- How to set viewport height and width in CSS
- How to use height and width attributes in HTML?
- HTML Screen width Property
- How to set the width of an element in JavaScript?
- Set border width with CSS
- How to set the number of rows a table cell should span in HTML?
- HTML DOM Object Width Property
- HTML DOM Style width Property
- HTML DOM Video width Property
- How to merge table cells in HTML?
- How to merge table columns in HTML?
Advertisements