Building a Simple News Website: Enhance your Front-end Development Skills using HTML, CSS, and Bootstrap Print

  • 0

Building a news website is a great way to practice your front-end web development skills. It's a project that is not overly complex, yet will challenge you to create a responsive, visually appealing layout and implement key functionalities.

In this article, we will walk through the creation of a simple news website using HTML, CSS, and Bootstrap.

Required Tools & Technologies:


1. HTML
2. CSS
3. Bootstrap (for quick and responsive design)

Step-by-Step Guide

 1. Setting up the HTML structure

We begin by setting up our HTML structure. It's here where we will add our main content sections: a header for the site title, a navigation bar for categories, and a main section to display news articles.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>News Website</title>
<!-- link to Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- link to custom CSS -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>News Website</h1>
</header>
<nav id="navbar">
<!-- Navigation items will be added here -->
</nav>
<main id="news-section">
<!-- News items will be added here -->
</main>
</body>
</html>

2. Styling the Header with CSS

Next, let's style our header with CSS to make it more attractive. We'll also style the text in the header to give it a distinctive look.


header {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}

header h1 {
font-size: 2em;
}

3. Creating the Navigation Bar with Bootstrap

Bootstrap's navbar component makes it easy to create a responsive navigation bar. We add this in the `nav` section of our HTML:


<nav id="navbar" class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">News Categories</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Politics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Technology</a>
</li>
<!-- More categories can be added here -->
</ul>
</div>
</nav>

4. Adding News Articles with Bootstrap Cards

Finally, let's add some news articles. For this, we can use Bootstrap's card component, which is a great way to display small snippets of content. Each article will have a title, an image, and a short description.


<div id="news-section" class="container">
<div class="row">
<div class="col-lg-4 col-md-6 col-sm-12">
<div class="card">
<img src="news1.jpg" class="card-img-top" alt="News 1">
<div class="card-body">
<h5 class="card-title">News Article 1</h5>
<p class="card-text">Short description of the news article...</p>
<a href="#" class="btn btn-primary">Read More</a>
</div>
</div>
</div>
<!-- More news articles can be added here -->
</div>
</div>

Remember, this is just the beginning. To enhance your front-end skills, you can extend this project with more features. You could add a comments section under each news article, add a login functionality, or even integrate with a news API to pull in real-time news articles.

let's move on to some additional features that can be added to this news website to enhance your frontend development skills.

Adding a Carousel for Featured News

One popular feature on news websites is a carousel or slideshow at the top of the page, featuring the latest or most important news. We can achieve this using the Carousel component from Bootstrap.

Here's a basic example of how you can implement this in HTML:


<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="news1.jpg" class="d-block w-100" alt="News 1">
<div class="carousel-caption d-none d-md-block">
<h5>News 1</h5>
<p>Short description of the news...</p>
</div>
</div>
<!-- More carousel items can be added here -->
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>

Remember to place the carousel at the appropriate spot in your HTML file (likely under the header and above the main news section).

Adding a Sidebar for Additional Content

Adding a sidebar to your news website can be beneficial for presenting additional information, like trending articles, recent posts, tags, or advertisements. With Bootstrap's grid system, adding a sidebar is straightforward.

Here's a basic example of how you can add a sidebar to your news section:


<div id="news-section" class="container">
<div class="row">
<!-- Main news section -->
<div class="col-lg-8">
<!-- News articles here -->
</div>

<!-- Sidebar section -->
<div class="col-lg-4">
<h2>Trending News</h2>
<ul class="list-group">
<li class="list-group-item">Trending Article 1</li>
<li class="list-group-item">Trending Article 2</li>
<!-- More articles can be added here -->
</ul>
</div>
</div>
</div>

In this example, the Bootstrap grid is divided into 12 columns, with the main section taking up 8 and the sidebar section taking up the remaining 4.

These are just two examples of how you can enhance your news website and thereby develop your frontend skills. Remember, it's not only about creating a website but also about creating a pleasant user experience. Continue to explore and experiment with different components and designs as you refine your abilities.

Alright, let's take this a step further and integrate a feature that can give you some interactive experience - a search bar. Adding a search bar to your website enables users to look up articles based on keywords, making navigation easier.

Adding a Search Bar

Bootstrap provides an input group component which is perfect for building a search bar. We can add this in our navbar:


<div class="input-group">
<input type="text" class="form-control" placeholder="Search for news">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">Search</button>
</div>
</div>

