Skip to content
Tutorials Center
My learning

Topics

Lesson 55 of 58 ยท Projects

Project: Portfolio Site

Build a personal portfolio with Bootstrap 5: a gallery grid that opens a shared modal, skill progress bars, a contact form with printed output and a dark mode switch.

A portfolio is a small site with a big job: show your work, say what you can do, and make it easy to get in touch. It is also the best capstone for this course, because it combines layout, components, forms and a little JavaScript, and you can personalize it and publish it afterwards.

You will build a page for a fictional designer, Lena Ortiz, in three steps: the top of the page with a dark mode switch and skill bars, a gallery whose items open in one shared modal, and a contact form that prints what the visitor typed. Every example is self-contained, so you can run it, change the text and make it your own. Before starting, glance at Color Modes and Dark Mode, Modals and Plugin Events and Programmatic Control.

Plan

flowchart TD
  NB["Navbar<br/>links and theme switch"] --> HE["Intro and skills"]
  HE --> GA["Gallery grid"]
  GA --> MO["One shared modal<br/>filled on show.bs.modal"]
  GA --> CO["Contact form<br/>printed result"]

The page is a short vertical story: who, what skills, what work, how to reach.

Think about content before code. A good portfolio shows fewer, better projects with a sentence of context for each; put the best one first. Use real project images in your final version, saved with width and height attributes and descriptive alt text. In the examples below, colored tiles stand in for images so the demos run anywhere.

Step 1: dark mode switch and skills

Bootstrap 5.3 colors depend on the data-bs-theme attribute. Set it to dark on the <html> element and the whole page switches, including components. A switch (form-check form-switch) toggles it with a few lines of script.

In a normal page you would save the choice in localStorage so it survives a reload, and use prefers-color-scheme for the first visit. The preview here has no storage (it runs in an opaque-origin sandbox), so the code keeps the choice in a variable and reads the system preference at the start. The lines you would add on your own site are shown in the comment.

Skill bars are progress bars with a label. Remember role="progressbar" and the ARIA values, which tell assistive technology what the bar means.

Theme switch, intro and skills

Flip the switch: cards, borders, form controls and the navbar background all follow, because they read CSS variables that change with the theme. Elements you color with fixed classes such as bg-white or text-dark do not change, so prefer bg-body, bg-body-tertiary and text-body-secondary in a themed page.

A gallery of six pieces would need six modals if you copied markup, which is heavy and easy to get wrong. A better pattern is one modal whose content is filled in from the clicked item. Each gallery button carries its data in data-title and data-text attributes. When the modal is about to show, Bootstrap fires show.bs.modal, and the event has a relatedTarget: the button that opened it. The handler reads the data from it and writes it into the modal with textContent.

The gallery grid itself is row row-cols-2 row-cols-md-3 g-3. Each tile is a <button> styled as a block, not a div with a click handler, so it is reachable and activatable with the keyboard.

Gallery with a shared modal

When you use real images, put the <img class="img-fluid rounded-3"> inside the button, use the thumbnail in the grid and set a larger source in the modal from another data attribute.

Step 3: contact form with printed output

The contact form is the call to action, so keep it short: name, email and message. It uses the same validation pattern as before. On a real site the form would post to a server or a form service; here the handler prints the values in an alert, using textContent so nothing typed can be treated as HTML.

Contact form

Finishing and publishing

Join the three pieces into one page: navbar and about section first, gallery and modal in the middle, contact last, with a single stylesheet link and a single script at the end. Then:

  • Add a <footer> with social links and a copyright line.
  • Add <meta name="description"> and a good <title>, so search engines show something meaningful.
  • Optimize images (modern formats, sizes close to what is displayed) and add loading="lazy" to those below the fold.
  • Run through the accessibility checklist and the performance tips.
  • Host it on any static host. A portfolio needs no server, only a form service or small endpoint for the contact form.

You have now built five complete pages with the same few ideas: containers and the grid for structure, utilities for spacing and color, components for interaction, and a sprinkle of JavaScript through data attributes and events.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which attribute on the html element switches the whole page to Bootstrap's dark color mode?

    Bootstrap 5.3 reads data-bs-theme on the element (usually html) and on any component to set light or dark colors.
  2. 2. In the show.bs.modal handler, how do you find the button that opened the modal?

    Bootstrap passes the triggering element as relatedTarget on show.bs.modal, so you can read its data attributes.
  3. 3. Why are gallery tiles real button elements instead of divs with click handlers?

    Native buttons are focusable and respond to Enter and Space, so keyboard and screen reader users can use them.
  4. 4. Why does the example write text with textContent in the printed contact result?

    textContent inserts the value as plain text, so markup typed by a visitor appears literally instead of running.

Summary

  • data-bs-theme="dark" on html turns on dark mode; use theme-aware classes such as bg-body-tertiary and text-body-secondary so components adapt.
  • Persist the theme with localStorage and prefers-color-scheme on your own site; the preview keeps it in memory because of the sandbox.
  • One shared modal filled from event.relatedTarget on show.bs.modal replaces many copies of the same markup.
  • Skill bars need ARIA attributes; gallery items should be real buttons or links.
  • Print or send form data safely: validate in the browser, insert with textContent, and validate again on the server.

Next lesson: Exercises with Solutions.