Front-end Snippet Library

Karina Mercedes · tested patterns for event pages, registration forms and HTML email. Each snippet has comments that walk through the logic, and links to the official docs.

Page setupStarter page with Bootstrap 5 and jQuery · brand colours

Starter page

Every new page. CSS in the head, scripts at the end of the body.

<!doctype html>
<html lang="en">                       <!-- lang helps screen readers -->
<head>
  <meta charset="utf-8">
  <!-- makes the page scale properly on phones -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Event name</title>

  <!-- 1. Bootstrap's CSS first -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- 2. my own CSS after it, so mine wins on a tie -->
  <link href="brand.css" rel="stylesheet">
</head>
<body>

  <!-- page content goes here -->

  <!-- scripts at the end so the page shows first -->
  <!-- 3. jQuery BEFORE my code, because my code uses $ -->
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  <!-- 4. Bootstrap's JS: powers modals, accordions, menus -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  <!-- 5. my code last -->
  <script>
    $(function () {      // wait until the page has loaded
      // my code
    });
  </script>
</body>
</html>

Say: "Bootstrap CSS in the head with my overrides after it. Scripts at the bottom: jQuery, then Bootstrap's bundle, then my own code, because each one depends on the one before."

Brand colours over Bootstrap

Never edit bootstrap.min.css. Override its CSS variables in your own file.

/* Bootstrap 5.3 reads its colours from CSS variables,
   so I change the variable instead of fighting the CSS */
:root {
  --bs-primary: #0f2a44;              /* brand navy */
  --bs-primary-rgb: 15, 42, 68;       /* same colour as numbers, for transparency */
  --bs-body-font-family: Arial, sans-serif;
}

/* buttons have their own variables */
.btn-primary {
  --bs-btn-bg: #0f2a44;
  --bs-btn-border-color: #0f2a44;
  --bs-btn-hover-bg: #1b4166;         /* a bit lighter on hover */
  --bs-btn-hover-border-color: #1b4166;
}

Say: "I never touch Bootstrap's own file. I override its variables in a stylesheet loaded after it, so updates don't wipe my changes."

Bootstrap layoutGrid · cards · utility classes

Responsive grid: 1 column on phone, 2 on tablet, 3 on laptop

Container → row → col. "A box, a shelf, the items on the shelf." Each row has 12 slots.

<!-- the box: centred, with space at the sides -->
<div class="container">

  <!-- the shelf: lines the items up. g-4 = gap between them -->
  <div class="row g-4">

    <!-- the items. Read the classes left to right, small screen to big:
         col-12     phones: all 12 slots = full width
         col-md-6   from 768px: 6 of 12 = half
         col-lg-4   from 992px: 4 of 12 = a third -->
    <div class="col-12 col-md-6 col-lg-4">Session 1</div>
    <div class="col-12 col-md-6 col-lg-4">Session 2</div>

    <!-- on tablets the 3rd would sit alone in half a row,
         so col-md-12 makes it span the full width there -->
    <div class="col-12 col-md-12 col-lg-4">Session 3</div>

  </div>
</div>
  • Breakpoints: sm 576 · md 768 · lg 992 · xl 1200 · xxl 1400.
  • Numbers in a row add up to 12: 6+6, 4+4+4, 3+3+3+3.
  • .container-fluid = always full width.

Say: "Mobile-first: full width on phones, half from medium, a third from large. The last card spans the row on tablets so it doesn't sit alone."

Speaker or session card

<!-- h-100 = 100% height, so cards in the same row line up -->
<div class="card h-100">
  <img src="speaker.jpg" class="card-img-top" alt="Alex Morgan">  <!-- alt = name -->
  <div class="card-body">
    <h3 class="h5 card-title">Alex Morgan</h3>   <!-- h3 for structure, looks like h5 -->
    <p class="card-text text-muted text-break">Managing Director, Infrastructure</p>
  </div>
</div>

Say: "h-100 keeps every card in a row the same height, and text-break stops a long job title breaking the layout on mobile."

Utility classes I use most

m = margin, p = padding · t b s e = top bottom start end · x y = sides / top-bottom · 0–5 = size.

  • mt-3 mb-4 py-5 px-2 spacing
  • d-none hide · d-md-block show from md up · d-flex flexbox
  • text-center fw-semibold text-muted small
  • text-break wrap long words · text-truncate one line with …
  • w-100 full width · img-fluid image never wider than its box
Bootstrap formsRegistration fields · validation

Registration fields

