Helder Esteves

Type and hit Enter to search

JavaScript
Uncategorized
Software Architecture
React
General
Management
Next.JS
TypeScript
JavaScript
Uncategorized
Software Architecture
React
General
Management
Next.JS
TypeScript
JavaScript

Simple Backgrounds For Websites — Cheat Sheet

Helder Esteves
Helder Esteves
February 21, 2023 3 Mins Read
76 Views
0 Comments

Let’s talk about simple backgrounds that you can use on your website! You probably test a lot of backgrounds when creating a new page, so this cheat sheet will help you pick the one that suits you best.

Changing the background

First, for the beginners, you mainly have 3 ways to change the background of a web page:

Using HTML, search for “<body” in your HTML file:

<body style="background-color:blue;">
...
</body>

Using CSS, add a “body” block if it doesn’t exist already in your CSS file (or inside a <style> tag in HTML):

body {
  background-color: "blue";
}

Not so common, but an option nonetheless, is using JavaScript. Just add this line to your JS file (or inside a <script> tag in HTML):

document.body.style.backgroundColor = "blue";

Note: Check out all the background properties you can use here

You can also use backgrounds on many types of elements in HTML, such as <div>, <table>, etc… Give it a try!

Let’s now move on to the list of backgrounds you won’t regret using!

Basic backgrounds

We’ll be using CSS to show off the different background styles, but you’re able to adapt them to HTML or JS (if you really want to).

Solid color

body {
  background-color: "blue";
}

Example Website: Google

Gradient backgrounds (linear)

body {
  background: cyan; /* fallback color */
  background: linear-gradient(90deg, blue 0%, cyan 100%);
}

Example Website: Spotify

Gradient backgrounds (radial)

body {
  background: cyan; /* fallback color */
  background: radial-gradient(circle at center, red 0, cyan 100%);
}

Background with image

body {
  background-color: white; /* needed to cover the parts that the image doesn't */
  background-image: url('bottom-image-example.jpg');
  background-repeat: no-repeat;
  background-size: contain; /* make the image responsive */
  background-position: center bottom; /* "center top" is also common to use*/
}

Example: Linkedin (bottom), Amazon (top)

Image pattern background

body {
  background-image: url('pattern-example.jpg');
  background-repeat: repeat;
}

Note: A good tool you can use for icon pattern backgrounds like this one is patternico

Example: Whatsapp (inside the messenger)

Image covering the background

body {
  background-image: url('cover-image-example.jpg');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center top;
}

Example: Tumblr

Fixed image covering the background

body {
  background-image: url('cover-image-example.jpg');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  background-attachment: fixed; /* always relative to the viewport */
}

Example: Quora

Advanced backgrounds

You won’t be able to use these backgrounds with the HTML option. The best way is to use CSS for these.

Animated solid background

body {
  background-color: blue;
  animation: animatedSolidBg 30s linear infinite; /* change the animation time here */
}
@keyframes animatedSolidBg {
  0%{background-color: blue}
  50%{background-color: cyan}
  100%{background-color: blue}
}

Animated gradient background

body {
    background: linear-gradient(135deg, blue, cyan, yellow); /* change the colors and angles here */
    background-size: 500% 500%;
    animation: animatedGradientBg 40s ease infinite; /* change the animation time here */
}
@keyframes animatedGradientBg {
    0%{background-position:0% 0%}
    50%{background-position:100% 100%}
    100%{background-position:0% 0%}
}

There are plenty of more ways to make backgrounds interesting. You could, for example, generate random colors for the background using JavaScript. You could also use libraries such as particles.js to have an awesome background.

A word of advice, though: most of the time, you want to stick to the more simple ones because, well, a background is a background. It’s meant not to call too much attention to the user, so bear it in mind.

As always, if you have any questions or something of the sort, reply to this post, I’ll be sure to reply back!

Tags:

Beginner

Share Article

Other Articles

Previous

Generating Random Colors in JS + Dark, Light colors

brown rope on black background
Next

The Crash Course on Node Redis

Next
brown rope on black background
March 3, 2023

The Crash Course on Node Redis

Previews
February 18, 2023

Generating Random Colors in JS + Dark, Light colors

No Comment! Be the first one.

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Subscribe
    Stay Updated!
    Get notified when awesome content is posted. Learn more everyday.
    Most Read
    Software Architecture
    5 JS Design Patterns Every Developer Should Know
    March 10, 2023
    5 Min Read
    yellow line on gray asphalt road
    Next.JS
    5 Next.JS Tips You Never Heard About
    March 27, 2023
    4 Min Read
    blue UTP cord
    Uncategorized
    Setting up a TURN server with Node: Production-ready
    May 19, 2023
    5 Min Read
    Most Engagement
    brown rope on black background
    Uncategorized
    The Crash Course on Node Redis

    Learn everything you need to know for Node Redis! The only article you'll need to read, from...

    March 3, 2023
    4 Min Read
    Most Recent
    grayscale photo of person holding glass
    JavaScript
    Top 10 JavaScript Coding Challenges You Must Absolutely Know
    May 17, 2023
    9 Min Read
    a person pointing at a rock with writing on it
    JavaScript
    7 Best Coding Challenge Websites for 2023: Improve Your Skills and Boost Your Career
    May 20, 2023
    5 Min Read
    blue UTP cord
    Uncategorized
    Setting up a TURN server with Node: Production-ready
    May 19, 2023
    5 Min Read

    Related Posts

    Software Architecture
    5 JS Design Patterns Every Developer Should Know
    March 10, 2023
    5 Min Read
    Read More
    opened secret door inside library
    JavaScript
    5 JavaScript Features You Didn’t Know About
    March 6, 2023
    2 Min Read
    Read More
    low angle of black metal tower
    General
    Top 5 Cross-platform Frameworks to Use in 2023
    March 12, 2023
    4 Min Read
    Read More
    JavaScript
    The Ultimate Sith Lord Developer Guide
    April 28, 2023
    5 Min Read
    Read More

    Helder Esteves

    Read everything there is to know about the JavaScript development ecosystem, from programming to project management.

    Recent

    7 Best Coding Challenge Websites for 2023: Improve Your Skills and Boost Your Career
    May 20, 2023
    Setting up a TURN server with Node: Production-ready
    May 19, 2023

    Categories

    JavaScript9
    Uncategorized4
    Software Architecture2
    React2

    Contact

    Reach out to us through helder.writer@gmail.com

    © 2022, All Rights Reserved.

    Go to mobile version