All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Create Simple Notification Bar Using jQuery And CSS

Last Updated : Jul 1, 2023

IN - jQuery CSS HTML | Written & Updated By - Pragati

In this tutorial we will create a simple Notification Bar using jQuery and CSS, Notification bar is an area used to display recent updates and offers to user it is used in modern websites to display offers and updates to user it is fast and easy way to display information without sending user to different page.

You may also like Play Sound On Notification Using JavaScript And CSS

Create Simple Notification Bar Using jQuery And CSS

To Create Notification Bar It Takes Only Two Steps:-

  1. Make a HTML file and define markup and scripting
  2. Make a CSS file and define styling

Step 1. Make a HTML file and define markup and scripting

We make a HTML file and save it with a name notification_bar.html

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<link rel="stylesheet" type="text/css" href="notification_bar_style.css">
<script>
 function notification()
 {
  $("#notification_div").slideToggle(300);
 }
</script>
</head>
<body>
<div id="wrapper">

 <div id="notification_div">
  <span>Yesterday - You Have One Notification Pending From Yesterday</span>
  <br>
  <span>Today - You have No Notifications On Today</span>
 </div>

 <p id="show_notification" onclick='notification();'>Click To Show/Hide Notification Bar</p>

</div>
</body>
</html>

In this step we made a div for notification bar and a paragraph which is used to show and hide the notification whenever user clicks on it.

We use jQuery slideToggle() function to show hide notification bar you can use what you want.

Step 2. Make a CSS file and define styling

We make a CSS file and save it with a name notification_bar_style.css

body
{
 width:100%;
 margin:0 auto;
 padding:0px;
 background-color:#A9D0F5;
 font-family:helvetica;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:100%;
}
#notification_div
{
 height:100px;
 margin:0px;
 background-color:#2E9AFE;
 display:none;
 padding:40px;
}
#notification_div span
{
 padding:15px;
 background-color:#084B8A;
 color:#A9D0F5;
 border-radius:5px;
}
#show_notification
{
 padding:12px;
 margin:0px;
 background-color:#0174DF;
 vertical-align:bottom;
 color:#E0ECF8;
 font-weight:bold;
 font-size:17px;
 border-top:10px solid #045FB4;
 border-bottom:10px solid #045FB4;
 cursor:pointer;
}

In this step we give some general styling to notification bar and we hide the notification bar because we want to display the notification only when user clicks on notification para.

Thats all, this is how to create simple Notification Bar using jQuery and CSS. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on notification bar jquery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