HTML Formatting
HTML Formatting
HTML Formatting is a process of formatting text for better look and feel.
HTML provides us ability to format text without using CSS. There are many
formatting tags in HTML. These tags are used to make text bold, italicized, or
underlined. There are almost 14 options available that how text appears in
HTML and XHTML.
o Physical tag: These tags are used to provide the visual appearance to
the text.
o Logical tag: These tags are used to add some logical or semantic value
to the text.
<b> This is a physical tag, which is used to bold the text written between it.
<strong> This is a logical tag, which tells the browser that the text is important.
<tt> This tag is used to appear a text in teletype. (not supported in HTML5)
<strike> This tag is used to draw a strikethrough on a section of text. (Not supported i
HTML5)
<big> This tag is used to increase the font size by one conventional unit.
<small> This tag is used to decrease the font size by one unit from base font size.
o 1) Bold Text
HTML<b> and <strong> formatting elements
The HTML <b> element is a physical tag which display text in bold font,
without any logical importance. If you write anything within <b>............</b>
element, is shown in bold letters.
The HTML <strong> tag is a logical tag, which displays the content in bold
font and informs the browser about its logical importance. If you write
anything between <strong>???????. </strong>, is shown important text.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of formatting element</h1>
8. <p><strong>This is an important content</strong>, and this is normal conten
t</p>
9. </body>
10.</html>
This is an important content, which displayed in italic font.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of italic formatting element</h1>
8. <p><em>This is an important content</em>, which displayed in italic font
.</p>
9. </body>
10. </html>
4) Underlined Text
If you write anything within <u>.........</u> element, is shown in underlined
text.
5) Strike Text
Anything written within <strike>.......................</strike> element is
displayed with strikethrough. It is a thin line which cross the statement.
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is
an empty tag that contains attributes only, closing tags are not used in HTML
image element.
Example:
1. <a href="https://www.javatpoint.com/what-is-robotics"><img src="robot.jpg" heig
ht="100" width="100"></a>
HTML Table
HTML table tag is used to display data in tabular form (row * column).
There can be many columns in a row.
In Each table, table row is defined by <tr> tag, table header is defined by
<th>, and table data is defined by <td> tags.
HTML tables are used to manage the layout of the page e.g. header section,
navigation bar, body content, footer section etc. But it is recommended to
use div tag over table to manage the layout of the page .
HTML Table Tags
Tag Description
<col> It is used with <colgroup> element to specify column properties for each column.
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
HTML Border attribute
You can use border attribute of table tag in HTML to specify border. But it is
not recommended now.
<table border="1">
1. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
2. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
3. <tr><td>James</td><td>William</td><td>80</td></tr>
4. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
5. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
6. </table>
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. }
5. </style>
1. <style>
2. table, th, td {
3. border: 2px solid black;
4. border-collapse: collapse;
5. }
6. </style>
Name Last Name Marks
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
HTML Table with cell padding
You can specify padding for table header and table data by two ways:
1. <style>
2. table, th, td {
3. border: 1px solid pink;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
Test it Now
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
HTML Table width:
We can specify the HTML table width using the CSS width property. It can
be specify in pixels or percentage.
We can adjust our table width as per our requirement. Following is the
example to display table with width.
1. table{
2. width: 100%;
3. }
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>table</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. width: 100%;
9. }
10. th,td{
11. border: 2px solid green;
12. padding: 15px;
13. }
14.
15. </style>
16. </head>
17.<body>
18. <table>
19. <tr>
20. <th>1 header</th>
21. <th>1 header</th>
22. <th>1 header</th>
23. </tr>
24. <tr>
25. <td>1data</td>
26. <td>1data</td>
27. <td>1data</td>
28. </tr>
29. <tr>
30. <td>2 data</td>
31. <td>2 data</td>
32. <td>2 data</td>
33. </tr>
34. <tr>
35. <td>3 data</td>
36. <td>3 data</td>
37. <td>3 data</td>
38. </tr>
39.</table>
40.</body>
41.</html>