HTML5 avancé

Maîtrisez HTML5 moderne : Web Components, APIs avancées, PWA.

Maîtrisez HTML5 moderne

Maîtrisez HTML5 moderne ! Web Components, APIs avancées, PWA, et sémantique de pointe. Créez des applications web natives dignes d'une interface S.H.I.E.L.D.

🧩 Web Components

🚀 Progressive Web Apps

🎯 APIs Natives

🧠 HTML5 de Niveau Expert

Découvrez la différence entre HTML basique et HTML moderne de niveau professionnel. Nous allons créer une interface S.H.I.E.L.D. avec les techniques les plus avancées.

🔧 HTML Traditionnel

html

<div class="card">
  <div class="header">
    <h2>Titre</h2>
  </div>
  <div class="content">
    <p>Contenu simple</p>
    <div onclick="alert('Click')">
      Bouton
    </div>
  </div>
</div>

⚡ Fonctionnel mais non sémantique

🚀 HTML5 Moderne

html

<article itemscope itemtype="https://schema.org/NewsArticle">
  <header role="banner">
    <h1 itemprop="headline">Titre Sémantique</h1>
    <time datetime="2025-01-15" itemprop="datePublished">
      15 Janvier 2025
    </time>
  </header>

  <section itemprop="articleBody">
    <p>Contenu riche et accessible</p>
    <smart-button type="primary"
                 aria-label="Action principale">
      Action Intelligente
    </smart-button>
  </section>
</article>

🤯 Sémantique, accessible et intelligent !

🧩

Web Components

html

                        customElements.define()
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Custom Elements&lt;/p&gt;

html

                        this.attachShadow()
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Shadow DOM&lt;/p&gt;

html

                        <template>
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Templates HTML&lt;/p&gt;

📋

Sémantique Avancée

html

                        itemscope itemtype
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Schema.org&lt;/p&gt;

html

                        role="application"
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;ARIA avancé&lt;/p&gt;

html

                        <main> <aside>
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;HTML5 structural&lt;/p&gt;

⚡

APIs Natives

html

                        navigator.serviceWorker
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Service Workers&lt;/p&gt;

html

                        window.localStorage
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Storage API&lt;/p&gt;

html

                        canvas.getContext('2d')
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Canvas 2D/WebGL&lt;/p&gt;

🚀

Progressive Web Apps

html

                        manifest.json
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Web App Manifest&lt;/p&gt;

html

                        sw.register()
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Installation PWA&lt;/p&gt;

html

                        cache.addAll()
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Cache Strategy&lt;/p&gt;

⚡

Performance Web

html

                        loading="lazy"
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Lazy Loading&lt;/p&gt;

html

                        rel="preload"
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Resource Hints&lt;/p&gt;

html

                        intersection-observer
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;APIs Performance&lt;/p&gt;

♿

Accessibilité Avancée

html

                        aria-live="polite"
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Live Regions&lt;/p&gt;

html

                        aria-describedby
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Relations ARIA&lt;/p&gt;

html

                        tabindex="-1"
                        &lt;p class="text-gray-300 text-xs mt-1"&gt;Focus Management&lt;/p&gt;

💪 Exercices HTML5 Avancés

Mettez en pratique les techniques HTML5 modernes avec ces 3 exercices progressifs. Créez des composants réutilisables et des interfaces intelligentes.

1

Exercice 1 : Web Component Avenger

Custom Elements + Shadow DOM + Template + Slot

🎯 Objectif

Iron Man

html

                    <!-- Simulation du Web Component -->

                                🦾

                                &lt;h4 class="text-white font-bold text-lg"&gt;&lt;/h4&gt;
                                &lt;p class="text-gray-300"&gt;Tony Stark - Genius Inventor&lt;/p&gt;

                                    Technology
                                    Flight

Créez un Web Component réutilisable pour afficher des cartes d'Avengers avec Shadow DOM pour l'encapsulation et des slots pour la flexibilité.

💻 Code à implémenter

HTML Template :

html

<template id="avenger-card-template">
  <style>
    /* TODO: Styles pour Shadow DOM */
    :host {
      /* TODO: Styles du composant hôte */
    }
    .card {
      /* TODO: Style de la carte */
    }
  </style>

  <div class="card">
    <!-- TODO: Structure avec slots -->
    <slot name="avatar"></slot>
    <slot name="content"></slot>
  </div>
</template>

JavaScript (à compléter) :

html

class AvengerCard extends HTMLElement {
  constructor() {
    super();
    // TODO: Attacher Shadow DOM
    // TODO: Cloner template
  }

