HTML5
& CSS3

A comprehensive, interactive masterclass covering every major feature — from semantic markup to advanced CSS animations, layouts, and modern tooling.

HTML5 CSS3 JavaScript ● Interactive

Semantic Elements

HTML5 introduced meaningful tags that describe their content's purpose, improving accessibility, SEO, and code readability.

Why semantics matter: Screen readers, search engines, and developer tools all use the element type to infer meaning. A <nav> tells crawlers it's navigation; a <main> marks the primary content.
LIVE DEMO — Semantic Layout
<header>Site Logo & Title
<section> Latest Post
A section groups thematically related content.
<section> Another Section
<article> Self-contained piece of content
<footer>Copyright & Links
semantic-layout.html
<body>
  <header>
    <h1>My Website</h1>
    <nav>
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <article>
      <h2>Post Title</h2>
      <section>
        <p>Content grouped by theme.</p>
      </section>
    </article>
    <aside>Related links / sidebar</aside>
  </main>

  <footer>
    <p><small>&copy; 2025</small></p>
  </footer>
</body>

New HTML5 Elements

<header> <footer> <main> <nav> <section> <article> <aside> <figure> <figcaption> <mark> <time> <details> <summary> <dialog>

Details & Summary — Native Accordion

▶ Click to expand
This is a native HTML5 collapsible! No JavaScript required. Use <details> + <summary>.
▶ Another panel
Zero JavaScript. Pure HTML5 semantics. Works in all modern browsers.

CSS3 Selectors

CSS3 massively expanded selector power — target by state, position, attribute, and relationship without adding classes.

LIVE DEMO — Pseudo-class selectors
  • :first-child — I am first
  • :nth-child(2) — second item
  • :nth-child(3) — font-weight:700
  • :nth-child(odd) — odd rows tinted
  • :last-child — I am last

↑ Hover middle items for :not() selector