<!-- novalidate = turn off the browser's pop-ups, use Bootstrap's messages -->
<form id="regForm" novalidate>

  <div class="mb-3">
    <!-- label for="email" pairs with input id="email":
         clicking the label focuses the box, screen readers read it -->
    <label for="email" class="form-label">Work email</label>
    <!-- type="email" checks the format · required = can't be empty -->
    <input type="email" class="form-control" id="email" required>
    <!-- only shows when the field is invalid -->
    <div class="invalid-feedback">Please enter a valid email address.</div>
  </div>

  <div class="mb-3">
    <label for="attendance" class="form-label">How will you attend?</label>
    <!-- dropdowns use form-select, not form-control -->
    <select class="form-select" id="attendance" required>
      <option value="" selected disabled>Choose…</option>  <!-- forces a choice -->
      <option value="in-person">In person</option>
      <option value="virtual">Virtual</option>
    </select>
  </div>

  <!-- hidden until "In person" is chosen (see jQuery section) -->
  <div class="mb-3 d-none" id="dietaryWrap">
    <label for="dietary" class="form-label">Dietary requirements</label>
    <input type="text" class="form-control" id="dietary">
  </div>

  <div class="form-check mb-3">
    <input class="form-check-input" type="checkbox" id="privacy" required>
    <label class="form-check-label" for="privacy">I agree to the privacy notice</label>
  </div>

  <button type="submit" class="btn btn-primary" id="submitBtn">Register</button>
</form>

Say: "Every input has a matching label for accessibility. I use the built-in checks first, required and type email, then JavaScript only for custom rules."

Validation with Bootstrap's red/green states

$('#regForm').on('submit', function (e) {
  e.preventDefault();                 // stop the page reloading

  // checkValidity() runs the HTML rules (required, type="email")
  // "this" is the form itself
  if (!this.checkValidity()) {
    $(this).addClass('was-validated');              // Bootstrap shows red/green + messages
    $(this).find(':invalid').first().trigger('focus'); // jump to the first problem
    return;                                         // stop: don't send
  }

  // valid: send it (the platform does this part)
});

Say: "If the form isn't valid I show the messages and move focus to the first error. Front-end validation is for the guest's experience. The server validates again, because the browser can be bypassed."

Bootstrap componentsAccordion · modal · navbar (no JavaScript to write)

FAQ accordion

<!-- data-bs-* attributes tell Bootstrap's JS what to do. No code of my own. -->
<div class="accordion" id="faq">
  <div class="accordion-item">
    <h3 class="accordion-header">
      <!-- the button opens the panel whose id is in data-bs-target -->
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
              data-bs-target="#faq1" aria-expanded="false" aria-controls="faq1">
        What is the dress code?
      </button>
    </h3>
    <!-- data-bs-parent = only one panel open at a time -->
    <div id="faq1" class="accordion-collapse collapse" data-bs-parent="#faq">
      <div class="accordion-body">Business attire.</div>
    </div>
  </div>
  <!-- next item: copy it and change faq1 to faq2 in all THREE places -->
</div>

Say: "Bootstrap's bundle handles this through data attributes. The one thing to watch is a unique id per item, used in three places."

Modal

<!-- the trigger -->
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#venueModal">Venue</button>

<!-- the modal. tabindex="-1" + aria-* make it work with keyboard and screen readers -->
<div class="modal fade" id="venueModal" tabindex="-1" aria-labelledby="venueTitle" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title fs-5" id="venueTitle">Venue</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">Address and directions</div>
    </div>
  </div>
</div>

Navbar with mobile menu

<!-- navbar-expand-lg = full menu from laptop size, hamburger below -->
<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container">
    <a class="navbar-brand" href="#">Event</a>
    <!-- the hamburger: opens the element with id="nav" -->
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav"
            aria-controls="nav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="nav">
      <ul class="navbar-nav ms-auto">   <!-- ms-auto pushes links to the right -->
        <li class="nav-item"><a class="nav-link" href="#agenda">Agenda</a></li>
        <li class="nav-item"><a class="nav-link" href="#register">Register</a></li>
      </ul>
    </div>
  </div>
</nav>
jQueryThe recipe · the "do" moves · conditional field · double submit

The recipe: FIND · LISTEN · DO

// wrapper: wait until the page has loaded, or the button may not exist yet
$(function () {

  // FIND    $('#showBtn')      $ = jQuery, inside is a CSS selector (# id, . class)
  // LISTEN  .on('click', …)    which event: click, change, submit, input
  // DO      function () {…}    what happens when it fires
  $('#showBtn').on('click', function () {
    $('#panel').toggleClass('d-none');   // d-none = Bootstrap's "hidden" class
  });

});

Say: "Almost everything in jQuery is the same shape: find the element, listen for an event, then do something."

The "do" moves

