Table of Contents
Examples of HTML Table Background
Example #3
Conclusion
Home Web Front-end HTML Tutorial HTML Table Background

HTML Table Background

Sep 04, 2024 pm 04:48 PM
html html5 HTML Tutorial HTML Properties HTML tags

Like other HTML elements, there are many things to do with HTML Table. So we can set the Table background with different styles in the HTML table too. HTML Table background can be used to set control over the table’s background. It can be in the form of colors or images set as a background to the table. In this topic, we are going to learn about HTML Table Background.

This code allows users to do changes to HTML Table’s background. CSS code sets style to the table’s background using a property called background. As per the table’s width, we can also set a particular image as a background to the table. But this will repeat in table size. To avoid this case, we can use a property called background-repeat.

Syntax

There are multiple ways to set the background to the Table in HTML. Let’s see all the ways and syntax for the same one by one as follows:

The basic syntax to set background to any HTML element is as follows:

1

2

<HTML element background-color:color-name>

<HTML element background:"Image URL">

Copy after login

Same thing we can set as background to the table. In this scenario, we are going to set

color as the background to the Table.

1

2

3

4

<table style=" background-color:color-name;">

<tr style=" background-color:color-name;">

<td style=" background-color:color-name;">

<th style=" background-color:color-name;">

Copy after login

One can also set an image as a background to the Table in HTML. It can be done using a CSS property called a background image. This image will automatically set to the table background. In case this image is smaller in size than table width, then it will show repeat and repeat again.

1

<table background:" Image URL">

Copy after login
Copy after login

In the above case, we are able to avoid this condition of showing image repeat and repeat by using CSS property as follows:

1

<table background:" Image URL">

Copy after login
Copy after login

1

background-repeat: no-repeat;

Copy after login

It is also possible to set an image as a background to the one specific sell also. This can be done as follows:

1

2

3

4

5

6

7

8

.cellimg{

width: 100%;

border: 1px solid black;

}

.cellimg{

background-img: url("");

background-repeat: no-repeat;

}

Copy after login

Like an image to a specific cell, one can set the color to the specific cell also as follows:

1

2

3

4

5

6

7

8

9

10

<table>

<tr>

<th>content</th>

<th>content</th>

</tr>

<tr>

<td>content</td>

<td style="background-color:color-name; color:color-name;">content</td>

</tr>

</table>

Copy after login

OR

1

2

3

td.classname {

background-color:color-name;

}

Copy after login

We can set the color to the specific row also by using the following syntax:

1

2

3

4

<tr style="background-color:color-name;">

<th> </th>

<th> </th>

</tr>

Copy after login

By defining class to the table and apply CSS property to that specific class is also helpful to set background to the table. The syntax for this is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

<style>

.tableclassname {

width:100%;

background-color:color-name;

}

.tableclassname  th{

width:100%;

background-color:color-name;

}

.tableclassname td{

background-color:color-name;

}

</style>

Copy after login

Examples of HTML Table Background

Here are the following examples mention below :

Example #1

This example is for setting the background as a color. So can set the color to the table background as per their choice.HTML code and output for it as follows:

Code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

<!DOCTYPE html>

<html>

<head>

<title>HTML Table Background</title>

<!-- CSS -->

<style>

.tabledemo {

width: 100%;

text-align: Center;

background-color:aquamarine;

border-collapse: collapse;

}

.tabledemo td, .tabledemo th {

border:2px solid brown;

padding:3px;

}

</style>

</head>

<body>

<table class="tabledemo">

<tr>

<th>Place Name</th>

<th>To do Things</th>

<th>Distance from Pune</th>

<th>Best Time to visit</th>

</tr>

<tr>

<td>Sinhgad</td>

<td>Trekking, photography</td>

<td>30 km</td>

<td>All seasons</td>

</tr>

<tr>

<td>Lohgad fort</td>

<td>Pawana lake, Visapur fort</td>

<td>65 km</td>

<td>Mansoon</td>

</tr>

<tr>

<td>Pawana Lake</td>

<td>Night campaing</td>

<td>50 km</td>

<td>All seasons</td>

</tr>

<tr>

<td>lonvala</td>

<td>Rajmachi Fort, Bushi dam</td>

<td>66 km</td>

<td>Mansoon</td>

</tr>

<tr>

<td>Kamshet</td>

<td>Paragliding</td>

<td>47.5 km</td>

<td>All seasons</td>

</tr>

<tr>

<td>Khandala</td>

<td>Karla Hills</td>

<td>71.1 km</td>

<td>Rainy days</td>

</tr>

<tr>

<td>Alibaug</td>

<td>Colabo Fort, Kihim Beach</td>

<td>143 km</td>

<td>All Seasons</td>

</tr>

<tr>

<td>Tarkarli</td>

<td>Scuba Diving</td>

<td>388 km</td>

<td>All Seasons</td>

</tr>

<tr>

<td>Rajgad fort</td>

<td>Suvela machi, Balekilla</td>

