Skip to Content

Create a Banner with HTML and CSS — The Easy Way

Create a Banner with HTML and CSS — The Easy Way

Banners have been used in advertising for decades. To an extent, they are still effective, just not as much as they used to be. It does depend on how you use them.

Modern-day banner ads tend to use HTML5 as it can include animations, video, and more colors than a gif format could provide, and it can be interactive too.

The process (for HTML5) is complicated and usually requires at least knowledge of HTML, and a professional graphic design tool.

HTML and CSS though is another league. One of simplicity!

The process involves creating a CSS container for the banner, an image to set as the background, then any text, video scripts, or interactive elements such as a form or other function with JavaScript added.

Interactive elements on HTML banners are essentially an overlay.

 

How to create a banner with HTML and CSS

  1. Create a container in CSS
  2. Create your banner size (a border is optional)
  3. Apply a background (image or color fill)
  4. Apply additional functions
 

Step 1: Create a container in CSS

How to create a banner in HTML - Step 1

Within an HTML document, the CSS is placed between the style tags.

Two attributes are required. A selector and a class value.

A period is used to declare a selector within the style section. A matching class value is assigned to the div HTML tag in the body section.

To create a container, place a period (dot) followed by a class name between the style tags followed by a curly bracket to lead into your CSS style code.

The selector name (banner) can be changed. Between the opening and closing brackets are where you style your banner.

 

Step 2: Create your banner size (a border is optional)

How to create a banner in HTML - Step 2a

Banners can be any size you want, however, there are standard sizes generally used for website banners.

  • A leaderboard banner is 728px x 90px.
  • A large leaderboard banner is 970px x 90px.
  • A billboard banner is 970px x 250px.
  • A hero banner can be as large as 1600px x 500px as it is intended to cover the full viewport in a browser. The entire top fold of a web page is taken up with a hero banner image.

To set your banner size in HTML/CSS, apply the width and height to the line below the opening curly bracket between the style tags.

 

Adding an optional border

How to create a banner in HTML - Step 2b

If you want your banner to be completely separated from the content of the page, a border can be applied around it. Otherwise, you can set a background image that will fill the banner size that has been set.

If you want to add a border around a banner in HTML, use the border-style tag. A number of styles can be applied to show the banner area.

  • dashed
  • double
  • dotted
  • groove
  • inset
  • outset
  • ridge
  • Solid

In addition, you can set border colors, and width, and apply a radius to curve the edges of banners.

 

Step 3: Apply a background (image or color fill)

How to create a banner in HTML - Step 3

The background of banners is what makes them stand out. They can be a solid color or you can apply a background image.

If you are adding an image, it is the background-image property to apply to the banner container in CSS. Not the IMG tag in HTML.

To add a background image, use

Between the brackets is where you place the file path to the image that you want to set as a background image.

To add a solid background color, use

Change the hex color code to the color that you want.

Once the above steps are complete, call the banner up using the class value in the body or head of your HTML document.

The banner can be called anywhere in your document and as many times as you like.

Place it in the body of the content (between the opening and closing tags). If you want the banner to be visible on page load, insert the banner class in the header section.

That way, your site header will load immediately followed by your banner, and then the rest of the page content will begin to load.

 

Step 4: Apply additional functions (optional)

How to create a banner in HTML - Step 4

The reason for using HTML banners is interactivity. They engage with users better than static banners. If all you wanted was a static banner, the easy solution is to use the HTML image tag.

With HTML banners, you can include all sorts of things. Radio buttons, forms, multiple links, or at the very least, one link to the primary page you want your site visitors to visit.

Use the banner as a navigational aid. Lead users to the best part of your website by adding the HTML anchor tag.

This makes your banner clickable so that users can click to be taken to the page your banner is advertising.

The entire image does not need to be hyperlinked, and you can also make a single banner link to multiple pages by using image mapping.

All you need for that is to find the coordinates of an image in HTML and only link a section of the HTML banner.

In the banner screenshot above, the countdown timer is called and runs within the banner using JavaScript.

And the “shop now” button is hyperlinked to a store.html page using image coordinates.

With the above applied, the banner functions with a JS countdown timer and has a clickable button within it that takes the user to the linked destination page.

The huge advantage of creating a banner in HTML is that multiple functions, including scripts, can be run right within the banner to make them interactive.