Chapters: JavaScript HTML & CSS JSON XML YAML ← Full TOC

🌐 Chapter 31 — HTML5 & CSS3

Complete reference for HTML5 semantic elements, CSS3 layout (Flexbox, Grid), animations, forms, and responsive design with copy-paste examples.
Part of The Direct Path to Linux Ubuntu — free for all.

4Topics
121+Properties
5Examples
browserOpen in
HTML5/CSS3Version
FreeNo login
🏗️ HTML5 Elements 🎨 CSS3 & Layout 📐 Flexbox ⬛ CSS Grid ⚡ Examples

🏗️ HTML5 Elements

🏗️ HTML5 ElementsDocument structure, semantic, form, and media elements

🎨 CSS3 & Layout

🎨 CSS3 & LayoutSelectors, box model, Flexbox, Grid, custom properties

📐 Flexbox

📐 CSS Flexbox ReferenceComplete Flexbox — container and item properties

⬛ CSS Grid

⬛ CSS Grid ReferenceComplete CSS Grid — tracks, areas, placement

⚡ Quick Examples

Save as .html file and open in any modern browser.

Complete HTML5 Page Template

Production-ready HTML5 boilerplate with SEO and accessibility.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Page description for search engines (150-160 chars)">
  <meta name="keywords"    content="keyword1, keyword2, keyword3">
  <meta name="author"      content="MyWebUniversity.com">
  <meta name="robots"      content="index, follow">
  <!-- Open Graph -->
  <meta property="og:title"       content="Page Title | Site Name">
  <meta property="og:description" content="Description for social sharing">
  <meta property="og:type"        content="website">
  <meta property="og:url"         content="https://example.com/page">
  <meta property="og:image"       content="https://example.com/og-image.jpg">
  <!-- Twitter Card -->
  <meta name="twitter:card"        content="summary_large_image">
  <meta name="twitter:title"       content="Page Title">
  <meta name="twitter:description" content="Description">
  <link rel="canonical" href="https://example.com/page">
  <title>Page Title | Site Name</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <a href="#main" class="skip-link">Skip to main content</a>

  <header role="banner">
    <nav aria-label="Primary navigation">
      <ul>
        <li><a href="/" aria-current="page">Home</a></li>
        <li><a href="/courses">Courses</a></li>
        <li><a href="/about">About</a></li>
      </ul>
    </nav>
  </header>

  <main id="main" tabindex="-1">
    <article>
      <header>
        <h1>Main Page Heading</h1>
        <time datetime="2026-06-25">June 25, 2026</time>
      </header>
      <p>Content goes here&hellip;</p>
    </article>
  </main>

  <aside aria-label="Related content">
    <h2>Related Topics</h2>
  </aside>

  <footer role="contentinfo">
    <p>&copy; 2026 MyWebUniversity.com</p>
  </footer>

  <script src="app.js" defer></script>
</body>
</html>

Dark Theme with CSS Variables

CSS custom properties for theming and dark mode.