  connectedCallback() {
    // TODO: Logique de connexion
  }

  static get observedAttributes() {
    // TODO: Attributs observés
    return ['name', 'power'];
  }

  attributeChangedCallback(name, oldValue, newValue) {
    // TODO: Réagir aux changements d'attributs
  }
}

// TODO: Définir le custom element

html

<template id="avenger-card-template">
  <style>
    :host {
      display: block;
      margin: 1rem 0;
    }

    .card {
      display: flex;
      align-items: center;
      padding: 1rem;
      border: 2px solid #E34F26;
      border-radius: 8px;
      background: rgba(227, 79, 38, 0.1);
      gap: 1rem;
      transition: transform 0.3s ease;
    }

    .card:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 20px rgba(227, 79, 38, 0.3);
    }

    ::slotted([slot="avatar"]) {
      width: 64px;
      height: 64px;
      border-radius: 50%;
      flex-shrink: 0;
    }
  </style>

  <div class="card">
    <slot name="avatar">
      <div class="default-avatar">🦸</div>
    </slot>
    <div class="content">
      <slot name="content">
        <h3>Avenger</h3>
        <p>Description par défaut</p>
      </slot>
    </div>
  </div>
</template>

<script>
class AvengerCard extends HTMLElement {
  constructor() {
    super();
    const shadow = this.attachShadow({mode: 'open'});
    const template = document.getElementById('avenger-card-template');
    shadow.appendChild(template.content.cloneNode(true));
  }

  connectedCallback() {
    console.log('Avenger card connectée au DOM');
  }

  static get observedAttributes() {
    return ['name', 'power', 'description'];
  }

  attributeChangedCallback(name, oldValue, newValue) {
    if (name === 'name') {
      this.updateContent();
    }
  }

  updateContent() {
    // Mise à jour du contenu basée sur les attributs
    const name = this.getAttribute('name') || 'Avenger';
    const power = this.getAttribute('power') || 'Unknown';

    this.shadowRoot.querySelector('slot[name="content"] h3').textContent = name;
    this.shadowRoot.querySelector('slot[name="content"] p').textContent = power;
  }
}

customElements.define('avenger-card', AvengerCard);
</script>

2

Exercice 2 : PWA S.H.I.E.L.D.

Service Worker + Web App Manifest + Cache Strategy

🎯 Objectif

S.H.I.E.L.D. Command

html

                            🛡️

                        &lt;h4 class="text-white font-bold mb-2"&gt;&lt;/h4&gt;
                        &lt;p class="text-gray-300 text-sm mb-4"&gt;Application installable hors-ligne&lt;/p&gt;
PWA Active

Créez une Progressive Web App complète avec installation, fonctionnement hors-ligne et synchronisation en arrière-plan pour les opérations S.H.I.E.L.D.

💻 Code à implémenter

manifest.json (à compléter) :

html

{
  "name": "S.H.I.E.L.D. Command Center",
  "short_name": "SHIELD",
  // TODO: Ajouter icônes, couleurs
  // TODO: Configuration display et orientation
  // TODO: URLs de démarrage
  "start_url": "/",
  "display": "standalone",
  "background_color": "#1e3c72",
  "theme_color": "#E34F26"
}

Service Worker (à compléter) :

html

const CACHE_NAME = 'shield-v1';
const STATIC_ASSETS = [
  '/',
  '/index.html',
  // TODO: Ajouter assets à cacher
];

self.addEventListener('install', event => {
  // TODO: Mettre en cache les assets
});

self.addEventListener('fetch', event => {
  // TODO: Stratégie Cache First/Network First
});

html