Please note that to make the search bar functional, you'll need to employ JavaScript or a backend technology, which is beyond the scope of this article.

Enhancing User Experience with a Sticky Navigation Bar

A sticky navigation bar can enhance the user experience as it allows users to navigate through the website from anywhere on the page. We can make our navbar sticky by adding a few lines of CSS:


#navbar {
position: sticky;
top: 0;
z-index: 1000;
}

With these additions, you should now have a well-rounded news website that provides a solid foundation for practicing front-end web development. Remember, the best way to learn is by doing. Don't hesitate to experiment with different styles, components, and features.

A news website is a versatile project with plenty of scope for customization and expansion. You might consider integrating a news API for real-time news updates, incorporating a login and user registration system, or adding interactive features like a comments section or voting system for articles.

The more you practice and experiment, the more comfortable you'll become with HTML, CSS, and Bootstrap, and the more advanced your front-end development skills will become.

Add a Footer to Your News Website

Footers often contain information like contact info, social media links, or a short about us section. Let's add a simple footer to our website using HTML and style it with CSS.


<footer>
<div class="footer-content">
<p>About Us</p>
<p>Contact: info@newswebsite.com</p>
<p>Follow us on social media!</p>
</div>
</footer>

And now the CSS:

css
footer {
background-color: #333;
color: white;
text-align: center;
padding: 20px;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
}

Adding Social Media Icons

To help users connect with you on various social media platforms, you can add social media icons in the footer. This can be done using Font Awesome, a popular icon library.

First, include Font Awesome in your HTML file:


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

Then, you can use the icons like this:


<div class="social-media-icons">
<a href="#" class="fa fa-facebook"></a>
<a href="#" class="fa fa-twitter"></a>
<a href="#" class="fa fa-instagram"></a>
<!-- Add as many as you like -->
</div>

Style these icons as desired with CSS. For example:

css
.fa {
padding: 15px;
font-size: 20px;
width: 50px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
}

.fa:hover {
opacity: 0.7;
}

.fa-facebook {
background: #3B5998;
color: white;
}

.fa-twitter {
background: #55ACEE;
color: white;
}

.fa-instagram {
background: #125688;
color: white;
}

 Implementing a Dark Mode

A dark mode toggle can enhance the user experience, especially for users who prefer a darker color scheme. This can be implemented using a bit of JavaScript along with CSS. However, since the scope of this project is only HTML, CSS, and Bootstrap, you can learn about this once you're comfortable with JavaScript.

Remember, the best way to learn frontend development is to practice. Try to build this project from scratch, experiment with different styles, add new features, and make the project your own. 

At this point, we've built a solid foundation for a news website. You've got a navbar, a main content area featuring news cards, a featured news carousel, a search bar, a sidebar for additional content, and a footer with social media links. Let's explore some more advanced functionalities that you can consider for further learning.

 Implementing Pagination

News websites usually have tons of articles, and it's not feasible to load all articles on one page. Here's where pagination comes into play. You can display a limited number of news cards per page and provide page numbers at the bottom for navigation. Bootstrap provides a pagination component:


<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>

Note: To make the pagination functional, you'll need to use a backend technology or JavaScript to manage which content to show based on the page number.

Adding a Back-to-Top Button

A "back-to-top" button is a small floating button that appears when users scroll down, allowing them to quickly jump back to the top of the page. You can create this button using HTML:


<button onclick="topFunction()" id="backToTopBtn" title="Go to top">Top</button>

And add some style using CSS:


#backToTopBtn {
display: none; /* Hidden by default */
position: fixed; /* Fixed/sticky position */
bottom: 20px; /* Place the button at the bottom of the page */
right: 30px; /* Place the button 30px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: #333; /* Set a background color */
color: white; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 15px; /* Some padding */
border-radius: 10px; /* Rounded corners */
font-size: 18px; /* Increase font size */
}

#backToTopBtn:hover {
background-color: #555; /* Add a dark-grey background on hover */
}

To make the "back-to-top" button work, you'll need to use a bit of JavaScript to show the button when the user scrolls down and to scroll to the top when the user clicks the button.

With the addition of pagination and a back-to-top button, you can provide a better user experience on your news website, especially when dealing with a large amount of content. These additional features introduce more complexity to the project, and implementing them is a great way to continue improving your front-end development skills.