/* style.css — Dark theme with CSS variables and responsive grid */
:root {
  /* Light theme defaults */
  --bg:      #ffffff;
  --surface: #f8fafc;
  --border:  #e2e8f0;
  --text:    #0f172a;
  --muted:   #64748b;
  --accent:  #2563eb;
  --radius:  8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0f172a;
    --surface: #1e293b;
    --border:  #334155;
    --text:    #e2e8f0;
    --muted:   #94a3b8;
    --accent:  #60a5fa;
  }
}
/* Manual dark mode override */
[data-theme="dark"] {
  --bg:      #0f172a;
  --surface: #1e293b;
  --border:  #334155;
  --text:    #e2e8f0;
  --accent:  #60a5fa;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body   { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; line-height: 1.6; }
.card  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.btn   { padding: 10px 24px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-size: 1rem; }

/* Toggle button in JavaScript */
/* document.querySelector('[data-theme-toggle]')
     .addEventListener('click', () =>
       document.documentElement.dataset.theme =
         document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark');  */

Responsive Grid Layout

CSS Grid layout that adapts to any screen size.

/* Responsive Grid — no media queries needed for the grid itself */
.page {
  display: grid;
  grid-template-areas:
    "header"
    "main"
    "footer";
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}
@media (min-width: 768px) {
  .page {
    grid-template-areas:
      "header  header"
      "sidebar main"
      "footer  footer";
    grid-template-columns: 240px 1fr;
  }
}

/* Auto-responsive card grid (no media queries!) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
}

/* Dashboard widgets */
.dashboard {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
.widget        { grid-column: span 12; }
.widget-half   { grid-column: span 6; }
.widget-third  { grid-column: span 4; }
.widget-quarter{ grid-column: span 3; }
@media (max-width: 900px) {
  .widget-half, .widget-third, .widget-quarter { grid-column: span 12; }
}

CSS Animations & Transitions

Smooth transitions and keyframe animations.

/* CSS Animations & Transitions */

/* Transition — smooth state changes */
.btn {
  background: #2563eb;
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.btn:hover  { background: #1d4ed8; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37,99,235,.4); }
.btn:active { transform: translateY(0);  box-shadow: none; }

/* Fade in on load */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeInUp 0.4s ease forwards; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.2s; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid #334155;
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Pulse */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
.skeleton { background: #1e293b; border-radius: 4px; animation: pulse 1.5s ease infinite; }

/* Scroll-triggered (with JS IntersectionObserver) */
.reveal { opacity: 0; transform: translateY(30px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.visible { opacity: 1; transform: translateY(0); }
/*
const observer = new IntersectionObserver(entries =>
  entries.forEach(e => e.isIntersecting && e.target.classList.add('visible')));
document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
*/

Accessible Form Design

Semantic, accessible HTML form with validation and ARIA.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Enrollment Form | MyWebUniversity</title>
  <style>
    :root { --accent:#22d3ee; --bg:#0f172a; --surface:#1e293b; --border:#334155; --text:#e5e7eb; }
    *, *::before, *::after { box-sizing: border-box; }
    body   { font-family: system-ui; background: var(--bg); color: var(--text); padding: 40px 20px; }
    .form  { max-width: 480px; margin: 0 auto; background: var(--surface);
             border: 1px solid var(--border); border-radius: 10px; padding: 28px; }
    label  { display: block; font-size: .9em; font-weight: 600; margin-bottom: 5px; color: var(--accent); }
    input, select { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
                    border-radius: 6px; color: var(--text); font-size: 1rem; margin-bottom: 16px; }
    input:focus, select:focus { outline: none; border-color: var(--accent); }
    input:invalid:not(:placeholder-shown) { border-color: #f43f5e; }
    .error { color: #f43f5e; font-size: .85em; margin-top: -12px; margin-bottom: 12px; display: none; }
    input:invalid:not(:placeholder-shown) + .error { display: block; }
    .btn   { width: 100%; padding: 12px; background: var(--accent); color: #0f172a;
             border: none; border-radius: 6px; font-size: 1rem; font-weight: 700; cursor: pointer; }
    .btn:hover { opacity: .9; }
    .required::after { content: " *"; color: #f43f5e; }
  </style>
</head>
<body>
  <form class="form" novalidate id="enrollForm" aria-labelledby="formTitle">
    <h2 id="formTitle">Enroll in a Course</h2>
    <p role="note" style="color:#9ca3af;font-size:.9em;margin-bottom:20px">
      Fields marked <span style="color:#f43f5e">*</span> are required.
    </p>

    <label for="name" class="required">Full Name</label>
    <input type="text" id="name" name="name" required minlength="2"
           placeholder="Alice Smith" autocomplete="name" aria-required="true">
    <div class="error" id="name-error" role="alert">Please enter your full name (2+ characters).</div>

    <label for="email" class="required">Email Address</label>
    <input type="email" id="email" name="email" required
           placeholder="alice@example.com" autocomplete="email" aria-required="true">
    <div class="error" id="email-error" role="alert">Please enter a valid email address.</div>

    <label for="course" class="required">Select Course</label>
    <select id="course" name="course" required aria-required="true">
      <option value="" disabled selected>-- Choose a course --</option>
      <option value="js">Chapter 30 — JavaScript</option>
      <option value="html">Chapter 31 — HTML &amp; CSS</option>
      <option value="py">Chapter 1 — Python</option>
    </select>

    <button type="submit" class="btn" aria-label="Submit enrollment form">
      Enroll Now
    </button>
  </form>
  <script>
    document.getElementById('enrollForm').addEventListener('submit', e => {
      e.preventDefault();
      if (e.target.checkValidity()) alert('Enrolled! Thank you.');
      else e.target.reportValidity();
    });
  </script>
</body>
</html>