<td>54 km</td>

<td>Mansoon</td>

</tr>

<tr>

<td>Kolad</td>

<td>River raffting</td>

<td>194 km</td>

<td>Mansoon, Winter</td>

</tr>

</table>

</body>

</html>

Copy after login

Output:

HTML Table Background

 Example #2

This example is for setting the background as an image. So one can set an image to the table background as per their choice. Image is in repeat mode as output, HTML code and output for it as follows:

Code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

<!DOCTYPE html>

<html>

<head>

<title>HTML Table Background</title>

<style>

.imgbg {

width: 100%;

text-align: left;

background-image: url(BG.jpg);

border-collapse: collapse;

}

.imgbg td, .imgbg th {

border:2px solid black;

padding:5px;

}

</style>

</head>

<body>

<table class="imgbg">

<tr>

<th>Front End Languages</th>

<th>Backend Languages</th>

<th>Databases</th>

<th>OS</th>

</tr>

<tr>

<td>HTML </td>

<td>.NET</td>

<td>SQL</td>

<td>Windows 10</td>

</tr>

<tr>

<td>CSS</td>

<td>.NET</td>

<td>MYSQL</td>

<td>Windows 10</td>

</tr>

<tr>

<td>Bootstrap</td>

<td>angular JS</td>

<td>PL/SQL</td>

<td>Ubuntu</td>

</tr>

<tr>

<td>Javascript</td>

<td>.NET</td>

<td>Mongo DB</td>

<td>Windows 10</td>

</tr>

<tr>

<td>Jquery</td>

<td>Core java</td>

<td>Mariya DB</td>

<td>Windows 10</td>

</tr>

<tr>

<td>React JS</td>

<td>Python</td>

<td>Maria DB</td>

<td>ubuntu</td>

</tr>

<tr>

<td>Vue JS</td>

<td>Php</td>

<td>PL-SQL</td>

<td>Windows 10</td>

</tr>

<tr>

<td>Angular 8</td>

<td>Java</td>

<td>Maria DB</td>

<td>Ubuntu</td>

</tr>

<tr>

<td>RWD</td>

<td>Ruby</td>

<td>Mongo DB</td>

<td>Windows 10</td>

</tr>

<tr>

<td>React JS</td>

<td>ASP .NET</td>

<td>Maria DB</td>

<td>Windows 10</td>

</tr>

</table>

</body>

</html>

Copy after login

Output:

HTML Table Background

Example #3

This is one more scenario in which we are going to add both image and color as a background but to the particular cell.

Code :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

<!DOCTYPE html>

<html>

<head>

<title>HTML Table Background</title>

<style>

.imgno {

width: 100%;

border-collapse: collapse;

text-align: center;

}

.imgno td, .imgno th {

border:1px solid black;

padding:4px;

}

</style>

</head>

<body>

<table class="imgno">

<tr style="background-color: chartreuse;">

<th>First Name</th>

<th>Last Name</th>

<th>Age</th>

<th>Location</th>

</tr>

<tr>

<td>ketki </td>

<td>Patil</td>

<td>28</td>

<td style="background-image: url(BG1.jpg)">Mumbai</td>

</tr>

<tr>

<td>Devendra</td>

<td>Gupta</td>

<td>35</td>

<td>Delhi</td>

</tr>

<tr>

<td style="background-color: aquamarine;">Nikhil</td>

<td>Sabnis</td>

<td>49</td>

<td>Neral</td>

</tr>

<tr >

<td style="background-color: darkgoldenrod;">Snehal</td>

<td>Wagh</td>

<td>29</td>

<td>Nashik</td>

</tr>

<tr>

<td>Gitu</td>

<td>Rathi</td>

<td>34</td>

<td>Pune</td>

</tr>

<tr style="background-image: url(BG1.jpg)">

<td>Pooja</td>

<td>Lohiya</td>

<td>26</td>

<td>Nanded</td>

</tr>

<tr style="background-image: url(BG1.jpg)">

<td>Dipti</td>

<td>Roy</td>

<td>22</td>

<td>Parbhani</td>

</tr>

<tr>

<td>Prem</td>

<td>Jadu</td>

<td>67</td>

<td>Kolkata</td>

</tr>

<tr>

<td>Aditi</td>

<td>Jain</td>

<td>23</td>

<td>Nagpur</td>

</tr>

<tr>

<td>Raj</td>

<td>Sohani</td>

<td>25</td>

<td>Latur</td>

</tr>

<tr>

<td>Sai</td>

<td>Jain</td>

<td>56</td>

<td style="background-image: url(BG1.jpg)">Mumbai</td>

</tr>

</table>

</body>

</html>

Copy after login

Output:

HTML Table Background

Conclusion

Like other elements, it’s also possible to set the background in the form of an image and color to the HTML Table. One can set an image or color to the specific table attributes like the whole table or to the table head, table row or table column. This is also possible using table background property in code.

The above is the detailed content of HTML Table Background. 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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles