Skip to Content

How To Add a News and Alerts Section to Your Website


Keeping your audience informed is a core mission for every website. By adding a compact news and alerts section, you can give visitors quick access to late-breaking or urgent updates on any page.

Stop the presses: having "news" on your website is still big news. 

OK, so it's probably not a shocker... but we like flashy headlines as much as the next developer. 

News is important. That's why you probably have an entire page on your site dedicated to it, where visitors can see all your activity. But when someone hits your homepage, it's helpful to feature a bite-sized set of entries. This can be done by creating a shorter, more compact section that features your news and alerts in one place.

It's not that different from the front page of a newspaper, which gives you the latest-breaking stories with the option to flip to other pages to read more. Remember newspapers?

In this tutorial, we'll show you how to build a news and alerts section in a neat grid system – perfect for living anywhere on your website. You can list them side by side using Bootstrap columns, so your visitors can peruse the latest headlines while getting updated on critical issues. You can also add images and icons to help your headlines jump off the page and hook your reader in the right manner. We've got an example below, but you can get creative with how you display it.

 

The difference between "news" and "alerts"

Generally speaking, your news can behave a lot like your blog (and in some cases, might even be your blog). The latest articles can be displayed in attractive, well-organized managers that provide a great user experience. The difference is in how you're engaging with your audience around the nature of your news. Maybe you're featuring things like press releases or updated product features, but in truth, "news" is whatever your organization feels is "newsworthy."

Alerts are a little different, as they tend to connote a sense of urgency. With alerts, you might want your audience to take action due to an event or even a crisis – things like road closures or service interruptions. In our COVID-19 series, we showed you how to build a customizable alert bar for your website, so you can keep your customers informed during an emergency like a pandemic (hopefully that's a rare occurrence).

Alerts are still news, but with a much stronger spotlight. To that end, you can also use tagging or categories to distinguish between the two versus having dedicated pages. That said, for some organizations, subscribing to alert feeds or services might require an independent page or manager, so it's really driven by your needs. 

With your website, you can own your news and alerts without relying solely on other channels. Sure, they provide the distribution – but if you're feeding your SEO the right way, you can really optimize the performance of your news section and drive greater traffic and awareness. Better still, you can integrate with those outside channels to expand your reach. 

Extra, extra – we've got the code to bring this life! Keep reading.

 

Getting Started

Since we're using Bootstrap to build our section, go ahead and copy and paste the links below in the head section of your project's HTML file:

HTML

In the HTML code below, we have a main section to house both the news and the alerts. We used the classname .section--news to make it more identifiable and easily select in the CSS file to style it. It is using the Bootstrap grid elements and columns which makes it easier to adjust their width. Both the news and the articles columns are half the width of the section. In smaller screens, the columns take up the full width. We do this by giving each column div a classname of .col-lg-6 .col-12. In Bootstrap, all divs are divided into 12 columns so col-6 spans 6 of 12 columns making up half the width and col-12 spans 12 of 12 columns making up the full width. 

The news and alerts rows are made up of div elements with a classname of .box-news. They're structurally the same except the news rows have an additional img element to display images. Copy and paste the code below in your project:

CSS

Since most of the layout adjustment and spacing was done via Bootstrap's built-in classes used in the HTML file, we set properties such as colors, font sizes, and link styling via CSS. Feel free to change the color and the styling of the fonts to match your website's branding:

And there it is! Check out the JSFiddle below to see the demo before committing to its use:


Paris Tuzun
Contributions Editor here at Solodev. Want to be featured on the Solodev Blog? Get in touch.
Follow me on Twitter

Sign up to explore

Create an account in seconds and start building today.

Sign up for Solodev