Open In App

How to create a gradient navbar using HTML and Inline CSS ?

A gradient navbar is a stylish way to make your website look modern and professional. In this article, we will show you how to create a gradient navbar using HTML only. No CSS or JavaScript is required.

Approach: Please refer linear-gradient() method to create a gradient background.



HTML Code: 

Step 1: Create the HTML structure. The first step is to create the HTML structure of the navbar. The following is an example of a simple navbar.






<!DOCTYPE html>
<html>
  
<body>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
    <h1 style="color:green">GeeksforGeeks</h1>
    <p>Default code has been loaded into the Editor.</p>
</body>
  
</html>

Step 2: Add the gradient effect

To add the gradient effect, you can use the background-image property in the HTML nav element. The gradient effect can be created using a CSS linear-gradient() function that specifies the start and ends colors of the gradient. 




<!DOCTYPE html>
<html>
  
<body>
    <nav style="background-image:linear-gradient(
                to right, #00bfff, #00ffd5);">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <p>
        Default code has been 
        loaded into the Editor.
    </p>
</body>
  
</html>

You can choose any two colors you like for the gradient effect. The `to right` keyword specifies the direction of the gradient.

Step 3: Style the Navbar

Now, you have added the gradient effect, you may want to style the navbar to make it look more professional. You can do this by adding some CSS styles to the nav element and the ul element.

Example 1: The following demonstrates the gradient navbar using the above steps and references.




<!DOCTYPE html>
<html>
  
<body>
    <nav style="background-image:linear-gradient(
                to right, #00bfff, #00ffd5);
                padding: 10px 0;">
        <ul style="list-style:none;
                   display:flex; 
                   justify-content:space-between;">
            <li style="margin:0 10px;">
                <a href="#">Home</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">About</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Services</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Contact</a>
            </li>
        </ul>
    </nav>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <p>
        Default code has been 
        loaded into the Editor.
    </p>
</body>
  
</html>

Output:

 

Example 2: This code will create a gradient that goes from a red-pink (#ff4b2b) to a deep pink (#ff416c), then to the red-pink again (#ff4b2b), then to an orange (#ff7519), and finally to a bright yellow (#ffb900).




<!DOCTYPE html>
<html>
  
<body>
    <nav style="background: linear-gradient(
                to right, #ff4b2b, #ff416c, 
                #ff4b2b, #ff7519, #ffb900); 
                padding: 10px 0;">
        <ul style="list-style:none;
            display:flex; 
            justify-content:space-between;">
            <li style="margin:0 10px;">
                <a href="#">Home</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">About</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Services</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Contact</a>
            </li>
        </ul>
    </nav>
  
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <h2 style="color:green;">
        Welcome To GFG
    </h2>
      
    <p>
        Default code has been 
        loaded into the Editor.
    </p>
</body>
  
</html>

Output:

 

Example 3: The gradient uses three color stops: #9acd32 (a light green), #ffeb3b (a bright yellow), and #006400 (a dark green). These colors are specified in the order they should appear in the gradient.




<!DOCTYPE html>
<html>
  
<body>
    <nav style="background-image:linear-gradient(
                to right, #9acd32, #ffeb3b, #006400);
                padding: 10px 0;">
        <ul style="list-style:none;
                   display:flex; 
                   justify-content:space-between;">
            <li style="margin:0 10px;">
                <a href="#">Home</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">About</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Services</a>
            </li>
            <li style="margin:0 10px;">
                <a href="#">Contact</a>
            </li>
        </ul>
    </nav>
      
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
</body>
  
</html>

Output:

 

Conclusion: Creating a gradient navbar using HTML is an easy and uncomplicated procedure that can give your website a sleek and contemporary appearance. By using a few lines of code, you can effortlessly add a touch of style and elegance to your website’s navigation bar. This method is especially advantageous when you don’t have the luxury of using CSS or JavaScript, or when you need to create a basic navigation bar swiftly. Overall, it is a simple yet effective way to enhance the aesthetic appeal of your website without having to rely on more complex design techniques.


Article Tags :