Wednesday, November 15, 2023
HomeEmail MarketingA Information to Coding HTML Background Colours

A Information to Coding HTML Background Colours



Black and white is traditional, however how about utilizing HTML/CSS background colours to make your electronic mail advertising and marketing campaigns pop? In spite of everything, shade psychology has a big effect in your readers.

In different articles, we’ve mentioned how you can type your emails with HTML and CSS, and we’ve given you tips about how you can code a bulletproof background. Now, we’re going again to fundamentals and speaking about how you can add background shade in HTML and CSS. Let’s dive in.

How do I take advantage of colours in HTML?

Let’s paint the city crimson. Effectively, not the city, per se. Let’s begin with the background of an HTML electronic mail template.

Right here’s a easy HTML code that units the HTML background shade to crimson:

<physique type="background-color:crimson;">INSERT CONTENT HERE.</physique>

Right here, we used an HTML shade title, “crimson,” to specify the background-color.

There are just a few methods to refer to colours in HTML, together with:

  1. HTML shade title
  2. Hex shade code
  3. RGB worth
  4. HSL worth

Try this shade picker for the assorted HTML shade codes, and let’s dive into every of those in additional element beneath.

1. HTML shade title

The HTML shade title might be probably the most intuitive option to specify a shade in HTML. Within the earlier code pattern, you merely use the HTML shade title to specify the colour in your background. Try W3C’s useful record of HTML shade names.

2. Hex shade code

Hex shade codes encompass a hashtag “#” adopted by a sequence of six letters and/or numbers. For instance, the Hex shade code for crimson is #FF0000. You’ll be able to set your background-color to crimson through Hex shade code with the next code:

<physique type="background-color:#FF0000;">INSERT CONTENT HERE.</physique>

3. RGB worth

RGB refers to crimson, inexperienced, and blue. These three colours of sunshine combine to create all different colours, together with white. Utilizing RGB, you may specify a shade with three numeric values, starting from 0 to 255, and representing the values for crimson, inexperienced, and blue. By assigning values to rgb (crimson worth, inexperienced worth, blue worth, alpha worth) to seek out your required shade. Right here’s the pattern code utilizing RGB values to set your background-color as crimson:

<physique type="background-color:rgb(255,0,0);">INSERT CONTENT HERE.</physique>

On this instance, the primary worth (crimson) is 255, which is the utmost worth, and the following shade values for inexperienced and blue to 0. These values combine, producing the colour crimson.

RBGA provides one other worth to RBG to incorporate extra customization. The final worth, the alpha channel, permits you to specify the opacity of the colour. You’ll be able to write RBGA as rgb (crimson worth, inexperienced worth, blue worth, alpha worth). Purple, inexperienced, and blue take a price of 0 to 255 and alpha takes a price between 0 for absolutely clear to 1.0 for absolutely opaque. Try the next code, which is a half-transparent crimson background-color:

<physique type="background-color:rgb(255,0,0,0.5);">INSERT CONTENT HERE.</physique>

4. HSL worth

HSL, which stands for hue, saturation, and lightness, is one other set of values used to “combine” chosen colours. The syntax to specify HSL worth is much like that for RGB because it consists of three values. Try the pattern code to specify a crimson background utilizing HSL: First, a price from 0 to 255 specifies the hue. Then, a proportion from 0% to 100% signifies the saturation. Lastly, a proportion from 0% to 100% dictates the lightness.

<physique type="background-color:hsl(0,100%,50%);">INSERT CONTENT HERE.</physique>

Similar to with RGBA, HSL will be prolonged with an alpha channel that takes a price between 0 for absolutely clear to 1.0 for absolutely opaque. Try the instance beneath. The primary three values are the identical as within the instance above. The final parameter is a price between 0 and 1.0 that signifies the transparency of your shade.

<physique type="background-color:hsla(0,100%,50%,.5);">INSERT CONTENT HERE.</physique>

How can I code background colours in an electronic mail?

Now that we all know how you can reference colours we wish to use in HTML electronic mail backgrounds, let’s go over how you can code colours into emails. There are just a few methods so as to add a background shade to your electronic mail:

  • Utilizing inline CSS
  • Utilizing exterior type sheets
  • Utilizing embedded types within the <head> part of your electronic mail 

We used inline CSS to type our background shade within the earlier examples. We’ll proceed to make use of inline CSS on this part since exterior type sheets and embedded types typically break emails and have an effect on your deliverability and accessibility.

If you happen to want a refresher, try our HTML coding 101. With out additional ado, let’s break down the code samples we’ve used thus far.

<physique type="background-color:crimson;">Right here’s some textual content over a crimson background.</physique>