{
  "name": "S.H.I.E.L.D. Command Center",
  "short_name": "SHIELD",
  "description": "Interface de commandement S.H.I.E.L.D. avec capacités hors-ligne avancées",
  "start_url": "/",
  "display": "standalone",
  "background_color": "#1e3c72",
  "theme_color": "#E34F26",
  "orientation": "portrait",
  "scope": "/",
  "lang": "fr",
  "dir": "ltr",
  "categories": ["security", "productivity", "utilities"],
  "icons": [
    {
      "src": "icons/icon-72.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "icons/icon-96.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "icons/icon-128.png",
      "sizes": "128x128",
      "type": "image/png"
    },
    {
      "src": "icons/icon-144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "icons/icon-152.png",
      "sizes": "152x152",
      "type": "image/png"
    },
    {
      "src": "icons/icon-192.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "maskable"
    },
    {
      "src": "icons/icon-384.png",
      "sizes": "384x384",
      "type": "image/png"
    },
    {
      "src": "icons/icon-512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ],
  "shortcuts": [
    {
      "name": "Missions actives",
      "url": "/missions?status=active",
      "description": "Voir les missions en cours"
    },
    {
      "name": "Alertes urgentes",
      "url": "/alerts?priority=high",
      "description": "Alertes de sécurité prioritaires"
    },
    {
      "name": "Statut agents",
      "url": "/agents",
      "description": "État des agents sur le terrain"
    }
  ],
  "screenshots": [
    {
      "src": "screenshots/desktop-1280x720.png",
      "sizes": "1280x720",
      "type": "image/png",
      "form_factor": "wide",
      "label": "Interface principale desktop"
    },
    {
      "src": "screenshots/mobile-540x720.png",
      "sizes": "540x720",
      "type": "image/png",
      "form_factor": "narrow",
      "label": "Interface mobile responsive"
    }
  ],
  "related_applications": [
    {
      "platform": "play",
      "url": "https://play.google.com/store/apps/details?id=com.shield.command",
      "id": "com.shield.command"
    }
  ]
}

3

Exercice 3 : Interface Holographique

Canvas 2D + WebGL + Interaction + Animation

🎯 Objectif

html

                    &lt;canvas id="demo-canvas" width="300" height="200" class="w-full border border-neon-green/30 rounded"&gt;
                        Votre navigateur ne supporte pas Canvas
                    &lt;/canvas&gt;

Créez une interface holographique interactive utilisant Canvas 2D et WebGL. L'utilisateur peut interagir avec des éléments 3D et voir des données en temps réel.

💻 Code à implémenter

HTML Canvas :

html

<canvas id="hologram"
        width="800"
        height="600"
        aria-label="Interface holographique interactive">
  Interface holographique non supportée
</canvas>

JavaScript (à compléter) :

html

class HologramInterface {
  constructor(canvasId) {
    this.canvas = document.getElementById(canvasId);
    this.ctx = this.canvas.getContext('2d');
    // TODO: Initialiser WebGL si disponible
    // TODO: Configurer les événements de souris
  }

  render() {
    // TODO: Nettoyer le canvas
    // TODO: Dessiner les éléments holographiques
    // TODO: Animer les particules
    requestAnimationFrame(() => this.render());
  }

  handleMouseMove(event) {
    // TODO: Interaction avec la souris
  }
}

// TODO: Initialiser l'interface

html

class HologramInterface {
  constructor(canvasId) {
    this.canvas = document.getElementById(canvasId);
    this.ctx = this.canvas.getContext('2d');
    this.mouseX = 0;
    this.mouseY = 0;
    this.particles = [];
    this.time = 0;

    this.initParticles();
    this.bindEvents();
    this.render();
  }

  initParticles() {
    for (let i = 0; i < 50; i++) {
      this.particles.push({
        x: Math.random() * this.canvas.width,
        y: Math.random() * this.canvas.height,
        vx: (Math.random() - 0.5) * 2,
        vy: (Math.random() - 0.5) * 2,
        size: Math.random() * 3 + 1,
        color: `hsl(${120 + Math.random() * 60}, 70%, 50%)`
      });
    }
  }

  bindEvents() {
    this.canvas.addEventListener('mousemove', (e) => {
      const rect = this.canvas.getBoundingClientRect();
      this.mouseX = e.clientX - rect.left;
      this.mouseY = e.clientY - rect.top;
    });

    this.canvas.addEventListener('click', (e) => {
      this.createRipple(this.mouseX, this.mouseY);
    });
  }

  createRipple(x, y) {
    // Effet de ripple au clic
    for (let i = 0; i < 20; i++) {
      const angle = (i / 20) * Math.PI * 2;
      this.particles.push({
        x: x,
        y: y,
        vx: Math.cos(angle) * 5,
        vy: Math.sin(angle) * 5,
        size: 2,
        color: '#00FF94',
        life: 60
      });
    }
  }

  drawGrid() {
    this.ctx.strokeStyle = 'rgba(0, 217, 255, 0.2)';
    this.ctx.lineWidth = 1;

    const gridSize = 30;
    for (let x = 0; x < this.canvas.width; x += gridSize) {
      this.ctx.beginPath();
      this.ctx.moveTo(x, 0);
      this.ctx.lineTo(x, this.canvas.height);
      this.ctx.stroke();
    }

    for (let y = 0; y < this.canvas.height; y += gridSize) {
      this.ctx.beginPath();
      this.ctx.moveTo(0, y);
      this.ctx.lineTo(this.canvas.width, y);
      this.ctx.stroke();
    }
  }

  drawCursor() {
    const radius = 20;
    const pulseRadius = radius + Math.sin(this.time * 0.1) * 5;

    this.ctx.strokeStyle = '#00FF94';
    this.ctx.lineWidth = 2;
    this.ctx.beginPath();
    this.ctx.arc(this.mouseX, this.mouseY, pulseRadius, 0, Math.PI * 2);
    this.ctx.stroke();

    // Croix au centre
    this.ctx.beginPath();
    this.ctx.moveTo(this.mouseX - 10, this.mouseY);
    this.ctx.lineTo(this.mouseX + 10, this.mouseY);
    this.ctx.moveTo(this.mouseX, this.mouseY - 10);
    this.ctx.lineTo(this.mouseX, this.mouseY + 10);
    this.ctx.stroke();
  }

  updateParticles() {
    for (let i = this.particles.length - 1; i >= 0; i--) {
      const p = this.particles[i];

      p.x += p.vx;
      p.y += p.vy;

      // Rebond sur les bords
      if (p.x < 0 || p.x > this.canvas.width) p.vx *= -1;
      if (p.y < 0 || p.y > this.canvas.height) p.vy *= -1;

      // Attraction vers la souris
      const dx = this.mouseX - p.x;
      const dy = this.mouseY - p.y;
      const distance = Math.sqrt(dx * dx + dy * dy);

      if (distance < 100) {
        p.vx += dx * 0.0001;
        p.vy += dy * 0.0001;
      }

      // Vie limitée pour les ripples
      if (p.life !== undefined) {
        p.life--;
        if (p.life <= 0) {
          this.particles.splice(i, 1);
          continue;
        }
      }

      // Dessiner la particule
      this.ctx.fillStyle = p.color;
      this.ctx.beginPath();
      this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
      this.ctx.fill();
    }
  }

  drawHUD() {
    // Interface HUD style S.H.I.E.L.D.
    this.ctx.strokeStyle = '#00D9FF';
    this.ctx.fillStyle = '#00D9FF';
    this.ctx.font = '14px monospace';
    this.ctx.lineWidth = 2;

    // Coin supérieur gauche
    this.ctx.strokeRect(10, 10, 200, 80);
    this.ctx.fillText('S.H.I.E.L.D. SYSTEM', 20, 30);
    this.ctx.fillText(`PARTICLES: ${this.particles.length}`, 20, 50);
    this.ctx.fillText(`CURSOR: ${this.mouseX}, ${this.mouseY}`, 20, 70);

    // Coin supérieur droit
    const rightX = this.canvas.width - 150;
    this.ctx.strokeRect(rightX, 10, 140, 60);
    this.ctx.fillText('STATUS: ONLINE', rightX + 10, 30);
    this.ctx.fillText(`TIME: ${this.time}`, rightX + 10, 50);
  }

  render() {
    this.time++;

    // Nettoyer le canvas avec un effet de trail
    this.ctx.fillStyle = 'rgba(15, 20, 25, 0.1)';
    this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);

    this.drawGrid();
    this.updateParticles();
    this.drawCursor();
    this.drawHUD();

    requestAnimationFrame(() => this.render());
  }
}

// Initialiser l'interface quand le DOM est prêt
document.addEventListener('DOMContentLoaded', () => {
  new HologramInterface('hologram');
});

🛡️ S.H.I.E.L.D. Command PWA

Voici le résultat final : une Progressive Web App complète utilisant toutes les techniques HTML5 avancées. Interface de commandement S.H.I.E.L.D. installable avec fonctionnement hors-ligne.

🖥️ S.H.I.E.L.D. Command Center v3.0

PWA Ready

Le style est écrit en ligne dans la maquette : c’est ce que produit le code montré au-dessus.

Installable

App native avec icône sur l'écran d'accueil

Offline First

Fonctionne sans connexion internet

Push Notifications

Alertes mission en temps réel

Performance

Chargement instantané avec le cache

🚀 Maîtrisez HTML5 Moderne 🚀

Vous venez de découvrir les techniques HTML5 les plus avancées ! Web Components, PWA, APIs natives - tout pour créer des applications web modernes.

🏆 Votre Parcours HTML5 Expert

Sémantique → Web Components → PWA → APIs Natives → Expert HTML5

Maîtrisez HTML5 moderne

Vous venez de découvrir les techniques HTML5 les plus avancées. Web Components, PWA et APIs natives sont désormais à votre portée.