selectors.css
/* Positional */
li:first-child  { color: cyan; }
li:last-child   { color: coral; }
li:nth-child(3){ font-weight: 700; }
li:nth-child(odd) { background: #f5f5f5; }

/* Negation */
li:not(:first-child) { padding-left: 16px; }

/* Attribute selectors */
a[href^="https"]  { color: green; }
input[type="email"]{ border: 2px solid blue; }
img[alt]           { outline: 2px solid red; }

/* Combinators */
div > p      { /* direct child */ }
h2 + p       { /* adjacent sibling */ }
h2 ~ p       { /* all siblings */ }
:is() and :where() — New grouping selectors that reduce repetition. :is(h1, h2, h3) a targets links in any heading. :where() has zero specificity.

Specificity

CSS resolves conflicts using a 3-column score: (IDs, Classes/attrs/pseudo-classes, Elements/pseudo-elements). Higher score wins.

Selector IDs Class El Weight
*000
p001
p.note011
div p.note012
#header100
#header .nav a111
#nav #logo.active210
style="" (inline)

Box Model

Every element is a rectangular box with four layers. box-sizing: border-box is the modern default.

VISUAL — Box Layers
MARGIN
BORDER
PADDING
CONTENT
box-model.css
/* Modern reset — box-sizing */
*, *::before, *::after {
  box-sizing: border-box;
}

.card {
  width: 300px;
  padding: 20px;       /* inner space */
  border: 2px solid #00e5ff;
  margin: 16px auto;   /* outer space */
  border-radius: 12px;

  /* box-shadow layers */
  box-shadow:
    0 2px 4px rgba(0,0,0,.2),
    0 8px 32px rgba(0,229,255,.1),
    inset 0 1px 0 rgba(255,255,255,.1);

  /* outline doesn't affect layout! */
  outline: 2px dashed lime;
  outline-offset: 4px;
}

Flexbox

A one-dimensional layout system for distributing space along a row or column. Use the controls below to see properties in action.

INTERACTIVE — Flexbox Playground
A
B
C
D
E
flexbox-cheatsheet.css
/* ── CONTAINER ── */
.flex-container {
  display: flex;
  flex-direction: row;        /* row | column | row-reverse | column-reverse */
  flex-wrap: wrap;            /* nowrap | wrap | wrap-reverse */
  justify-content: space-between; /* main-axis alignment */
  align-items: center;       /* cross-axis alignment */
  align-content: flex-start;  /* multi-line cross-axis */
  gap: 16px 12px;             /* row-gap column-gap */
}

/* ── CHILDREN ── */
.flex-item {
  flex-grow: 1;               /* how much extra space to absorb */
  flex-shrink: 0;             /* 0 = don't shrink */
  flex-basis: 200px;          /* initial size */
  flex: 1 0 200px;            /* shorthand: grow shrink basis */
  align-self: flex-end;       /* override parent align-items */
  order: 2;                   /* visual reordering */
}

CSS Grid

A two-dimensional layout system that gives precise control over both rows AND columns simultaneously.

INTERACTIVE — Grid Playground
grid-cheatsheet.css
/* ── CONTAINER ── */
.grid {
  display: grid;

  /* Named column tracks */
  grid-template-columns: repeat(3, 1fr);

  /* Named row tracks */
  grid-template-rows: 80px auto 60px;

  /* Named areas 
     — match via grid-area on children */
  grid-template-areas:
    "header header header"
    "sidebar main   main"
    "footer footer footer";

  gap: 16px;

  /* Auto-responsive columns */
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* ── ITEMS ── */
.header { grid-area: header; }
.sidebar{ grid-area: sidebar; }

.span-two {
  grid-column: span 2;   /* span 2 column tracks */
  grid-row: 1 / 3;        /* rows 1 through 3 */
}

Media Queries

Adapt layouts to any screen size, orientation, or user preference. The core of responsive design.

VISUAL — Responsive Breakpoints
Mobile
<768px
Tablet
768–1024px
Desktop
1024–1440px
Wide
>1440px
responsive.css
/* Mobile-first approach (recommended) */
.layout {
  display: grid;
  grid-template-columns: 1fr; /* single column on mobile */
}

/* Tablet */
@media (min-width: 768px) {
  .layout { grid-template-columns: 1fr 1fr; }
}

/* Desktop */
@media (min-width: 1024px) {
  .layout { grid-template-columns: 240px 1fr 1fr; }
}

/* Dark mode preference */
@media (prefers-color-scheme: dark) {
  body { background: #111; color: #eee; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; }
}

/* Print */
@media print {
  .sidebar, .ads { display: none; }
}

/* Orientation */
@media (orientation: landscape) { ... }

/* Container Queries (CSS4) */
.card-wrapper { container-type: inline-size; }
@container (min-width: 400px) {
  .card { flex-direction: row; }
}

Gradients

CSS3 gradients are images — use them in backgrounds, borders, masks, even text. Three types: linear, radial, and conic.

VISUAL — Gradient Types
gradients.css
/* Linear — angle, position, to side */
background: linear-gradient(135deg, #00e5ff, #7cfc00);
background: linear-gradient(to right, red, blue);

/* Multi-stop */
background: linear-gradient(to right,
  #ff6b6b 0%,
  #ffb347 25%,
  #00e5ff 75%,
  #7cfc00 100%);

/* Radial — shape at position */
background: radial-gradient(circle at center, cyan, navy);
background: radial-gradient(ellipse at top, #b392f0, #111);

/* Conic — sweeps around a center point */
background: conic-gradient(red, blue, green, red);
background: conic-gradient(from 45deg, cyan 90deg, navy 90deg);

/* Gradient on text! */
h1 {
  background: linear-gradient(90deg, #00e5ff, #7cfc00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Grid pattern using multiple gradients */
background:
  linear-gradient(#ccc 1px, transparent 1px),
  linear-gradient(90deg, #ccc 1px, transparent 1px),
  white;
background-size: 24px 24px;

Transitions & Animations

Transitions animate between two states. @keyframes create complex multi-step sequences, fully CSS-driven.

LIVE DEMO — CSS Animations
spin — linear
pulse — ease-in-out
bounce — cubic-bezier
slide — alternate
gradient — shift
Hello, World!
typewriter — steps()
morph — border-radius
@property — hue rotate
stacked animations
Hover transitions: Move your cursor over each button below.
Lift + Shadow
Background Fill
Glow Effect
Elastic Scale
animations.css
/* ── TRANSITIONS ── */
.button {
  transition: all 0.3s ease;

  /* Fine-grained: property duration easing delay */
  transition:
    background 0.3s ease,
    transform  0.2s cubic-bezier(0.34,1.56,0.64,1),
    box-shadow 0.3s ease;
}

/* ── @KEYFRAMES ── */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-30px); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.element {
  animation-name: bounce;
  animation-duration: 1s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-fill-mode: forwards;
  animation-delay: 0.2s;

  /* Shorthand */
  animation: bounce 1s ease-in-out 0.2s infinite alternate;

  /* Multiple animations separated by comma */
  animation: spin 2s linear infinite, morph 4s ease infinite;
}

/* Typewriter using steps() */
.typewriter {
  overflow: hidden;
  border-right: 2px solid cyan;
  white-space: nowrap;
  animation: typing 3s steps(30, end) infinite;
}
@keyframes typing {
  from { width: 0; }
  to   { width: 100%; }
}

Transforms

Move, rotate, scale, and skew elements without affecting document flow. GPU-accelerated — ideal for animation.

INTERACTIVE — Hover each box
transforms.css
/* Individual transforms */
transform: translateX(20px);
transform: translateY(-50%);      /* % = % of element itself */
transform: translate(-50%, -50%); /* centering trick */
transform: rotate(45deg);
transform: scale(1.2);
transform: scaleX(-1);            /* horizontal flip */
transform: skewX(15deg);
transform: skewY(5deg);

/* Chained — applied right to left */
transform: rotate(30deg) scale(1.1) translateX(10px);

/* Origin point */
transform-origin: top left;
transform-origin: 50% 0;  /* top center */

/* 3D Transforms */
transform: rotateY(45deg);
transform: perspective(400px) rotateY(30deg);
transform-style: preserve-3d;
perspective: 800px;           /* on parent for 3D context */

/* Individual transform properties (newer) */
translate: 10px 20px;
rotate: 45deg;
scale: 1.2;

CSS Filters

Apply Photoshop-like visual effects directly in CSS. Stack multiple filters for compound results.

VISUAL — filter() examples
none
blur(3px)
grayscale
sepia
brightness+contrast
hue-rotate(180°)
invert
saturate+contrast
filters.css
img {
  /* Single */
  filter: blur(4px);
  filter: brightness(0.5);      /* 0=black, 1=normal, 2=2× bright */
  filter: contrast(200%);
  filter: grayscale(100%);
  filter: hue-rotate(90deg);
  filter: invert(1);
  filter: opacity(0.5);
  filter: saturate(3);
  filter: sepia(100%);
  filter: drop-shadow(4px 4px 8px rgba(0,0,0,.5));

  /* Stacked filters (applied left-to-right) */
  filter: contrast(1.4) saturate(1.8) brightness(0.9);

  /* Hover effect: color → greyscale */
  filter: grayscale(100%);
  transition: filter 0.4s;
}
img:hover { filter: grayscale(0%); }

/* backdrop-filter — blur behind an element */
.glass-card {
  backdrop-filter: blur(12px) saturate(1.5);
  background: rgba(255,255,255,0.1);
}

Clip-path

Mask elements into any geometric shape — circles, polygons, ellipses — without images.

VISUAL — Hover to animate
circle(50%)
ellipse
triangle
star
hexagon
pentagon
inset round
cut corner
cross
5-gon
clip-path.css
/* Basic shapes */
clip-path: circle(50%);
clip-path: ellipse(50% 35% at 50% 50%);
clip-path: inset(10px 20px round 8px);

/* Polygon — list of x/y vertices */
clip-path: polygon(50% 0%, 100% 100%, 0% 100%);

/* Diagonal section divider */
.hero {
  clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
}

/* Animated clip-path */
.expand {
  clip-path: circle(0% at 50% 50%);
  transition: clip-path 0.5s ease;
}
.expand:hover {
  clip-path: circle(100% at 50% 50%);
}

/* SVG path reference */
clip-path: path("M10,30 A20,20,0,0,1,50,30 ...");

CSS Custom Properties

CSS variables are live, cascading, JavaScript-accessible. Change one variable to retheme your entire interface instantly.

INTERACTIVE — Theming with CSS Variables
190 90% 55% 10px
Dynamic Theme Preview
Adjust sliders to change CSS variables live
css-variables.css
/* ── DEFINITION ── */
:root {
  --primary: #00e5ff;
  --primary-dark: hsl(188, 90%, 30%);
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* ── USAGE ── */
.card {
  background: var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--spacing-md);

  /* Fallback value */
  color: var(--text-color, #ffffff);
}

/* ── LOCAL SCOPE ── */
.danger-card {
  --primary: #ff6b6b; /* overrides for this element + children */
}

/* ── JAVASCRIPT ACCESS ── */
// Read
getComputedStyle(document.documentElement)
  .getPropertyValue('--primary');

// Write
document.documentElement.style
  .setProperty('--primary', '#ff6b6b');

/* ── CALC WITH VARIABLES ── */
.container {
  --cols: 3;
  width: calc(100% / var(--cols) - var(--spacing-md));
}

Pseudo-elements

::before and ::after inject a virtual element inside the selected element — used for decorations, icons, and effects.

LIVE DEMO

Each paragraph has an arrow prefix

Styled with ::before

No extra HTML needed

Pure CSS decoration

Content generated by CSS is purely decorative and should never carry meaning accessible to screen readers.
pseudo-elements.css
/* Arrow prefix */
p::before {
  content: '›';
  position: absolute;
  left: 0;
  color: cyan;
}

/* Large decorative quote */
blockquote::before {
  content: '"';
  font-size: 5rem;
  color: rgba(0,229,255,0.3);
  position: absolute;
  line-height: 1;
  top: -10px; left: 10px;
}

/* Highlight effect */
h2::after {
  content: '';
  display: block;
  height: 3px;
  width: 60%;
  background: linear-gradient(to right, cyan, transparent);
  margin-top: 6px;
}

/* Counter — other pseudo-elements */
ol              { counter-reset: steps; }
ol li::before  {
  counter-increment: steps;
  content: counter(steps, decimal-leading-zero);
}

/* ::first-line, ::first-letter */
p::first-letter {
  font-size: 3em;
  float: left;
  line-height: 0.8;
}

/* ::selection — custom text selection */
::selection {
  background: rgba(0,229,255,0.3);
  color: white;
}

Positioning

The position property controls how an element is placed and whether it participates in normal document flow.

VISUAL — Position types
static — normal flow
relative — offset by top/left
absolute — top:10, right:10
sticky — stays visible on scroll ↑↓
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
positioning.css
/* static — default */
.default { position: static; }

/* relative — offset from its normal spot */
.nudged  {
  position: relative;
  top: 10px;
  left: 20px;
}

/* absolute — removed from flow;
   positioned relative to nearest
   positioned ancestor            */
.badge   {
  position: absolute;
  top: -8px; right: -8px;
}
.parent { position: relative; }

/* fixed — relative to viewport */
.navbar  {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

/* sticky — relative until threshold */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Centering trick with absolute */
.centered {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

CSS Functions

calc(), min(), max(), and clamp() bring math to CSS — enabling truly responsive, constraint-aware sizing.

VISUAL — Width functions
calc(100% - 80px)
← fills minus 80px →
min(400px, 80%) — cap at 400px
min(400px, 80%)
max(200px, 40%) — at least 200px
max(200px, 40%)
clamp(150px, 50%, 500px) — between 150–500px
clamp(150px, 50%, 500px)
Fluid Typography with clamp(): The font below scales smoothly between viewport sizes — no breakpoints needed.
FLUID TEXT — RESIZE THE WINDOW
css-functions.css
/* calc() — arithmetic with mixed units */
.sidebar {
  width: calc(33.33% - 24px);
  height: calc(100vh - 60px);
  margin: calc(var(--gap) * 2);
}

/* min() — use the smallest value */
.card   { width: min(400px, 90%); }

/* max() — use the largest value */
.btn    { padding: 0 max(20px, 3vw); }

/* clamp(min, preferred, max) — fluid sizing */
h1 {
  font-size: clamp(1.5rem, 5vw, 4rem);
}
.container {
  padding: clamp(16px, 4vw, 60px);
}

/* env() — safe areas (mobile notch) */
.app {
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* color functions */
color: rgb(0 229 255);
color: hsl(188 100% 50%);
color: oklch(0.75 0.2 200);   /* perceptual */
color: color-mix(in srgb, cyan 60%, navy);

HTML5 Forms

HTML5 added 13 new input types, built-in validation, the datalist element, and powerful constraint APIs.

LIVE DEMO — New Input Types
html5-forms.html
<form novalidate>
  <!-- Built-in validation -->
  <input type="email"
         required
         minlength="5"
         placeholder="user@example.com">

  <!-- Pattern regex -->
  <input type="text"
         pattern="[A-Z]{3}-[0-9]{4}"
         title="Format: ABC-1234">

  <!-- Datalist autocomplete -->
  <input list="colors" placeholder="Pick a color">
  <datalist id="colors">
    <option value="Red">
    <option value="Green">
    <option value="Blue">
  </datalist>

  <!-- meter and progress -->
  <meter value="0.6" low="0.3" high="0.8" optimum="1"></meter>
  <progress value="65" max="100"></progress>

  <!-- CSS-only validation styling -->
</form>
/* :valid / :invalid pseudo-classes */
input:valid:not(:placeholder-shown)   { border-color: lime; }
input:invalid:not(:placeholder-shown) { border-color: red;  }

HTML5 Canvas API

A pixel-level 2D drawing surface. Games, charts, image processing — anything rendered via JavaScript.

INTERACTIVE — Canvas Drawing
canvas-api.js
const canvas = document.getElementById('myCanvas');
const ctx    = canvas.getContext('2d');

/* Rectangles */
ctx.fillStyle    = '#00e5ff';
ctx.fillRect(10, 10, 100, 60);        // x,y,w,h
ctx.strokeRect(10, 10, 100, 60);      // outline only
ctx.clearRect(0, 0, canvas.width, canvas.height);

/* Paths */
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(150, 100);
ctx.lineTo(50, 150);
ctx.closePath();
ctx.stroke();                          // draw outline
ctx.fill();                            // fill inside

/* Circles / arcs */
ctx.beginPath();
ctx.arc(200, 100, 50, 0, Math.PI * 2); // cx,cy,r,start,end
ctx.fill();

/* Text */
ctx.font        = 'bold 24px DM Mono';
ctx.fillStyle  = 'white';
ctx.fillText('Hello Canvas', 50, 50);

/* Gradients on canvas */
const grad = ctx.createLinearGradient(0,0,200,0);
grad.addColorStop(0,   '#00e5ff');
grad.addColorStop(1,   '#7cfc00');
ctx.fillStyle = grad;

/* Transform the canvas context */
ctx.save();
ctx.translate(100, 100);
ctx.rotate(Math.PI / 4);
ctx.scale(1.5, 1.5);
ctx.restore();

/* Animation loop */
function loop() {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  draw();
  requestAnimationFrame(loop);
}

Fluid Typography & CSS Text

CSS3 gives text deep styling capabilities — gradients, shadows, custom fonts, variable fonts, and viewport-relative sizing.

VISUAL — Text Effects
Gradient Text
Glowing Text
Outlined Text
SHADOW DEPTH
Rainbow Animated Text
text-effects.css
/* Gradient text */
h1 {
  background: linear-gradient(90deg, cyan, lime);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Glow / shadow */
.glow {
  text-shadow:
    0 0 10px cyan,
    0 0 30px cyan,
    0 0 60px rgba(0,229,255,0.4);
}

/* Outlined only */
.outline {
  color: transparent;
  -webkit-text-stroke: 2px coral;
}

/* Fluid size with clamp */
body  { font-size: clamp(14px, 1.5vw, 18px); }
h1    { font-size: clamp(1.8rem, 5vw, 5rem); }

/* @font-face — custom fonts */
@font-face {
  font-family: 'MyFont';
  src: url('myfont.woff2') format('woff2');
  font-weight: 100 900;     /* variable font range */
  font-display: swap;
}

/* font-variant-numeric */
.price { font-variant-numeric: tabular-nums; }