Create a menu that spans the entire page using CSS

From time to time we have to ask our visitors which page they want to go to, by displaying the main sections of our website. This menu is often not very pleasant to use, so let's find out together in this article how to make it much more modern, with beautiful animations that will make your passers-by want to visit your site!
•
Updated on August 14, 2026
•
2 min read
Believemy logo

From time to time, we need to ask our visitors which page they want to go to by displaying the main sections of our website. This menu is not often very pleasant to use, so let's discover together in this article how to make it much more modern with beautiful animations that will make your visitors want to explore your site!

Image

 

Step 1

Let's start with the HTML code.

HTML
<ul>
    <li><a href="#" data-text="Home">Home</a></li>
    <li><a href="#" data-text="About">About</a></li>
    <li><a href="#" data-text="Services">Services</a></li>
    <li><a href="#" data-text="Contact">Contact</a></li>
</ul>

Nothing very complicated here: we just need a bullet list.

Note that we are using a data-text attribute; it's original but you will quickly understand why!

 

Step 2

Let's style the body tag.

CSS
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #111;
    height: 100vh;
}

Here, we center our menu in the middle of the page: vertically and horizontally, thanks to Flexbox.

 

Step 3

Now let's style our bullet list to make it more appealing.

CSS
ul {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    list-style-type: none;
}

Here, we center our menu in the middle of the page: vertically and horizontally, thanks to Flexbox.

 

Step 4

Let's work on the links.

CSS
a {
    text-transform: uppercase;
    font-size: 3em;
    color: white;
    text-decoration: none;
    font-family: sans-serif;
    display: inline-block;
    margin: 25px 0;
}

 

Step 5

Now let's create the ::before element.

CSS
a::before {
    content: attr(data-text);
    text-align: center;
    line-height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    transform: scale(0);
    font-size: 10rem;
    transition: all 0.3s;
}

In the previous step, we created the background that is displayed when we select a link from our menu.

When we use the content property, we write this time attr(data-text).

This value allows us to retrieve the text entered inside the data-text attribute of the <a> tag automatically.

 

Step 6

Let's detect the link hover.

CSS
li:hover a::before{
    transform: scale(1);
}

li:nth-child(1) a::before{
    background-color: #da4747;
}

li:nth-child(2) a::before{
    background-color: #303960;
}

li:nth-child(3) a::before{
    background-color: #dd7631;
}

li:nth-child(4) a::before{
    background-color: #95389e;
}

The nth-child selector is a pseudo-class denoted by the syntax :nth-child(n) which allows you to target each element that is the n-th child of its parent.

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Create a full-screen menu on click

Having a menu has become an indispensable classic. But having a menu that takes up the whole screen is ideal when you want your site to be totally responsive (and therefore suitable for mobile devices, for example). This article will help you to set up a full-screen menu that is activated on click!

December 9, 2024

Creating circled buttons on hover with HTML and CSS

For a menu or to encourage your readers to share your website, share buttons are essential elements to add to your website. Let's find out how to make them more modern with a "neon" effect that will surround the icon selected by your user.

December 9, 2024

Create a map displaying links on mouse-over with CSS

To present your team or simply yourself, this animation will allow you to display the links to your social networks when you hover over the map: a striking effect guaranteed! Let's find out how to do it together.

December 9, 2024

Creating a cascading animation on text

For a slogan or for an animation on a very important page of your project, this very modern effect is also very easy to achieve. Let's take a look at how to do it in this article.

December 9, 2024

Create a clean, modern timeline using html and css

Whether you want to show a purchasing process, the highlights of your career on your portfolio, or anything else, learn how to create a sleek, modern timeline to show it off!

December 9, 2024

Creating an animated list with CSS

Let's find out how to create an animated hover list!

December 9, 2024

Detecting the "swap" to close a menu with CSS

Think about your users when they visit your website on their mobile devices: allowing them to close your menu using the "swap" will make their experience on your site much easier, so you'll have a better user experience, which increases your chances of building loyalty. Let's find out how in this article!

December 9, 2024

Create an animated gradient background on hover avec CSS

Whether it's to highlight a part of your website or a quote as in this example, generating and adding a gradient to the background can give your website a very modern touch. Find out in this article how to do it easily!

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.