let's continue by adding some animations to our news website. Adding animations can increase the visual appeal of your site and enhance the user experience. You can use CSS animations or a library like Animate.css for this purpose.

Animate.css

Animate.css is a library of ready-to-use, cross-browser animations for use in your web projects. You can include it in your project by adding the following link in your HTML file's head tag:


<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>

### Using Animate.css

Here's an example of how you can use Animate.css to animate the appearance of a news card:


<div class="card animate__animated animate__fadeInUp">
<!-- Your card content here -->
</div>

In this example, `animate__animated` applies the animation, and `animate__fadeInUp` is the specific animation you want to apply. There are numerous other animations you can choose from, listed in the Animate.css documentation.

Adding a Loading Animation

Let's say you want to display a loading animation while the news content is being fetched. You can create a simple CSS spinner like this:


<div class="spinner"></div>

And the CSS for the spinner:

css
.spinner {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

Scroll Animation

Another popular effect on modern websites is to animate elements as you scroll down the page. One such library that provides this functionality is AOS (Animate On Scroll) library. This would allow you to, for example, have news articles slide in from the side as the user scrolls down.

Remember that animations can greatly enhance the user experience when used in moderation but can also be distracting if overused. The key is to find a balance that works for your specific project.

Let's continue our exploration. This time, we will touch upon making the website responsive to different screen sizes, which is an essential part of frontend development.

Making the Website Responsive

Responsive design ensures that your website looks good on all devices, including desktops, laptops, tablets, and phones. Bootstrap is a mobile-first framework, which means it's designed to make creating responsive designs easier.

Bootstrap's grid system is based on twelve columns that can be flexibly divided amongst the different elements of your page. It uses a series of containers, rows, and columns to layout and align content.

For example, here's how you could design a news card that looks different on a phone versus on a larger screen:


<div class="row">
<div class="col-12 col-md-8">
<div class="card">
<!-- Content of the card goes here -->
</div>
</div>
<div class="col-12 col-md-4">
<!-- Sidebar content goes here -->
</div>
</div>

In this example, `col-12` means that on small screens (less than 768px width), the card and the sidebar will each take up 12 columns, i.e., the full width of the screen. On medium screens (768px and up, indicated by `md`), the card will take up 8 columns, and the sidebar will take up 4.

You can adjust the breakpoints (e.g., use `col-lg` instead of `col-md`) and the number of columns (anywhere from 1 to 12) to suit your design.

Creating a Responsive Navbar

Navbars are an important part of any website, and making them responsive enhances user experience. Bootstrap's navbar component is responsive by default. On smaller screens, it turns into a hamburger menu, which you can click to expand:


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">News Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<!-- More links here -->
</ul>
</div>
</nav>

Creating a responsive website is a fundamental part of frontend development. The examples above are basic, but you can explore more advanced responsive design techniques as you progress. Remember, creating a good user experience across all devices is key!

Let's go over some other useful elements you can add to your website to further enhance its functionality and design. In this session, we will touch on adding forms and modal windows to your news website.

Adding a Contact Form

You may want to add a contact form to your website to allow your readers to get in touch with you. Bootstrap provides a robust and customizable form component that you can use. Here is a simple example:


<form>
<div class="form-group">
<label for="contactName">Name</label>
<input type="text" class="form-control" id="contactName" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="contactEmail">Email</label>
<input type="email" class="form-control" id="contactEmail" placeholder="Enter your email">
</div>
<div class="form-group">
<label for="contactMessage">Message</label>
<textarea class="form-control" id="contactMessage" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

This will give you a simple contact form with fields for the user's name, email, and a message. Please note that to process the form submission, you will need a backend, which is beyond the scope of this guide.

Creating a Modal Window

A modal is a dialog box or popup window that is displayed on top of your current page. Modals are used to command user interaction before they can return to the main content. Modals can be used for various purposes, such as displaying additional information, getting user input, or guiding user workflows.

Here's an example of how to create a simple modal with Bootstrap:


<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
This is the modal body text. It can contain any HTML elements, including forms.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

This creates a button that, when clicked, launches a modal with a title, body, and footer.

Adding forms and modals are both great ways to enhance the user interaction on your site. Please remember that handling data from forms and implementing modal behaviors require JavaScript, which is outside the scope of this guide. As you progress in your learning, combining HTML, CSS, and JavaScript will enable you to create dynamic, interactive web applications. Keep up the great work!


Was this answer helpful?

« Back