skip to Main Content

Hii guys I’m new to the community

So I am currently trying to make an html website using pycharm I did most of it now but I want to add a background picture or colour.
Does anyone know the code for it ?

I tried

<img src='background.jpeg'>

And

<style> </style> 

And I saved the picture on my pc but it didn’t work

2

Answers


  1. You mean something like below?

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="style2.css"> <!-- include the path to the style2.css if it's not in the same folder-->
        <title>Document</title>
    </head>
    <body>
        <h1>Something...</h1>
    </body>
    </html>
    

    and in your style2.css

    body{
        background-image: url('images/somepicture.jpeg'); /*assuming you have saved the picture in the images folder */
        background-size: cover;
    }
    
    Login or Signup to reply.
  2. Is your picture also in the root-folder, where your index.html lies?
    Or you do it with Internal-Styles

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    body {background-color: powderblue;
          background-image: url('images/somepicture.png');} /* Path to your picture */
    h1   {color: blue;}
    p    {color: red;}
    </style>
    </head>
    <body>
    
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    
    </body>
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search