- Blog Categories
- Software Development Projects and Ideas
- 12 Computer Science Project Ideas
- 28 Beginner Software Projects
- Top 10 Engineering Project Ideas
- Top 10 Easy Final Year Projects
- Top 10 Mini Projects for Engineers
- 25 Best Django Project Ideas
- Top 20 MERN Stack Project Ideas
- Top 12 Real Time Projects
- Top 6 Major CSE Projects
- 12 Robotics Projects for All Levels
- Java Programming Concepts
- Abstract Class in Java and Methods
- Constructor Overloading in Java
- StringBuffer vs StringBuilder
- Java Identifiers: Syntax & Examples
- Types of Variables in Java Explained
- Composition in Java: Examples
- Append in Java: Implementation
- Loose Coupling vs Tight Coupling
- Integrity Constraints in DBMS
- Different Types of Operators Explained
- Career and Interview Preparation in IT
- Top 14 IT Courses for Jobs
- Top 20 Highest Paying Languages
- 23 Top CS Interview Q&A
- Best IT Jobs without Coding
- Software Engineer Salary in India
- 44 Agile Methodology Interview Q&A
- 10 Software Engineering Challenges
- Top 15 Tech's Daily Life Impact
- 10 Best Backends for React
- Cloud Computing Reference Models
- Web Development and Security
- Find Installed NPM Version
- Install Specific NPM Package Version
- Make API Calls in Angular
- Install Bootstrap in Angular
- Use Axios in React: Guide
- StrictMode in React: Usage
- 75 Cyber Security Research Topics
- Top 7 Languages for Ethical Hacking
- Top 20 Docker Commands
- Advantages of OOP
- Data Science Projects and Applications
- 42 Python Project Ideas for Beginners
- 13 Data Science Project Ideas
- 13 Data Structure Project Ideas
- 12 Real-World Python Applications
- Python Banking Project
- Data Science Course Eligibility
- Association Rule Mining Overview
- Cluster Analysis in Data Mining
- Classification in Data Mining
- KDD Process in Data Mining
- Data Structures and Algorithms
- Binary Tree Types Explained
- Binary Search Algorithm
- Sorting in Data Structure
- Binary Tree in Data Structure
- Binary Tree vs Binary Search Tree
- Recursion in Data Structure
- Data Structure Search Methods: Explained
- Binary Tree Interview Q&A
- Linear vs Binary Search
- Priority Queue Overview
- Python Programming and Tools
- Top 30 Python Pattern Programs
- List vs Tuple
- Python Free Online Course
- Method Overriding in Python
- Top 21 Python Developer Skills
- Reverse a Number in Python
- Switch Case Functions in Python
- Info Retrieval System Overview
- Reverse a Number in Python
- Real-World Python Applications
- Data Science Careers and Comparisons
- Data Analyst Salary in India
- Data Scientist Salary in India
- Free Excel Certification Course
- Actuary Salary in India
- Data Analyst Interview Guide
- Pandas Interview Guide
- Tableau Filters Explained
- Data Mining Techniques Overview
- Data Analytics Lifecycle Phases
- Data Science Vs Analytics Comparison
- Artificial Intelligence and Machine Learning Projects
- Exciting IoT Project Ideas
- 16 Exciting AI Project Ideas
- 45+ Interesting ML Project Ideas
- Exciting Deep Learning Projects
- 12 Intriguing Linear Regression Projects
- 13 Neural Network Projects
- 5 Exciting Image Processing Projects
- Top 8 Thrilling AWS Projects
- 12 Engaging AI Projects in Python
- NLP Projects for Beginners
- Concepts and Algorithms in AIML
- Basic CNN Architecture Explained
- 6 Types of Regression Models
- Data Preprocessing Steps
- Bagging vs Boosting in ML
- Multinomial Naive Bayes Overview
- Gini Index for Decision Trees
- Bayesian Network Example
- Bayes Theorem Guide
- Top 10 Dimensionality Reduction Techniques
- Neural Network Step-by-Step Guide
- Technical Guides and Comparisons
- Make a Chatbot in Python
- Compute Square Roots in Python
- Permutation vs Combination
- Image Segmentation Techniques
- Generative AI vs Traditional AI
- AI vs Human Intelligence
- Random Forest vs Decision Tree
- Neural Network Overview
- Perceptron Learning Algorithm
- Selection Sort Algorithm
- Career and Practical Applications in AIML
- AI Salary in India Overview
- Biological Neural Network Basics
- Top 10 AI Challenges
- Production System in AI
- Top 8 Raspberry Pi Alternatives
- Top 8 Open Source Projects
- 14 Raspberry Pi Project Ideas
- 15 MATLAB Project Ideas
- Top 10 Python NLP Libraries
- Naive Bayes Explained
- Digital Marketing Projects and Strategies
- 10 Best Digital Marketing Projects
- 17 Fun Social Media Projects
- Top 6 SEO Project Ideas
- Digital Marketing Case Studies
- Coca-Cola Marketing Strategy
- Nestle Marketing Strategy Analysis
- Zomato Marketing Strategy
- Monetize Instagram Guide
- Become a Successful Instagram Influencer
- 8 Best Lead Generation Techniques
- Digital Marketing Careers and Salaries
- Digital Marketing Salary in India
- Top 10 Highest Paying Marketing Jobs
- Highest Paying Digital Marketing Jobs
- SEO Salary in India
- Brand Manager Salary in India
- Content Writer Salary Guide
- Digital Marketing Executive Roles
- Career in Digital Marketing Guide
- Future of Digital Marketing
- MBA in Digital Marketing Overview
- Digital Marketing Techniques and Channels
- 9 Types of Digital Marketing Channels
- Top 10 Benefits of Marketing Branding
- 100 Best YouTube Channel Ideas
- YouTube Earnings in India
- 7 Reasons to Study Digital Marketing
- Top 10 Digital Marketing Objectives
- 10 Best Digital Marketing Blogs
- Top 5 Industries Using Digital Marketing
- Growth of Digital Marketing in India
- Top Career Options in Marketing
- Interview Preparation and Skills
- 73 Google Analytics Interview Q&A
- 56 Social Media Marketing Q&A
- 78 Google AdWords Interview Q&A
- Top 133 SEO Interview Q&A
- 27+ Digital Marketing Q&A
- Digital Marketing Free Course
- Top 9 Skills for PPC Analysts
- Movies with Successful Social Media Campaigns
- Marketing Communication Steps
- Top 10 Reasons to Be an Affiliate Marketer
- Career Options and Paths
- Top 25 Highest Paying Jobs India
- Top 25 Highest Paying Jobs World
- Top 10 Highest Paid Commerce Job
- Career Options After 12th Arts
- Top 7 Commerce Courses Without Maths
- Top 7 Career Options After PCB
- Best Career Options for Commerce
- Career Options After 12th CS
- Top 10 Career Options After 10th
- 8 Best Career Options After BA
- Projects and Academic Pursuits
- 17 Exciting Final Year Projects
- Top 12 Commerce Project Topics
- Top 13 BCA Project Ideas
- Career Options After 12th Science
- Top 15 CS Jobs in India
- 12 Best Career Options After M.Com
- 9 Best Career Options After B.Sc
- 7 Best Career Options After BCA
- 22 Best Career Options After MCA
- 16 Top Career Options After CE
- Courses and Certifications
- 10 Best Job-Oriented Courses
- Best Online Computer Courses
- Top 15 Trending Online Courses
- Top 19 High Salary Certificate Courses
- 21 Best Programming Courses for Jobs
- What is SGPA? Convert to CGPA
- GPA to Percentage Calculator
- Highest Salary Engineering Stream
- 15 Top Career Options After Engineering
- 6 Top Career Options After BBA
- Job Market and Interview Preparation
- Why Should You Be Hired: 5 Answers
- Top 10 Future Career Options
- Top 15 Highest Paid IT Jobs India
- 5 Common Guesstimate Interview Q&A
- Average CEO Salary: Top Paid CEOs
- Career Options in Political Science
- Top 15 Highest Paying Non-IT Jobs
- Cover Letter Examples for Jobs
- Top 5 Highest Paying Freelance Jobs
- Top 10 Highest Paying Companies India
- Career Options and Paths After MBA
- 20 Best Careers After B.Com
- Career Options After MBA Marketing
- Top 14 Careers After MBA In HR
- Top 10 Highest Paying HR Jobs India
- How to Become an Investment Banker
- Career Options After MBA - High Paying
- Scope of MBA in Operations Management
- Best MBA for Working Professionals India
- MBA After BA - Is It Right For You?
- Best Online MBA Courses India
- MBA Project Ideas and Topics
- 11 Exciting MBA HR Project Ideas
- Top 15 MBA Project Ideas
- 18 Exciting MBA Marketing Projects
- MBA Project Ideas: Consumer Behavior
- What is Brand Management?
- What is Holistic Marketing?
- What is Green Marketing?
- Intro to Organizational Behavior Model
- Tech Skills Every MBA Should Learn
- Most Demanding Short Term Courses MBA
- MBA Salary, Resume, and Skills
- MBA Salary in India
- HR Salary in India
- Investment Banker Salary India
- MBA Resume Samples
- Sample SOP for MBA
- Sample SOP for Internship
- 7 Ways MBA Helps Your Career
- Must-have Skills in Sales Career
- 8 Skills MBA Helps You Improve
- Top 20+ SAP FICO Interview Q&A
- MBA Specializations and Comparative Guides
- Why MBA After B.Tech? 5 Reasons
- How to Answer 'Why MBA After Engineering?'
- Why MBA in Finance
- MBA After BSc: 10 Reasons
- Which MBA Specialization to choose?
- Top 10 MBA Specializations
- MBA vs Masters: Which to Choose?
- Benefits of MBA After CA
- 5 Steps to Management Consultant
- 37 Must-Read HR Interview Q&A
- Fundamentals and Theories of Management
- What is Management? Objectives & Functions
- Nature and Scope of Management
- Decision Making in Management
- Management Process: Definition & Functions
- Importance of Management
- What are Motivation Theories?
- Tools of Financial Statement Analysis
- Negotiation Skills: Definition & Benefits
- Career Development in HRM
- Top 20 Must-Have HRM Policies
- Project and Supply Chain Management
- Top 20 Project Management Case Studies
- 10 Innovative Supply Chain Projects
- Latest Management Project Topics
- 10 Project Management Project Ideas
- 6 Types of Supply Chain Models
- Top 10 Advantages of SCM
- Top 10 Supply Chain Books
- What is Project Description?
- Top 10 Project Management Companies
- Best Project Management Courses Online
- Salaries and Career Paths in Management
- Project Manager Salary in India
- Average Product Manager Salary India
- Supply Chain Management Salary India
- Salary After BBA in India
- PGDM Salary in India
- Top 7 Career Options in Management
- CSPO Certification Cost
- Why Choose Product Management?
- Product Management in Pharma
- Product Design in Operations Management
- Industry-Specific Management and Case Studies
- Amazon Business Case Study
- Service Delivery Manager Job
- Product Management Examples
- Product Management in Automobiles
- Product Management in Banking
- Sample SOP for Business Management
- Video Game Design Components
- Top 5 Business Courses India
- Free Management Online Course
- SCM Interview Q&A
- Fundamentals and Types of Law
- Acceptance in Contract Law
- Offer in Contract Law
- 9 Types of Evidence
- Types of Law in India
- Introduction to Contract Law
- Negotiable Instrument Act
- Corporate Tax Basics
- Intellectual Property Law
- Workmen Compensation Explained
- Lawyer vs Advocate Difference
- Law Education and Courses
- LLM Subjects & Syllabus
- Corporate Law Subjects
- LLM Course Duration
- Top 10 Online LLM Courses
- Online LLM Degree
- Step-by-Step Guide to Studying Law
- Top 5 Law Books to Read
- Why Legal Studies?
- Pursuing a Career in Law
- How to Become Lawyer in India
- Career Options and Salaries in Law
- Career Options in Law India
- Corporate Lawyer Salary India
- How To Become a Corporate Lawyer
- Career in Law: Starting, Salary
- Career Opportunities: Corporate Law
- Business Lawyer: Role & Salary Info
- Average Lawyer Salary India
- Top Career Options for Lawyers
- Types of Lawyers in India
- Steps to Become SC Lawyer in India
- Tutorials
- C Tutorials
- Recursion in C: Fibonacci Series
- Checking String Palindromes in C
- Prime Number Program in C
- Implementing Square Root in C
- Matrix Multiplication in C
- Understanding Double Data Type
- Factorial of a Number in C
- Structure of a C Program
- Building a Calculator Program in C
- Compiling C Programs on Linux
- Java Tutorials
- Handling String Input in Java
- Determining Even and Odd Numbers
- Prime Number Checker
- Sorting a String
- User-Defined Exceptions
- Understanding the Thread Life Cycle
- Swapping Two Numbers
- Using Final Classes
- Area of a Triangle
- Skills
- Software Engineering
- JavaScript
- Data Structure
- React.js
- Core Java
- Node.js
- Blockchain
- SQL
- Full stack development
- Devops
- NFT
- BigData
- Cyber Security
- Cloud Computing
- Database Design with MySQL
- Cryptocurrency
- Python
- Digital Marketings
- Advertising
- Influencer Marketing
- Search Engine Optimization
- Performance Marketing
- Search Engine Marketing
- Email Marketing
- Content Marketing
- Social Media Marketing
- Display Advertising
- Marketing Analytics
- Web Analytics
- Affiliate Marketing
- MBA
- MBA in Finance
- MBA in HR
- MBA in Marketing
- MBA in Business Analytics
- MBA in Operations Management
- MBA in International Business
- MBA in Information Technology
- MBA in Healthcare Management
- MBA In General Management
- MBA in Agriculture
- MBA in Supply Chain Management
- MBA in Entrepreneurship
- MBA in Project Management
- Management Program
- Consumer Behaviour
- Supply Chain Management
- Financial Analytics
- Introduction to Fintech
- Introduction to HR Analytics
- Fundamentals of Communication
- Art of Effective Communication
- Introduction to Research Methodology
- Mastering Sales Technique
- Business Communication
- Fundamentals of Journalism
- Economics Masterclass
- Free Courses
How to Add Background Image in HTML? [Step-by-Step Guide]
Updated on 13 November, 2024
68.75K+ views
• 15 min read
Table of Contents
- What is HTML?
- Two Methods to Add Background Image in HTML
- How to Add Background Image in HTML Using Background attribute?
- How to Add Background Image Using Internal Style Sheet (CSS)?
- Reviewing the HTML File
- How to Insert a Background Image in HTML Without CSS?
- How Do you Insert a Background Image in HTML Using Notepad?
- How to Repeat Background Image in HTML?
- Conclusion
Images can be added to a website in a variety of ways to make it look interesting & appealing. The addition of a background image is one such method. Images are essential when building a website or writing a blog post because they help make the content more appealing and understandable. Without images, a blog or website becomes boring, and readers begin to drift away. The practical impact of background images on a web page's interactivity is also significant.
The background image attribute found inside the <body> tag is the most popular and straightforward method of adding a background image. In this blog, we will learn how to add background images in HTML and how to use HTML and CSS to add background images to websites.
What is HTML?
HyperText Markup Language, or HTML, is a common markup language for building a webpage's basic framework and adding features like text, graphics, tables, forms, and so forth. HTML is a powerful coding language for creating websites. It is combined with CSS while designing and constructing websites. Therefore, it should go without saying that learning HTML is a necessary first step if you want to succeed in the field of Web development.
If building rich, useful web applications has always been your dream, whether you're a junior Front-End developer or a senior Full-Stack developer with a comprehensive Web Designing and Development course, you'll learn everything about creating web pages using HTML, CSS, and JavaScript.
Two Methods to Add Background Image in HTML
We can add HTML background image to be displayed on a web page using the following different two methods:
- Using the Background attribute (using HTML TAG)
- Using an Internal Style Sheet (CSS)
How to Add Background Image in HTML Using Background attribute?
Follow the steps to learn how to put an image in the background in HTML:
1. Setting up your files
Step 1: Create a folder to hold your HTML file and background
Make a folder on your computer with a name you can recall later.
Although the folder name is completely up to you, it's best to get into the habit of giving your files and folders recognizable, short, single-word names when working with HTML.
Step 2: Put the background image into the HTML folder
Put the background image in the HTML folder if you want to use it.
Use a higher-resolution image as your background if you aren't too concerned about making sure your website will function well on older devices with slower internet connections. To make any text on top of the background image easier to read, choose a simple image with subtle, repetitive patterns.
Step 3: Open a text editor or HTML editor
Simple text editors like NotePad on Windows or TextEdit on Mac can be used to create HTML files. Another option is to use a WYSIWYG (what-you-see-is-what-you-get) HTML editor like Adobe Dreamweaver.
At the top of the page, if you're using a WYSIWYG editor, select the option to open a new HTML file.
Step 4: Click File It’s in the menu bar at the top of the page
Step 5: Click Save as (Notepad) or Save (TextEdit)
It's listed below in the file menu. On a computer, select Save As from the "File" drop-down menu. On a Mac, select Save from the drop-down menu.
Step 6: Type a name for the HTML document
The first page of a website is typically referred to as the "index," but you can name the page whatever you like. In the text box next to "File Name," enter the file's name.
Step 7: Change the file type to an HTML document
If you're working in a WYSIWYG editor, all you have to do is save the document. Use the steps below to save the document in HTML format if you're creating HTML in NotePad or TextEdit.
Step 8: Click Save
It's located in the window's lower-right corner. This saves the text file as an HTML file.
With our Full Stack Certification, you'll learn more about topics and techniques through independent and group projects, get personalized feedback, work with MAANG experts as mentors, hone your skills in multiple hackathons spread throughout the programme, and receive intensive interview preparation and career launch support.
Check out our free technology courses to upskill yourself
2. Writing the HTML File
Step 1: Type <! DOCTYPE html > at the top of the HTML document
Open and closed tags make up HTML code. Every properly written HTML page should begin with <!DOCTYPE html>. This indicates to a web browser that the file is an HTML file.
Step 2: Write <html> in the next line
This is the first tag in your HTML code. This instructs the browser that your HTML code begins here.
Step 3: Type <head> in the next line
This is the first tag in the HTML document's Head section. The head contains meta information that the web browser does not display. This section contains information such as the page title, as well as Cascading Style Sheets (CSS) that format the look of the HTML code.
Step 4: Type <title> Page Title </title>
This is the HTML code that contains your web page's page title. The "<title>" tag is the first tag in the HTML code for the Page title. The closing tag is "</title>" of the tag. Replace "Page Title" with whatever title you want to give your HTML page. This text will appear at the top of the web browser in the browser tab.
Step 5: Type </head> in the next line
This is the tag that ends your HTML document's head. If you want to add any additional information or style sheets to your HTML document, place them after the "<head>" opening tag and before the "</head>" closing tag.
Step 6: Type <body> in the next line
This is the opening tag for your HTML document's body. The body contains all of your website's visual elements. This includes text, images, buttons, and other visible web page elements.
Step 7: Type <div style=“background-image : url ( ‘ [ image url ] ‘ ); “ > in the next line
This is the HTML tag for including a background image on your website. Replace "[image url]" with the actual URL of the image to be added. This can be the online server location of an image or the local location of an image on your computer.
You can also use CSS to set a background image.
When you use a filename that does not include a file path or URL (for example, background-image: url("background.png");), the web browser will look for the named image in the web page folder, if the file is in a different folder on your file system, you must include the full path to that file.
Step 8: Finish the rest of your HTML document
If you want to include other HTML elements on your web page, such as text, images, videos, links, buttons, and so on, make sure to put them in the "Body" section of your HTML document.
Step 9: Type < / body > in the last line
This is the tag that wraps your HTML document's body. When you've finished adding all of the HTML elements you want to include in your document, add this tag at the end.
Step 10: Type < / html > at the very end
This is the tag used to wrap your HTML document. Put this tag on the last line.
Step 11: Save the HTML file
When you are finished, click File and then Save to save your work. Your entire HTML document should resemble this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div style="background-image: url('https://www.website.com/images/image_background.jpg');">
</body>
</html>
How to Add Background Image Using Internal Style Sheet (CSS)?
Follow the following steps if you want to know how to add a background image in HTML using CSS:
Step 1: Create an HTML document
To create an HTML document, follow the procedures described in Part 2. An open and closing HTML tag, an open and closing head tag, and an open and closing body tag should all be present in your HTML document. To add a background image, you do not need to use the HTML tag. This section demonstrates how to set a background image using CSS rather than HTML.
Step 2: Type < style > in the head of the HTML document
The first tag in cascading style sheets is this one (CSS). Before the "</head>" tag and following the "<head>" tag.
You can also create your CSS in a separate CSS document and link it to your HTML document as an alternative.
Step 3: Type body { in the next line
The CSS code that will style the body of your HMTL document begins here.
Step 4: Type background-image: url (‘ [ image url ] ‘ ); in the next line
The background image to be used is specified in this line. The actual URL of the image you want to use should be substituted for the text "[image url]".
A filename without a file path or URL, such as background-image: url("background.png");, causes the web browser to search for the named image in the web page folder. You must include the complete path to the file if it is located in another folder on your file system.
Step 5: Type background-repeat: no - repeat; in the next line
By using this line, the web browser is instructed to only show the image once rather than repeatedly.
Step 6: Type background-size: cover; in the next line
This line instructs the web browser to use the image as the background for the entire page.
Step 7: Type} at the end of the “Body “section of your HTML
Make sure to include any additional CSS lines that have an impact on the HTML document's Body at this time. To close the "Body" section of your CSS, enter the symbol "}" in the final line.
Step 8: Type < / style > at the end of your CSS
Write "</style>" at the end once you have included all the CSS you want to. Your CSS is closed by this tag.
Step 9: Save the HTML file
When you are done, click File, followed by Save, to save your work.
Your entire HTML file should resemble the following:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
background-image: url("https://www.website.com/images/image_background.jpg");
background-repeat:no-repeat;
background-size:cover;
}
</style>
</head>
<body>
</body>
</html>
Explanation:
- The <style> tag within the <head> section is where the internal style sheet is defined.
- The background-image property in the body selector specifies the path to the image.
- background-size: cover; ensures the image covers the entire background area.
- background-position: center; centers the image in the viewport.
- background-repeat: no-repeat; prevents the image from repeating across the page.
Reviewing the HTML File
Step 1: Right-click the HTML document
To the right of it, a pop-up menu is displayed.
Step 2: Select Open with
A list of applications that can open HTML is shown in this.
Step 3: Select the web browser of your choice
You can use any web browser to view the HTML.
Step 4: Review the HTML file
Make sure everything in the file looks correct by going through it one last time.
The HTML file may have been saved as an a.txt or rtf file rather than an HTML document if you see the HTML code when the browser opens instead of the background image. You might want to try using a different text editor to edit the HTML file.
Step 5: Make edits to the HTML file
Place the cursor in the space between the <body> and </body> tags in the text editor window, and then type Hello world!. To see the text on top of the background image, reload the browser window.
How to Insert a Background Image in HTML Without CSS?
The steps listed below must be followed if we want to add a background image using the Background attribute in an HTML document. We can quickly view an image on a web page by following these steps:
Step 1: To begin, enter the HTML code into a text editor of your choice or open an existing HTML file to insert the background attribute.
<!Doctype Html>
<Html>
<Head>
<Title>
Add the Background image using the background attribute
</Title>
</Head>
<Body>
upGrad <br>
Html Tutorial <br>
This page helps us to understand how to show the background image of a web page. <br>
<br>
And this section helps you to understand how to add a background image in Html page using the background attribute.
</Body>
</Html>
Step 2: Place the cursor inside our HTML document's opening <body> tag. After that, type the background attribute as it appears in the block below:
<Body background=" ">
Step 3: The image path for the one we want to add must then be provided. Therefore, enter the image's path in the background attribute. Type the following path if our image is located in the same directory as the HTML file:
<Body background="filename.extension">
<Body background="image.jpg"> <br>
If our image is located in another directory, be sure to enter its correct path so that the browser can easily read it, as explained in the block below.
<Body background="/home/ishan/Desktop/images/image.jpg">
If our image is available online, we can also add it using the URL provided in the block below.
<Body background="https://images.unsplash.com/photo-1540270776932-e72e7c2d11cd?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MTh8fHxlbnwwfHx8fA%3D%3D&w=1000&q=8">
Step 4: In the text editor, we must finally save the HTML file or HTML code.
<!Doctype Html>
<Html>
<Head>
<Title>
Add the Background image using background attribute
</Title>
</Head>
<Body background="https://images.unsplash.com/photo-1540270776932-e72e7c2d11cd?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MTh8fHxlbnwwfHx8fA%3D%3D&w=1000&q=80
">
upGrad <br>
Html Tutorial <br>
This page helps us to understand how to show the background image of a web page. <br>
<br>
And this section helps you to understand how to add the background image in an Html page using the background attribute.
</Body>
</Html>
Output:
upGrad
Html Tutorial
This page helps us to understand how to show the background image of a web page
And, this section helps you to understand how to add the background image in a Html page using the background attribute.
How Do you Insert a Background Image in HTML Using Notepad?
You have to follow the following steps if you want to know how to insert a background image in HTML using Notepad:
Step 1: Open the Notepad text editor
Use Windows' Start button to search for Notepad. From the Search Results, pick Notepad and click twice. After that, your notepad text editor will launch.
Step 2: Writing HTML Image Syntax
Create an HTML image syntax that requires us to use HTML IMG tags to add and display images inside of our HTML webpage.
<img src="imageFileHere"/>
Step 3: Type the name of your image file
For assigning our image files' names, followed by the image extension, we must use SRC.
<img src="myImage.jpg"/>
Step 4: Save your HTML file
Use the File menu in the Notepad text editor to save your HTML file, or press Ctrl+S to save your HTML file directly in Notepad.
Step 5: Run your HTML file in a browser
Launch the web browser and run your HTML file.
Are you ready to unlock the power of Python? Join our Python programming course for beginners and embark on a journey of endless possibilities. Start coding today!
How to Repeat Background Image in HTML?
Repeating a background image can be useful for creating textures or patterns. By default, background images in CSS repeat both horizontally and vertically. However, you can control this behavior using the background-repeat property. Here’s how to do it:
A. Default Repeat
To repeat a background image both horizontally and vertically, you can use the following CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Repeat Background Image</title>
<style>
body {
background-image: url('path/to/your/image.jpg');
background-repeat: repeat; /* Default behavior */
}
</style>
</head>
<body>
<h1>Repeating Background Image Example</h1>
</body>
</html>
B. Horizontal Repeat Only
To repeat the background image only horizontally:
<style>
body {
background-image: url('path/to/your/image.jpg');
background-repeat: repeat-x; /* Repeats the image horizontally */
}
</style>
C. Vertical Repeat Only:
To repeat the background image only vertically:
<style>
body {
background-image: url('path/to/your/image.jpg');
background-repeat: repeat-y; /* Repeats the image vertically */
}
</style>
D. No Repeat
To prevent the background image from repeating:
<style>
body {
background-image: url('path/to/your/image.jpg');
background-repeat: no-repeat; /* Prevents the image from repeating */
}
</style>
Adding and controlling background images using CSS enhances the design of your webpage. Whether using an internal style sheet or managing image repetition, these techniques provide flexibility and ease in creating visually appealing web pages.
Conclusion
To include a background image in HTML, use the background-image property. The purpose of this article is to add an HTML background image. Either the entire web page or a single HTML element can have the background image added. Additionally, different CSS properties like background size, background attachment, or background repeat can be used to alter the background image. We have also given some insight into how to manipulate the background image using these properties of the background photo.
Now, you must be clear on how to add an image as background in HTML and how to insert a background image in HTML from the local folder.
If you are interested in pursuing a full-time career in website development, then the Software Engineering Course is the best course for you. However, if you are looking for a course that focuses more on the niche of Stack Development, check out the Executive PG Programme in Full Stack Development from IIITB.
Discover our top-rated Software Engineering courses designed to equip you with the latest industry skills and accelerate your career growth.
Explore our Popular Software Engineering Courses
Master the most sought-after software development skills with our expert-led courses, tailored to help you stay ahead in a fast-evolving tech landscape.
Explore Our Software Development Free Courses
Enhance your software development knowledge with our popular articles, offering insights and tips to boost your expertise and career.
Popular Articles related to Software Development
Get started with our free software development courses, designed to build your skills and kickstart your journey in tech.
In-Demand Software Development Skills
Explore the Best HTML Tutorials
Frequently Asked Questions (FAQs)
1. How to stretch background images in HTML?
To avoid using the same image twice, you can stretch the background image. The background-size and background-attachment CSS properties are used to achieve this.
2. How to make an image link in HTML?
Use both the <img> and <a> tags with the href attribute to link to an image in HTML. A link can be added using the a> tag, and an image can be used on a web page using the <img> tag. Add the image's URL to the src attribute of the image tag.
3. How to avoid the background image from repeating?
Specify no-repeat in the background-repeat property or the background shorthand property to prevent background images in HTML from repeating. Using the 'background-repeat' property, the background image is set to 'no-repeat'.
RELATED PROGRAMS