Skip to content
Tutorials Center
My learning

Topics

Lesson 53 of 58 ยท Projects

Project: Blog Layout

Build a two-column Bootstrap 5 blog: breadcrumbs, article list with cards, sidebar widgets, pagination and a comment form that shows new comments on the page.

A blog is mostly text, and text needs structure: a comfortable reading width, clear separation between posts, and navigation that tells readers where they are. Bootstrap's grid, cards, list groups, breadcrumbs and pagination cover all of it. In this project you build two pages of a small blog called Field Notes: the home page with a list of articles and a sidebar, and a single article page with a comment form.

As you work, keep the reading experience in mind. Long lines of text are hard to read, so the article body should not stretch across a wide monitor. The main column takes about two thirds of the width on large screens, and the sidebar the rest. If you need a refresher, see Responsive Columns, Cards and List Groups, Breadcrumbs and Pagination.

Structure of the two pages

Both pages share the same outer frame: a header with the blog name, a breadcrumb trail, then a row with a col-lg-8 main column and a col-lg-4 sidebar. Below lg the sidebar drops under the main column, which is the right order for readers on phones: content first, extras afterwards.

flowchart TD
  H["Header and breadcrumb"] --> R["row g-4"]
  R --> M["col-lg-8 main<br/>article list or single article"]
  R --> S["col-lg-4 sidebar<br/>search, categories, recent posts"]
  M --> P["Pagination or comments"]

A blog page is one row with a wide main column and a narrow sidebar.

Step 1: the article list

Each post in the list is a horizontal card: a colored placeholder block (in a real blog, an img with object-fit-cover) next to the title, a short excerpt, meta information and a "Read more" link. The sidebar holds three widgets: a search form, a list of categories with counts, and recent posts.

Breadcrumbs go above the content and mark the last item with aria-current="page". Pagination goes below the list. Wrap it in a nav with an aria-label, and mark the current page with active and the unavailable "Previous" with disabled. The disabled item must also stop being focusable: the usual way is tabindex="-1" on the link, as done below.

Blog home page

Look at the stretched-link on each title: it extends the link's clickable area over the whole card, so readers can click anywhere on a post while keyboard and screen-reader users still meet a single, clearly named link. The decorative emoji tile has aria-hidden="true" because it carries no information.

Step 2: the article page and comment form

A single post needs a comfortable measure. The article sits in the same col-lg-8; inside it use lead for the opening paragraph, ordinary p tags, a blockquote for a pull quote, and h2 subheadings. Add text-body-secondary meta below the title.

The comment form is a standard Bootstrap form with the needs-validation pattern. Because there is no server in this lesson (and the preview sandbox must not post anywhere), a small script handles the submit event: it calls preventDefault(), checks validity, and, if the form is valid, inserts the new comment into the list on the page. Text is added with textContent so a comment containing <b> appears as plain text instead of being treated as HTML. Never build comment markup with innerHTML from user input: that is a classic script-injection hole.

Article page with comments

Try posting an empty form first to see the red feedback, then add a comment. It appears in the list immediately; nothing is stored or sent, so a reload brings back the original page. A real blog would POST the data to a server, validate it again there (browser checks can be bypassed), and store it.

Making the blog feel finished

A few small decisions lift the design:

  • Reading width. If the article page has no sidebar, wrap the text in col-lg-8 mx-auto so lines stay around 65 to 80 characters.
  • Images. Use img-fluid with rounded-3, and set width and height attributes to avoid layout jumps while they load (see Images and Figures).
  • Dates and meta. Use the <time datetime="2026-05-04"> element, so machines read the date as well as people.
  • Navigation. Keep the breadcrumb on every page below the home page; it shows context and gives a quick way back.
  • Sticky sidebar. Add position-sticky with style="top: 1rem" on an inner wrapper if you want widgets to stay in view on desktop.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the stretched-link class do on a link inside a card?

    stretched-link adds a pseudo-element that covers the nearest positioned ancestor (the card), so one real link serves the whole card.
  2. 2. Why does the comment script use textContent instead of innerHTML?

    Setting innerHTML from user input can run injected markup. textContent treats everything as text.
  3. 3. How should the last item of a breadcrumb be marked?

    The active class styles it and aria-current tells assistive technology it is the current location.
  4. 4. On a phone, where does a col-lg-4 sidebar appear next to a col-lg-8 main column?

    Below lg the columns stack in source order, so the sidebar follows the main content.

Summary

  • A blog page is a row with a col-lg-8 main column and a col-lg-4 sidebar that stacks underneath on small screens.
  • Horizontal cards with stretched-link make a clean article list; list groups and cards build sidebar widgets.
  • Breadcrumbs end with active and aria-current="page"; pagination needs a labeled nav and a non-focusable disabled link.
  • Forms use novalidate, was-validated and invalid-feedback; a submit handler can add comments to the page without posting.
  • Insert user text with textContent, never innerHTML.

Next lesson: Project: Login and Signup Forms.