$('#email').val();                    // READ what someone typed or chose
$('#email').val('');                  // WRITE: here, clear the field
$('#title').text('Thank you');        // change the text
$('#card').addClass('active');        // add a class
$('#card').removeClass('active');     // remove a class
$('#panel').toggleClass('d-none');    // show/hide with Bootstrap's class
$('#panel').slideDown();              // show with an animation
$('#btn').prop('disabled', true);     // LIVE states: disabled, checked, required
$('#link').attr('href', '/agenda');   // HTML attribute text: href, src, data-*
$(this)                               // inside a handler: the element that fired

Show a field only for in-person guests

// LISTEN for 'change' on the dropdown
$('#attendance').on('change', function () {

  // read the value; true if they chose in person
  var inPerson = $(this).val() === 'in-person';

  // toggleClass with true/false: hide when NOT in person
  $('#dietaryWrap').toggleClass('d-none', !inPerson);

  // required only while it's visible, or virtual guests get blocked
  $('#dietary').prop('required', inPerson);

  // clear an old answer so we don't send stale data
  if (!inPerson) {
    $('#dietary').val('');
  }
});

Say: "Two details matter here: the field is only required while it's visible, and it's cleared when hidden, so we never block a guest or send stale data."

Stop double submission

$('#regForm').on('submit', function (e) {

  // 1. not valid? show errors and stop. DON'T lock the button,
  //    or the guest is stuck with a dead button
  if (!this.checkValidity()) {
    e.preventDefault();
    $(this).addClass('was-validated');
    return;
  }

  // 2. valid: lock the button straight away so a second click does nothing,
  //    and tell the guest something is happening
  $('#submitBtn').prop('disabled', true).text('Registering…');
});

Say: "I only lock the button once the form is valid. I'd also check the platform de-duplicates on the server, because front-end code alone can be bypassed."

Clicks on items added after the page loaded

// a normal .on('click') only reaches elements that existed at load time.
// Event delegation: listen on a parent that always exists,
// and filter by the selector in the middle
$('#agendaList').on('click', '.remove-session', function () {
  $(this).closest('li').remove();   // closest = nearest parent li
});

The same thing without jQuery

// DOMContentLoaded = jQuery's $(function () {…})
document.addEventListener('DOMContentLoaded', function () {
  // querySelector = $(…) · addEventListener = .on(…) · classList.toggle = .toggleClass(…)
  document.querySelector('#showBtn').addEventListener('click', function () {
    document.querySelector('#panel').classList.toggle('d-none');
  });
});
HTML emailSkeleton · button · Outlook background · images · columns · UTM

Email skeleton

Table → row → cell. Styles inline. 600 wide. Padding on cells.

<!-- WHY TABLES: classic Outlook renders email with Microsoft Word,
     which ignores flexbox, grid and most margins. Tables always work. -->
<body style="margin:0; padding:0; background-color:#eef1f4;">

  <!-- preheader: the grey preview text after the subject line, hidden in the email -->
  <div style="display:none; max-height:0; overflow:hidden; mso-hide:all;">18–19 March · Reserve your place</div>

  <!-- outer table: full width, paints the background.
       role="presentation" = layout, not data, for screen readers
       cellpadding/cellspacing/border 0 = remove default gaps -->
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#eef1f4">
    <tr>
      <td align="center" style="padding:24px 0;">

        <!-- inner table: the 600px email, centred by align="center" above -->
        <table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0"
               style="width:600px; max-width:600px; background-color:#ffffff;">
          <tr>
            <!-- padding on the td, styles INLINE (some apps delete style blocks) -->
            <td style="padding:32px 40px; font-family:Arial, sans-serif; font-size:16px; line-height:24px; color:#1d2733;">
              Dear [First name], …
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>

Say: "Tables because of Outlook, a 600px container, inline styles, padding on cells, and role presentation so screen readers skip the layout."

Bulletproof button

<!-- the COLOUR and PADDING sit on the td, which Outlook respects.
     The link is live text, so it works even with images blocked. -->
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td bgcolor="#0f2a44" style="background-color:#0f2a44; border-radius:4px; padding:14px 28px;">
      <a href="https://example.com/register" style="color:#ffffff; font-family:Arial, sans-serif;
         font-size:16px; font-weight:bold; text-decoration:none; display:inline-block;">Register now</a>
    </td>
  </tr>
</table>

Say: "Never an image button. A table cell with a background colour and a text link works in every client, even with images off. And never layered over an image."

Background image in Outlook (VML)

<!-- Outlook ignores CSS background-image. VML is Microsoft's own format,
     read only inside the [if gte mso 9] comments. Everyone else reads the td.
     The image URL appears 3 times: background attr, CSS, VML src.
     bgcolor = fallback colour when images are blocked, keeps white text readable. -->
