How to add a background image to HTML: 13 steps

Table of contents:

How to add a background image to HTML: 13 steps
How to add a background image to HTML: 13 steps
Anonim

To add an image to a web page, you need HTML, and to add an image to the background of a web page, you need HTML and CSS. HTML (Hypertext Markup Language) is a standardized document markup language that tells the browser what to display on a web page. CSS (Cascading Style Sheets) is a document appearance description language that is used to change the appearance and layout of a web page. You will need an image that you set as the background of your web page.

Steps

Part 1 of 5: How to create a folder and file

2627945 1 1
2627945 1 1

Step 1. Create a folder to store the HTML file and background image

Give the folder a name that makes it easy to find.

The folder name can be anything, but it is better if it consists of one short word

2627945 2 1
2627945 2 1

Step 2. Copy the background image to the created folder

  • If you don't really care about how your site will open on older devices or on devices with slow internet connections, use a higher resolution image. An image with a simple repeating pattern is also suitable as a background, because the text will be clearly visible on it.
  • If you do not have an image, download it for free on the Internet and copy it to the created folder.
2627945 3 1
2627945 3 1

Step 3. Create an HTML file

Open a text editor and then create a new file. Save it as index.html.

  • You can use any text editor such as Notepad on Windows or TextEdit on Mac OS X.
  • If you want to use a text editor designed for HTML, download the Atom editor, which supports Windows, macOS, and Linux.
  • If you are using TextEdit, before you start writing HTML, open the Format menu and choose Convert to Plain Text. In this case, the HTML file will load correctly in the web browser.
  • Powerful text editors such as Microsoft Word are not well suited for writing HTML code because they add invisible characters and formatting that can prevent the content of the HTML file from displaying correctly in a web browser.

Part 2 of 5: How to Write HTML Code

2627945 4 1
2627945 4 1

Step 1. Copy and paste the standard HTML code

Highlight and copy the HTML below, and then paste it into the open index.html file.

  Page title     
2627945 5 1
2627945 5 1

Step 2. Add the URL for the background image

In the index.html file, find the line background-image: url (""); … Place the cursor inside the parentheses, and then enter the name of the background image file. Be sure to include the file extension for the background image.

    The specified line should look something like this:

    background-image: url ("background.png");

    If you just enter the name of the file (without its URL or path), the web browser will look for the picture in the folder with the HTML file. If the image is located in a different folder, enter the full path to the file.

  • Save the HTML file.
  • 2627945 6 1
    2627945 6 1
  • Part 3 of 5: How to View an HTML File

    2627945 7 1
    2627945 7 1

    Step 1. Open the HTML file in a web browser

    Right-click the index.html file and open it in your chosen web browser.

    • If the desired picture does not open in the browser, in the text editor window, check if the name of the file with the image is entered correctly.
    • If the web browser displayed HTML instead of a background image, the index.html file was saved as an RTF document. In this case, edit the HTML file in another text editor.
    2627945 8 1
    2627945 8 1

    Step 2. Make changes to the HTML file

    In the text editor window, place the cursor between the tags and type "Hello world!" Refresh the page in the browser so that the entered text is displayed in the background of the picture.

    Part 4 of 5: How to understand the HTML code

    2627945 9 1
    2627945 9 1

    Step 1. Remember what tags are in HTML and CSS

    HTML code consists of opening and closing tags. For example, the tag is opening and it is closing. Each start tag must have a corresponding end tag for the web page to load correctly.

    2627945 10 1
    2627945 10 1

    Step 2. Remember the DOCTYPE tag

    Good HTML should start with. This tag tells the web browser that the HTML file is an HTML file.

    2627945 11 1
    2627945 11 1

    Step 3. Make changes to the HTML file

    In the text editor window, place the cursor between the tags and type "Hello world!"Refresh the page in the browser so that the entered text is displayed in the background of the picture.

    2627945 12 1
    2627945 12 1

    Step 4. Remember what tags are in HTML and CSS

    HTML code consists of opening and closing tags. For example, the tag is opening and it is closing. Each start tag must have a corresponding end tag for the web page to load correctly.

    2627945 13 1
    2627945 13 1

    Step 5. Remember the tag

    It contains the text that appears in the title bar of the browser window, as well as the text that appears in the browser tab.

    2627945 14 1
    2627945 14 1

    Step 6. Remember the tag

    It points to the content of the CSS. Everything between the tags is CSS code.

    2627945 15 1
    2627945 15 1

    Step 7. Remember the tag

    Any text between tags will display as entered (unless it's HTML or CSS).

    2627945 16 1
    2627945 16 1

    Step 8. Make changes to the HTML file

    In the text editor window, place the cursor between the tags and type "Hello world!" Refresh the page in the browser so that the entered text is displayed in the background of the picture.

    Part 5 of 5: How to Understand the CSS Code

    2627945 17 1
    2627945 17 1

    Step 1. Understand the CSS

    In the index.html file, the CSS between the tags directs the web browser to a named background image that appears between the tags.

    2627945 18 1
    2627945 18 1

    Step 2. Review the CSS code. 3

    body {background-image: url ("background.png"); }

    2627945 19 1
    2627945 19 1

    Step 4. Memorize the parts of the CSS code

    CSS styles have two parts: a selector and a declaration.

      In our example, body is a selector and

      background-image: url ("background.png") is an ad.

      The selector can be any HTML tag.

      Declarations are always enclosed in curly braces {}.

    2627945 20
    2627945 20

    Step 5. Remember what a CSS declaration is

    A CSS declaration has two parts: properties and values. Content in curly braces

    background-image is a property and url ("background.png") is a value.

      The property describes the item (in our example, this is the background image), and the value is the style of the item (in our example, this is the image file).

      The property and value are always separated by a colon (:).

      CSS declarations always end with a semicolon (;).

    Popular by topic