How to make a background in HTML. Brief instruction

This article will allow you to understand the question: "How to make a background in HTML?" The most common and convenient methods that are used by modern developers will be analyzed.

how to make background in html

To understand how to make a background in HTML, you just need to learn one simple attribute. Namely, bgcolor, to which you can assign values โ€‹โ€‹in the form of the name of the colors or their individual code. You can use this attribute for any tag or element, for example, for individual paragraphs, for a form, table, etc. To change the color of the entire document, specify the bgcolor attribute for the body tag. But there is one remark: bgcolor has long been recognized as undesirable and makes your code automatically invalid. The World Wide Web Consortium encourages all CSS developers to use their counterparts. The language of cascading tables allows you to replace unwanted attributes and even adds new features. It is with CSS that you can achieve the closest result to your plan.

Attribute Analogs

To create a background for the site, it is best to use the language of cascading style sheets. The background-color property will help change the background color of any element. If this command does not have a special purpose for a specific tag, then the background will change for the entire document. For example, the entry background-color: red will make the background of the site red. And if a more detailed description is specified, for example p {background-color: green}, then the background of each tag of the paragraph p will turn green. The more specifics given, the more priority the rule has. You can use a short background. As in the case of the bgcolor attribute, you can specify all known methods for describing color as the value of the background-color property.

  1. By name. In total there are 17 main names (red, green, blue, etc.).
  2. By a hexadecimal value, where it consists of numbers from 0 to 9 and letters from A to F (# c0c0c0).
  3. Using the abbreviations RGB, RGBA, HSL, HSLA. Recording in this way has the following form RBG (122, 142, 92) or HSL (13, 21%, 75%).

    create a background for the site

Picture

One of the great things about CSS is the ability to use background images for your site. In this case, instead of the usual background, a pre-selected picture will be applied. The background-image property can be used for any element or for the whole page, like the background-color command. The url entry is the required value. After it follows the address, which should refer to the image. For example, the entry background-image: url (image / 2.gif) will select the 2.gif file from the image directory and make it a background image. The address must be in parentheses. This rule can have a short background record, where you can write any properties related to the background. With the help of additional commands, you can achieve interesting effects. For example, background-attachment tells the browser how the image should enter itself when scrolling through the user's window. The background image can always be in one place or move along with all the contents of a particular element.

background images for the site

Conclusion

We hope you learned from this article about how to make a background in HTML. In this case, a choice is given several different ways. If it is important for you that your code is valid, you cannot use the HMTL bgcolor attribute. And the best thing is to forget about this command and use only CSS rules. After all, cascading style sheets were invented specifically to make it easier to engage in page design. That is why attributes like bgcolor are a thing of the past and considered undesirable when creating HTML pages. After these words, we can consider the question "how to make the background in HTML" closed.

Source: https://habr.com/ru/post/K20016/


All Articles