<td background="https://example.com/hero.jpg" bgcolor="#0f2a44" width="600" height="300" valign="middle"
    style="background-image:url('https://example.com/hero.jpg'); background-color:#0f2a44; background-size:cover;">
  <!--[if gte mso 9]>
  <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:600px;height:300px;">
    <v:fill type="frame" src="https://example.com/hero.jpg" color="#0f2a44" />
    <v:textbox inset="0,0,0,0">
  <![endif]-->
  <div>
    <h1 style="margin:0; color:#ffffff; font-family:Arial, sans-serif;">Event title</h1>
  </div>
  <!--[if gte mso 9]>
    </v:textbox>
  </v:rect>
  <![endif]-->
</td>

Email image

<!-- absolute https URL (never relative or behind a login)
     width attribute = Outlook's size
     alt = shown when images are blocked
     display:block = removes the small gap under images -->
<img src="https://example.com/images/venue.jpg" width="260" alt="The conference hall"
     style="display:block; width:100%; max-width:260px; height:auto; border:0;">

Two columns that stack on mobile

<!-- apps that support style blocks (iPhone, Gmail app) stack the cells on phones.
     Apps that don't just keep two columns, which still fits. -->
<style>
  @media screen and (max-width: 620px) {
    .stack { display: block !important; width: 100% !important; }
  }
</style>

<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td class="stack" width="50%" valign="top" style="padding:0 12px 16px 0;">Left</td>
    <td class="stack" width="50%" valign="top" style="padding:0 0 16px 12px;">Right</td>
  </tr>
</table>

Tracked link (UTM)

https://example.com/register?utm_source=email&utm_medium=invite&utm_campaign=eventname2026&utm_content=footer-button

utm_source   where it came from      (email)
utm_medium   what kind               (invite, reminder)
utm_campaign which campaign          (eventname2026)
utm_content  which link in the email (footer-button)

Say: "UTM tags show in Google Analytics which email and which link brought each registration. Clicks and registrations are more reliable than opens since Apple's Mail Privacy Protection."

Problems solvedWhat I check, in order

Images not showing in an email

  • Blocked by default in Outlook: alt text, background colours and live-text buttons must carry the message.
  • URL must be absolute, public, https: not relative, local, staging, or on a server a firewall blocks.
  • Background image in Outlook needs VML.
  • JPG, PNG or GIF, not WebP. Keep files small.
  • Test from an outside account too: a corporate firewall can block images internally.

Email fine in Gmail, broken in Outlook

  • Divs, flexbox or grid for layout → rebuild with tables.
  • Margins ignored → move spacing to td padding.
  • max-width on a div ignored → fixed-width table, or a ghost table inside <!--[if mso]>.
  • Something layered over an image → separate rows.
  • Background image missing → VML.

Sideways scrolling on mobile

  • Long word or URL → text-break.
  • Image without img-fluid.
  • A fixed width wider than the screen, or a row outside a container.
  • Find it: DevTools → device toolbar → look for what sticks out.

CSS not applying

  • DevTools → inspect → a crossed-out rule means something else won.
  • Specificity (id beats class beats element) or order (mine must load after Bootstrap).
  • Bootstrap utilities use !important.
  • Typo in the class, or an old cached file (hard refresh).

jQuery code does nothing

  • Console says "$ is not defined" → jQuery missing or loaded after my script.
  • Runs before the element exists → wrap in $(function () { … }).
  • Selector wrong → # for id, . for class, exact spelling.
  • Element added later → event delegation.
ChecklistsBefore sending · guest journey · accessibility · bug report

Before sending an email

  • Outlook desktop, Outlook web, Gmail web and app, iPhone Mail.
  • Images off · dark mode · phone width.
  • Every link clicked, UTM tags right, unsubscribe or preferences link present.
  • Merge fields fill in; empty field falls back (e.g. "Dear Colleague").
  • Subject, preview text, sender, spelling, dates, times, time zone.
  • Final sign-off from the event owner.

Testing the whole guest journey

  • Test guests on my own test addresses (name+test1@…), never real contacts.
  • One per type: in person with a dietary need, virtual, never opens, empty first name.
  • Invitation → link → registration form → answers saved → confirmation email shows them back.
  • Each guest lands on the right list; registered guests stop getting reminders.
  • Logistics email only goes to in-person guests.
  • Write down: test · expected · actual.

Accessibility

  • Every input has a label. Errors in words, not only red.
  • Text contrast at least 4.5:1.
  • Whole registration works with the keyboard, focus outline visible.
  • Meaningful alt text; alt="" on decorative images.
  • Headings in order; link text that makes sense alone.

Bug report

Title:     [What breaks, where]
Severity:  [Blocks registration / cosmetic / …]
Where:     [Event, page, step, browser + device]
Steps:     1. …  2. …  3. …
Expected:  …
Actual:    …
Evidence:  [Screenshot, console error]
© 2026 KARINA MERCEDES - All Rights Reserved