Right here’s how you can add background shade in HTML, primarily based on the earlier code pattern:

  1. Establish the HTML component you wish to apply the background shade to. On this case, you’ll apply the background shade to the component <physique>. Subsequent, you’ll modify the background-color of this tag in HTML.
  2. Add a method attribute. Within the pattern above, that is type. Set the attribute with the equal signal “=” adopted by a number of CSS selectors and related values.
  3. Decide the suitable CSS selector. To set the background shade, we’ll use the CSS selector background-color.
  4. Use an HTML shade code. Specify your background shade with an HTML shade code, like an HTML shade title, Hex shade code, RGB worth, or HSL worth.

And that’s it! Your end result ought to look one thing like this:

Generated with https://jsfiddle.internet/.

What else can I do with HTML background colours?

Now you already know the fundamentals, however there’s way more you are able to do with HTML background colours. Right here are some things to strive:

  • Wish to change only a particular part of your electronic mail? You’ll be able to add background colours to particular components by referring to their HTML tag, like <div>, <physique>, or <p>.
  • Do you assume plain, stable backgrounds are boring? We do too. You’ll be able to add gradients to your background shade – extra on that subsequent. 

Similar to you may set one shade as your background in your HTML electronic mail template, you may as well specify two colours and mix them with a gradient. This gives an attention-grabbing impact and permits you to seamlessly mix two background colours in your electronic mail design.

Try the next pattern code, which blends crimson and black from left to proper:

<physique type = "background-color: linear-gradient(to proper, #FF0000, #000000);">Is not this gradient nice?</physique>

Specify the physique component with the <physique> tag. Then, modify the physique’s <type> attribute by setting background-image to a linear gradient that goes from left to proper, ranging from the colour crimson (#ff0000) to black (#000000).

That is the results of the code above:

HTML background with red to black gradient
Generated with https://jsfiddle.internet/.

However what about accessibility?

Bear in mind your shade decisions have a serious impression on readability and electronic mail accessibility. 

You’re already taking a giant step in direction of electronic mail accessibility when utilizing background colours as a substitute of background photographs. The truth is, we don’t suggest utilizing background photographs as a result of they could take longer to load, and a few electronic mail shoppers don’t help them.

However right here’s crucial consideration for accessibility…

Because the textual content of your electronic mail might be positioned on prime of the background, you must make sure you’re utilizing acceptable shade distinction between the background and textual content colours. In our gradient instance, it’s straightforward to see that our black textual content would begin disappearing if it went a lot additional.

Clearly, you’ll need mild textual content on a darkish background and vice versa. Nevertheless, take into account that sure shade mixtures are more durable to learn. You’ll additionally want to think about folks with various kinds of shade blindness when coding background colours. For extra recommendation, try our article on bettering electronic mail accessibility with shade distinction.

How does darkish mode have an effect on HTML electronic mail backgrounds?

So that you’ve acquired your colours down pat now, proper? Effectively, not fairly. Remember the fact that a few of your readers might browse your emails in darkish mode. And, electronic mail background colours don’t at all times play good with darkish mode. The truth is, some electronic mail shoppers merely invert your electronic mail colours when your subscriber has darkish mode enabled. Discover ways to optimize your electronic mail for darkish mode so your emails show as meant.

Wrapping up

There are some things to recollect: Utilizing background photographs isn’t at all times a good suggestion as a result of they could take longer to load, some electronic mail shoppers don’t help them, and so they can impression your electronic mail’s accessibility. However in the event you do all the things accurately and set in place the correct fallbacks, you’ll be sending lovely, partaking emails very quickly.

Regardless of the way you code your electronic mail background, be sure that to check and preview it earlier than you hit ship. That approach you may catch potential points in dozens of various electronic mail shoppers… which don’t at all times play good along with your code and electronic mail design.

Prepared to begin sending the best-looking emails? Test that your HTML background colours show as meant with our electronic mail testing instruments at E mail on Acid. Strive us out totally free for seven days!

Creator: The E mail on Acid Staff

The E mail on Acid content material staff is made up of digital entrepreneurs, content material creators, and straight-up electronic mail geeks.

Join with us on LinkedIn, observe us on Fb, and tweet at @EmailonAcid on Twitter for extra candy stuff and nice convos on electronic mail advertising and marketing.

Creator: The E mail on Acid Staff

The E mail on Acid content material staff is made up of digital entrepreneurs, content material creators, and straight-up electronic mail geeks.

Join with us on LinkedIn, observe us on Fb, and tweet at @EmailonAcid on Twitter for extra candy stuff and nice convos on electronic mail advertising and marketing.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments