How To Create a Static Footer With HTML and CSS (Section 7)


In the final tutorial of the CSS series, you will create a static footer that stays in a fixed position at the bottom of the viewport as the visitor scrolls down the page. This tutorial will recreate the footer in the demonstration website but you can use these methods for other website projects as well.

Gif of static footer on demonstration website


To follow this tutorial, make sure you have set up the necessary files and folders as instructed in a previous tutorial in this series How To Set Up You CSS and HTML Practice Project.

This tutorial uses several social media icons as content in the footer. If you’d like to use these icons, download them now from our demonstration site and save them to your images folder as:

  • “twitter.jpeg”
  • “github.jpeg”
  • “email.jpeg.”

To download these images, click on the linked filename above and then click CTRL + Left Click (on Macs) or Right Click (on Windows) while hovering on the image and select “Save Image As”. Save the images with the instructed file names to your images folder.

Once you have your icons saved, you can proceed to the next section.

Adding a Class To Style Your Footer

First you will define a “footer” class by adding the following code snippet to the bottom of the styles.css file:


. . .  /* Footer */  .footer {   position:fixed;   bottom:0;   left:0;   width:100%;   height: 90px;   background-color: #D0DAEE; } 

Save the styles.css file. In this code snippet you have added a comment to label the CSS code for the Footer section. You then defined a class named footer and declared several style rules. The first rule declares its position as fixed, which means the element will not move from the location you specify as the user scrolls down the page. This location is specified by the next two declarations: bottom:0 and left:0, which specifies a location zero pixels from the left and zero pixels from the bottom of the browser’s viewport.

By changing these values, you can change the location of the element on the page. Note, however, that any value aside from zero needs to include the px suffix after the number. The ruleset also specified the width, height, and background color of the footer class.

You are now ready to add the footer content in the next section of this tutorial.

Adding a Footer Styled With Your Footer Class

To add the footer content, you will add a <div> container to the webpage and assign the footer class that you just created. Return to your index.html file and paste the following code snippet after the end of the last closing </div> tag:


. . .  <!--Section 7: Footer-->  <div class="footer"> </div> 

Save your index.html file and reload it in the browser. (For instructions on loading an HTML file, please visit our tutorial step How To View An Offline HTML File In Your Browser).
You should now have an empty footer section at the bottom of your webpage that stays in place as you scroll up and down the page:

Gif of blank fixed footer

Next you will add content to the newly created footer.

How To Add and Style Menu Items To Your Footer

In this step, you will add and style the menu items to the left side of the footer. These menu items can be used to link to other pages on your site. Currently, there is only one webpage on your site, so you can use the links we provide for demonstration purposes. Later on, if you add additional pages to your website you can create menu items here and add the correct links. You can learn how to create and link to new webpages with this tutorial on How to Build a Website with HTML.

Return to your styles.css file and add the following code snippet to the bottom of the file:


. . .  .footer-text-left {   font-size:25px;   padding-left:40px;   float:left;   word-spacing:20px; } {   background-color:yellow;   font-size:20px; } 

Let’s pause briefly to review each of the rulesets we’ve created:

  • The first ruleset defines a class named footer-text-left that will be used to style the menu item text. Note that you are setting the float property to left so that the text assigned to this class will float to the left of the page. You are also using the word-spacing property to grant extra space between the menu items. If any of your menu items are more than one word, you’ll need to create a class for styling the menu items (instead of just changing the word spacing value).

  • The second ruleset uses the hover pseudo-class to add a yellow background color to the text when the user hovers their cursor over the text.

Now you will add the menu items to the webpage. Return to your index.html file and add the following highlighted code snippet inside the footer container that you’ve already created:


. . .  <div class="footer">   <p class="footer-text-left">     <a href="index.html" class="menu">home</a>     <a href="" class="menu">about</a>      <a href="" class="menu">credits</a>   </p> </div>  

This code snippet adds two menu items (“about” and “credits”), links these menu items, and styles the text with the footer-text-left and classes you just created.

Save both files and reload your webpage in the browser. You should receive something like this:

Gif of footer with menu items

Adding Social Media Icons

Next you will add the social icons to the footer, which you can use to link to your social media accounts. If you want to use icons for different social media platforms, you can search for free icons on the web and download them to your images folder. Return to your styles.css file and add the following three rulesets to the bottom of your file:


. . .  .footer-content-right {   padding-right:40px;   margin-top:20px;   float:right; }  .icon-style {   height:40px;   margin-left:20px;   margin-top:5px; }  .icon-style:hover {   background-color:yellow;   padding:5px; } 

Let’s pause to review each ruleset:

  • The first ruleset defines the class footer-content-right and assigns it specific padding, margin, and float values. You will use this ruleset to style a <div> element that will hold the social media icons.

  • The second ruleset creates the class icon-style that will provide height and margin values to the size and position of the social media icons.

  • The third ruleset uses the hover pseudo-class to add a yellow background to the icon when the user hovers their cursor over the text.

Save your styles.css file. You will now add the social media icons to the footer. Return to your index.html file and add the following code snippet after the last closing </a> tag of the menu items:


. . .  ... <div class="footer-content-right">   <a href=""><img src="images/github.jpeg" class="icon-style" alt="Github icon"></a>   <a href=""><img src="images/twitter.jpeg" class="icon-style" alt="Twitter icon"></a>   <a href=""><img src="images/email.jpeg" class="icon-style" alt="Emailicon"></a> </div> 

Make sure that you change the file paths and links with your own social media information.

This code snippet creates a <div> container, which is assigned the style of footer-content-right the class. Inside this div container, you have added three social media icons using the HTML <img> tag, and linked each image using the HTML <a> tag.

You have also added the alternative text that describes each icon using the alt attribute. When creating websites, alternative text should be added to all images to support site accessibility for individuals who use screen readers. To read more about using alternative text with HTML, please visit the section on alternative text in our guide How To Add Images To Your Webpage Using HTML.

Save your index.html file and reload it in the browser. You should now have a fixed footer with three social media icons on the right that link to your accounts. The links should change color when the user hovers their cursor over them. To confirm your results, you can compare them to the gif at the beginning of this tutorial.


You have now created a static footer that stays in a fixed position at the bottom of the viewport as the visitor scrolls down the page. You can continue exploring footer design and content possibilities by changing values in the CSS classes that you created, or add different types of content to your index.html file. For more ideas on exploring design and layout possibilities for your website, the conclusion of this tutorial series has more suggestions for things to try like rearranging content sections, adding links to other pages, and changing layout styles using the box model.