Revision guide built from your lecture slides

Learn HTML, CSS3 & Bootstrap 5 for the exam

Every topic from Lectures 1–7, explained simply. The code blocks show what the browser displays, the widgets let you play with layout, and each lecture ends with likely exam questions and their answers.

Read a lectureOpen the Q&A and answer out loudTick “I've revised this”Finish with the quiz
Lecture 1 · HTML

HTML Basics

HTML (HyperText Markup Language) describes the content of a web page using tags. Each page on a website is one HTML file.

1.1HTML files and tags

HTML files

  • Each web page = one HTML file
  • Written in plain ASCII text (Notepad works)
  • Extension: .html or .htm

Tags

  • Usually come in two parts: opening <html> and closing </html>
  • The pair marks off text and says how to format it
  • Most tags support attributes

DTD (Document Type Definition)

A collection of rules written in SGML (Standard Generalized Markup Language). HTML is defined by its DTDs: all details of tags, entities and document structure live there.

Element

A part of the document's structure, like a title, a paragraph or a list. It includes the opening tag, the closing tag and the content in between.

Remember: how a page looks also depends on the browser settings, and on the user's system and monitor.

1.2Basic page structure

The page as a family tree every tag sits inside its parent
<html> — the root, wraps everything
<head> — invisible info
<title><meta><style><link>
Shown on the tab, read by the browser
<body> — what visitors see
<h1>…<h6><p><a><img><ul> <ol><table><form>

<head>

Information about the page: title, styles, meta. Not shown in the page body.

<title>

Text shown on the browser tab.

<body>

Everything the visitor sees: headings h1–h6, paragraphs p, images, links.

1.3Hyperlinks: <a href>

<a> means anchor. href means hypertext reference: it holds the URL you link to. By default a link is blue and underlined.

Path typeWhere is the file?href value
RelativeSame folderhref="file2.htm"
In a child folder (subfolder)href="foldername/file2.htm"
In the parent folder (up one level)href="../file2.htm"
AbsoluteAnywhere: include the entire URLhref="http://condor.depaul.edu/~gandrus/index.html"
Memory trick: ../ = “go up one floor”. folder/ = “go down into a room”.

1.4Text formatting

<font> tag (old way)

Three attributes: color, size, face. The size is relative to the text before it.

CSS (preferred way)

Define a style rule once, then reuse it with a class.

1.5Special characters and alignment

Write thisBrowser showsWhy you need it
&lt;<A plain < would start a tag
&gt;>Greater-than sign
&amp;&Ampersand
&quot;"Double quote
&nbsp;(space)Non-breaking space; browsers collapse normal extra spaces
&copy;©Copyright sign
&reg;®Registered sign

1.6Lists

Unordered list <ul>

Bullet list. Each item uses <li>. type = disc (default), circle, square.

Ordered list <ol>

Numbered list. type = 1, A, a, I, i. start changes where numbering begins.

<ol type=...>Numbering
type="1"1, 2, 3 (default)
type="A"Uppercase Latin letters: A, B, C
type="a"Lowercase Latin letters: a, b, c
type="I"Uppercase Roman numerals: I, II, III
type="i"Lowercase Roman numerals: i, ii, iii
Exam trick: a nested list goes inside the <li>, before its closing </li>.

?Likely exam questions

What is HTML? What extension do HTML files use?

HTML (HyperText Markup Language) is the markup language that describes the content of a web page using tags. HTML files are plain ASCII text with the extension .html or .htm.

Define DTD and Element.

DTD: Document Type Definition, a collection of rules written in SGML. HTML is defined by its DTDs, which describe all tags, entities and document structure.

Element: a component of a document's structure (title, paragraph, list) made of the opening tag, the content and the closing tag.

What do <a> and href stand for? Write a link to a file in the parent folder.

<a> = anchor, href = hypertext reference. Parent-folder link: <a href="../file2.htm">File 2</a>

Difference between relative and absolute links?

A relative link gives the path from the current file (file.html, sub/file.html, ../file.html). An absolute link includes the entire URL (http://site.com/page.html).

Why is CSS preferred over the <font> tag?

With CSS you define the style once and reuse it everywhere with a class, so changes happen in one place. The font tag must be repeated on every piece of text.

Lecture 2 · HTML

Advanced HTML & HTML5

Clickable image maps, the new HTML5 elements and attributes, plug-ins, and built-in audio/video.

2.1Image maps

An image map makes clickable areas on one image. Three steps:

1 · <img usemap>

Add usemap="#workmap" to the image.

2 · <map name>

name="workmap" must match the usemap value (without #).

3 · <area>

Each clickable area: shape, coords, href, alt.

Computer rect 34,44,270,350 (34,44) top-left bottom-right (270,350) Phone Coffee r=44
rect → coords = top-left x,y , bottom-right x,y circle → coords = center x,y , radius

2.2HTML5 new features (big picture)

New elements

<header>, <footer>, <section>, <article> …

Forms 2.0

New attributes for <input>: autofocus, required, placeholder.

WebSockets

Two-way live connection; libraries like Socket.io make it easier.

Server-Sent Events (SSE)

Server pushes updates; widely supported but more limited than WebSockets.

Canvas

A 2D drawing surface you program with JavaScript (e.g. 2D games).

Audio & Video

Embed media without a plug-in.

Geolocation

Visitors can choose to share their physical location.

Drag & Drop

Any element can be draggable; often replaced by libraries like Sortable.js.

2.3New input attributes

AttributeWhat it does
autofocusCursor goes into this field automatically when the page loads.
requiredForm will not submit while the field is empty. No JavaScript needed for this client-side validation.
placeholderGrey hint text inside <input> / <textarea> showing what to type.

2.4New HTML5 elements

Key point: the input's list attribute must equal the datalist's id.
ElementMeaning
<article>Independent, self-contained content that makes sense on its own (a blog post, a news story).
<datalist>List of pre-defined options for an input: an “autocomplete” feature.
<details> / <summary>Extra details the user can show or hide. summary is the visible heading.
<figure>Self-contained content like illustrations, diagrams, photos, code listings.
<figcaption>Caption for a <figure>.
<mark>Highlighted (marked) text.
<progress>Progress of a task, used with JavaScript. Attributes: value, max.

2.5Plug-ins, video and audio

Plug-ins

Helper programs that extend the functionality of a browser (PDF readers, Flash, maps, virus scan, bank ID). Added with <object> or <embed>.

<object> vs <embed>

<object>: defines an embedded object, supported by all browsers. <embed>: embeds external applications, usually audio/video.

Why give video a width and height? The browser reserves the space while the page loads. Without them the layout jumps while the video loads. controls adds play, pause and volume.

Drag and Drop

“Grab” an object and drag it to another place. In HTML5 it is part of the standard and any element can be draggable.

Geolocation

Gets the user's position with getCurrentPosition(). Because of privacy, it only works after the user approves.

?Likely exam questions

What is an image map? Write the code for a circular clickable area.

An image with several clickable areas, each linking somewhere. <area shape="circle" coords="337,300,44" href="coffee.htm" alt="Coffee"> — center x, center y, radius.

List any five new features of HTML5.

New semantic elements (header, footer, section, article), Forms 2.0 attributes, Canvas, Audio & Video, Geolocation, Drag & Drop, WebSockets, Server-Sent Events.

Difference between placeholder and required?

placeholder only shows a hint inside the box. required stops the form from being submitted while the field is empty.

What is a plug-in? Which tags add one?

A helper program that extends the standard functionality of a browser. Added with <object> or <embed>.

Why is Geolocation not available automatically?

It can compromise user privacy, so the browser shows the position only if the user approves.

Lecture 3 · HTML

Tables

A table is a grid of rows and columns, like a spreadsheet. Know these five tags and two attributes and you can write any table.

3.1The building blocks

<table>

Defines the table.

<tr>

Table Row.

<td>

Table Data (a normal cell).

<th>

Table Heading cell: bold and centered.

<caption>

Title shown above the table.

<thead> <tbody> <tfoot>

Group header, body and footer rows.

Order to remember: table → row → cell. A <td> always lives inside a <tr>; there is no “column” tag.

3.2colspan and rowspan (merge cells)

Same as “merge cells” in Excel. Both are attributes of <td> and <th>.

Common mistake: when a cell has rowspan="2", the next row has one fewer <td>, because the merged cell already fills that spot.

3.3caption, thead, tbody, tfoot

Notice: <tfoot> is written before <tbody> in the code, but the browser still shows it at the bottom.

?Likely exam questions

Difference between <th> and <td>?

<th> is a header cell (bold, centered by default). <td> is a normal data cell.

What are rowspan and colspan?

Attributes of td/th that make a cell span several rows (rowspan=x) or several columns (colspan=x). They work like “merge cells” in Excel.

Write a table: one heading cell spanning 2 columns, then a row with 2 cells.

<table border="1"><tr><th colspan="2">Marks</th></tr><tr><td>Ali</td><td>90</td></tr></table>

What is the use of <caption>, <thead> and <tfoot>?

caption gives the table a title. thead, tbody and tfoot group the header, body and footer rows so they can be styled and handled separately.

Lecture 4 · HTML

HTML Forms

Forms collect data from visitors (name, email, password) and send it to a back-end program such as CGI, ASP or PHP, which processes it.

4.1The <form> tag and its attributes

AttributeMeaning
actionThe back-end script that will process the data.
methodHow data is sent: GET or POST.
targetWhere to show the result: _blank, _self, _parent, …
enctypeHow data is encoded. application/x-www-form-urlencoded = standard (default). multipart/form-data = for uploading files (images, Word files).

4.2GET vs POST

GET

  • Data goes in the URL, visible in the address bar
  • Can be bookmarked and cached
  • Limited size (about 2048 characters)
  • For small, non-sensitive data like search
/submit?username=ali

POST

  • Data goes in the request body, not visible in URL
  • More secure: use for passwords
  • No strict size limit
  • For large or sensitive data
/submit (data hidden in body)
What actually travels to the server same form, two methods
method="GET"
example.com/submit?username=ali&city=lahore
Browser→data glued to the URL→Server
GET /submit?username=ali&city=lahore HTTP/1.1 Host: example.com (no body)

Anyone looking at the screen, the history or a bookmark can see the data.

method="POST"
example.com/submit
Browser→data sealed in the body→Server
POST /submit HTTP/1.1 Host: example.com username=ali&password=••••••

The URL stays clean; the data rides inside the request body.

Memory trick: GET is like a postcard (anyone can read it). POST is like a sealed envelope.

4.3All form controls

Most controls use <input> with a different type. Only two have their own tags: <textarea> and <select>.

ControlCodeUse it when…
Single-line texttype="text"One line of input: name, search box
Passwordtype="password"Same as text but characters are masked
Multi-line text<textarea rows cols>Longer details than one sentence
Checkboxtype="checkbox"More than one option can be selected
Radio buttontype="radio"Only one option out of many (same name)
Select box<select><option>Drop-down list of options
File uploadtype="file"User uploads a file (attribute accept)
Hiddentype="hidden"Data hidden in the page, sent to server, not visible
Buttonssubmit / reset / button / imageSubmit form / reset to initial values / run a script / image as button

4.4Attributes per control

Text input

  • type — text
  • name — sent to the server to identify the value
  • value — initial value
  • size — width in characters
  • maxlength — max characters allowed

textarea

  • name
  • rows — number of rows
  • cols — number of columns

Checkbox & radio

  • type, name
  • value — sent if selected
  • checked — selected by default

select / option

  • select: name, size (scrolling list), multiple (pick many)
  • option: value, selected (default), label

File upload

  • name
  • accept — file types: .jpg,.png, image/*, audio/*, video/*

Button types

  • submit — submits the form
  • reset — clears to initial values
  • button — runs client-side script
  • image — image as the button
Radio trap: radio buttons only work as “pick one” when they share the same name. Checkboxes each get their own name.

?Likely exam questions

Differentiate between GET and POST (4 points).

GET: data in URL / visible / can be bookmarked and cached / limited (~2048 chars) / not for sensitive data. POST: data in request body / hidden / not bookmarked / no strict limit / suitable for passwords.

Checkbox vs radio button?

Checkbox: more than one option can be selected. Radio: only one option out of a group (same name) can be selected.

Which enctype is used for file upload?

multipart/form-data. The default is application/x-www-form-urlencoded.

What is a hidden control and why is it used?

<input type="hidden"> keeps data inside the page (e.g. page number) that is sent to the server but never shown to the user.

Write a form with username, password and a submit button using POST.

<form action="/login" method="POST"> Username: <input type="text" name="user"> Password: <input type="password" name="pass"> <input type="submit" value="Login"> </form>

Lecture 5 · CSS

CSS Introduction

CSS (Cascading Style Sheets) controls how a page looks. HTML gives the content; CSS gives the style.

5.1What and why

History

  • Created by Håkon Lie (MIT) in 1994
  • Became the W3C standard for visual presentation of web pages
  • Works by letting you specify rules

Benefits

  • Saves time, easy to change
  • Keeps consistency across pages
  • More control over layout
  • Works with JavaScript
  • Common format for all pages
Why CSS was needed: HTML was meant to describe content, not format it. When <font> and color attributes were added in HTML 3.2, large sites became a nightmare to maintain. With one external .css file you can change the look of an entire website.

5.2Three ways to add CSS

TypeWhere it goesUse it when…Example
Inlinestyle attribute in the tagFormatting just one element<h1 style="color:red">
Internal / Embedded<style> inside <head>Styling all instances of an element in one page<style>h1{color:red}</style>
ExternalSeparate .css file, linked with <link>Styling an entire website<link rel="stylesheet" href="mystyle.css">
Where each type lives from closest to the element to furthest away
page.html
<body> <h1 style="color:red">
Inline: styles one tag only
page.html
<head> <style> h1 {color:red} </style>
Internal: styles this one page
page1 · page2 · page3 .html
<head> <link href="mystyle.css">
mystyle.cssh1 {color:red}
External: one file styles the whole site
Cascading order: who wins when rules clash?
1
Inline style — highest priority
2
External and internal style sheets (the one written later wins)
3
Browser default — lowest
Best practice from the slides: put styles in external sheets wherever possible; use a global.css for the whole site, refine with section.css, and avoid styles inside tags.

5.3Anatomy of a CSS rule

h1 { color : blue ; font-size : 12px ;} Selector Declaration Declaration Property Value Property Value

A rule = selector (which elements) + declaration (how to style them). Each declaration = property : value, ending with a semicolon.

Element selector

p { } — all <p> elements

ID selector: #

#intro { } → <p id="intro">
For one unique element

Class selector: .

.center { } → <p class="center">
For many elements

Memory trick: # ID = your ID card, only one person has it. . class = a classroom, many students share it.

?Likely exam questions

What are the three ways to insert CSS? Give an example of each.

Inline: <h1 style="color:red">. Internal: <style> h1{color:red} </style> in head. External: a .css file linked with <link rel="stylesheet" type="text/css" href="mystyle.css">.

What is the cascading order?

1. Inline style (highest) 2. External and internal style sheets 3. Browser default (lowest).

Difference between ID and class selector?

ID (#name) styles one unique element. Class (.name) can be applied to many elements.

What does a CSS rule consist of?

A selector (the element(s) the rule applies to) and a declaration block of property: value pairs.

Lecture 5 · CSS3

CSS3 Features

CSS3 adds rounded corners, shadows, transforms, transitions and columns without images, Photoshop, Flash or JavaScript.

5.4What is CSS3?

Timeline

  • First CSS published: late 1996 (fonts, colors, backgrounds, alignment)
  • Earliest CSS3 drafts: June 1999
  • CSS3 is split into separate documents called modules

Important modules

Selectors · Box Model · Backgrounds and Borders · Text Effects · 2D/3D Transformations · Animations · Multiple Column Layout · User Interface

5.5Borders, shadows, backgrounds

PropertyWhat it doesExample
border-radiusRounded corners (CSS2 needed images for each corner)border-radius: 25px;
box-shadowShadow behind a box: h-offset v-offset blur color10px 10px 5px #888
border-imageUse an image as a border (sliced into 9 sections)border-image: url(b.png) 30 round;
background-sizeSize of the background image (before CSS3 it was the image's real size)background-size: 80px 60px;
text-shadowShadow on text5px 5px 5px #FF0000
word-wrapLets long words break onto the next lineword-wrap: break-word;

5.6Transforms (hover or tap each box)

A transform changes an element's shape, size and position: move, scale, turn, spin, stretch.

translate(30px,20px)
rotate(30deg)
scale(1.6,0.7)
skew(30deg,20deg)

translate(x,y)

Moves the element from its current position.

rotate(deg)

Turns clockwise by the given degrees.

scale(x,y)

Grows/shrinks width and height. scale(2,4) = 2× wide, 4× tall.

skew(x,y)

Slants the element along the X and Y axes.

5.7Transitions, columns, user interface

A transition lets an element change gradually from one style to another, without Flash or JavaScript.

Timing functions raceAll take 2s; they differ in speed during the move.
ease
linear
ease-in
ease-out
ease-in-out
ease slow start, fast, slow end (default) linear same speed the whole way ease-in slow start ease-out slow end ease-in-out slow start and slow end

resize

Whether the user can resize an element: horizontal, vertical, both. Needs overflow: auto.

box-sizing

Whether padding and border are included in width/height.

outline-offset

Draws the outline beyond the border edge.

Outlines differ from borders in two ways: outlines do not take up space, and outlines may be non-rectangular.

?Likely exam questions

What is CSS3? Name its important modules.

The latest standard of CSS, split into modules: Selectors, Box Model, Backgrounds and Borders, Text Effects, 2D/3D Transformations, Animations, Multiple Column Layout, User Interface.

Name the CSS3 border properties.

border-radius, box-shadow, border-image.

List the 2D transform methods with an example.

translate(50px,100px), rotate(30deg), scale(2,4), skew(30deg,20deg).

Two differences between outline and border?

Outlines do not take up space, and they may be non-rectangular. Outline is drawn outside the border and does not change the element's size.

Lecture 6 · CSS3 Notes

CSS Properties, Layout & Responsive Design

The biggest lecture. Focus hardest on: box model, display, position, float, selectors, flexbox, media queries and units.

6.1Backgrounds, borders, margin & padding

Background

  • background-color
  • background-image
  • background-repeat: repeat-x, repeat-y, no-repeat
  • background-position: right top
  • background-attachment: fixed (does not scroll)
  • background: shorthand for all

Border

  • border-style: dotted, dashed, solid, double, groove, ridge, inset, outset, none, hidden
  • border-width: thin, medium, thick, px
  • border-color
  • Shorthand: border: 2px solid red; (style is required)
The 1-to-4 value rule (margin, padding, border): values go clockwise — top, right, bottom, left. margin: 10px 20px; = top/bottom 10px, left/right 20px. Memory trick: TRouBLe.

6.2The box model (play with it)

Every HTML element is a box: content → padding (inside border, transparent) → border → margin (outside border, transparent). width and height set the content size only.

margin
border
padding
content 200px
Exam formula: total width = width + left/right padding + left/right border + left/right margin. With box-sizing: border-box, padding and border are included in the width.

Width & height

Values: auto, length (px, cm), %. max-width overrides width and handles small windows better. Also min-width, max-height, min-height.

Outline

A line drawn outside the border. It is not part of the element's size. Properties: outline-style, outline-width, outline-color, outline-offset, outline (shorthand).

6.3Text, font and links

Text properties

  • color
  • text-align: left, right, center, justify
  • text-decoration: overline, line-through, underline, none (remove link underline)
  • text-transform: uppercase, lowercase, capitalize
  • text-indent, letter-spacing, word-spacing, line-height, direction (rtl)

Font properties

  • font-family (give fallbacks, end with a generic family)
  • font-size: px, em, %. 1em = current font size, 16px by default
  • font-style: normal, italic, oblique
  • font-weight: normal, bold
  • font-variant: normal, small-caps
  • font: all in one
Link states MUST be in this order: LoVe HAte → :link, :visited, :hover, :active.

6.4Lists and tables in CSS

List properties

  • list-style-type: circle, square, upper-roman, lower-alpha
  • list-style-image: url("the_url")
  • list-style-position: inside, outside
  • list-style: shorthand

Table properties

  • border, border-collapse: collapse (single border)
  • text-align, vertical-align
  • tr:hover — hoverable table
  • tr:nth-child(even) — zebra stripes
  • Responsive: wrap in <div style="overflow-x:auto">

6.5Display: block, inline, none

Block elementInline element
New line?Always starts on a new lineDoes not start on a new line
WidthFull width availableOnly as much as necessary
Examplesdiv h1–h6 p form header footer sectionspan a img
display: nonevisibility: hidden
Hidden?YesYes
SpacePage shows as if the element is not thereStill takes up the same space
LayoutDoes not affect layoutStill affects the layout
Hide box B:
A
B
C
B is visible.

display: inline-block

Like inline (sits in a line, wraps nicely) but can have a width and height. An easier way to make a grid of boxes than float.

6.6Position (try each value)

top: 20px; left: 30px;
parent (position: relative)
Sibling 1
Me
Sibling 2
the viewport (browser window)
ValuePositioned relative toLeaves a gap?Key fact
staticNormal page flow—Default. Ignores top/left/right/bottom
relativeIts own normal positionYesOther content does not fill its gap
fixedThe viewportNoStays in place even when page scrolls
absoluteNearest positioned ancestorNoIf none, uses the body and moves with scrolling
“Positioned” element = any element whose position is anything except static. Use z-index to set stack order when elements overlap.

6.7Float, clear and centering

float

Whether an element should float (left/right). Elements after it flow around it.

clear

Which sides floating elements are not allowed. If a floated child is taller than its container, add overflow: auto to the container.

6.8Selectors: combinators, pseudo-classes, pseudo-elements, attributes

CombinatorSymbolExampleSelects
Descendantspacediv pAll <p> inside a <div> (any depth)
Child>div > p<p> whose parent is <div> (immediate children)
Adjacent sibling+div + pThe <p> immediately after a <div>
General sibling~p ~ ulAll <ul> after a <p> (same parent)
Which <p> gets selected?
<div> ← the reference div
<p>A</p> direct child
<span>
<p>B</p> grandchild (inside span)
</span>
</div>
<p>C</p> right after the div
<ul>…</ul>
<p>D</p> later sibling

Pseudo-class selector:pseudo-class

A special state of an element.

:hover :focus :checked :disabled :first-child :last-child :nth-child(n) :not(p) :required :valid

Pseudo-element selector::pseudo-element

A specific part of an element.

::before ::after ::first-letter ::first-line ::selection

Attribute selectorMatches elements whose attribute…Example
[attr]exists[target]
[attr="value"]equals value exactly[target="_blank"]
[attr~="word"]contains the whole word[title~="flower"]
[attr|="word"]is “word” or starts with “word-”[lang|="en"]
[attr^="x"]starts with xa[href^="https"]
[attr$="x"]ends with xa[href$=".pdf"]
[attr*="x"]contains x anywherea[href*="uu"]
Memory trick: ^ = start (like the start of a regex), $ = end (money comes at the end), * = anywhere (wildcard).

CSS counters

counter-reset, counter-increment, counter(), content.

Image sprites

Many images put into one image; reduces server requests and saves bandwidth.

Opacity

opacity: 0.4 (0 = invisible, 1 = solid). Navbar = list of links; dropdown uses :hover + display.

6.9CSS3 colours, gradients, shadows, text

Colours in CSS3

Names, hex, RGB, plus RGBA, HSL, HSLA and opacity. The “A” = alpha (transparency).

Gradients

linear-gradient(direction, c1, c2…), radial-gradient(shape size at position, c1, c2…), plus repeating versions.

Backgrounds

Multiple backgrounds; background-size: length, %, contain, cover, auto. background-origin/clip: border-box, padding-box, content-box.

Text & fonts

text-overflow, word-wrap, word-break. @font-face uses fonts not installed on the user's computer.

6.10Flexbox (play with it)

Flexbox = a flex container (display: flex) with flex items inside, laid out along a flex line.

1
2
3
4
Main axis vs cross axis understand this and every flex property makes sense
flex-direction: row (default)
1 2 3 MAIN axis → justify-content CROSS axis → align-items items flow left → right
flex-direction: column
1 2 3 MAIN → justify-content CROSS axis → align-items items flow top → bottom
Golden rule: Justify = Journey along the main axis. Align = Across (the cross axis). In a row justify is horizontal; in a column the two swap, so justify becomes vertical.
justify-content spacing along the main axis
123
flex-start

Packed at the start. This is the default.

123
flex-end

Packed at the end.

123
center

Packed in the middle.

123
space-between

First and last touch the edges; equal gaps between items.

123
space-around

Equal space around each item, so the edges get half a gap.

123
space-evenly

Every gap, edges included, is exactly equal.

align-items position on the cross axis (items have different heights)
123
stretch

Items stretch to fill the height. This is the default.

123
flex-start

Lined up at the top.

123
flex-end

Lined up at the bottom.

123
center

Centred vertically.

AaAaAa
baseline

The bottoms of the text line up, whatever the font size.

flex-direction which way the main axis runs
123
row

Left to right. Default.

123
row-reverse

Right to left: order flips and items start from the right.

123
column

Top to bottom, like normal block elements.

123
column-reverse

Bottom to top.

flex-wrap six 50px items in a narrow box
123456
nowrap

Default. Everything is forced onto one line; items shrink.

123456
wrap

Items that don't fit move to a new line below.

123456
wrap-reverse

Wraps, but new lines go above.

align-content spaces the lines — only works with wrap and 2+ lines
123456
flex-start

Lines packed at the top.

123456
center

Lines packed in the middle.

123456
space-between

First line at top, last at bottom.

123456
stretch

Lines stretch to fill the space. Default.

align-items vs align-content: align-items places items inside each line; align-content places the lines themselves, and does nothing when there is only one line.
Flex item properties set on the children, not the container
A
order:2
B
order:3
C
order:1
order

Written A, B, C in HTML but shown C, A, B. Lower order comes first (default 0).

flex:1flex:2flex:1
flex

Shares the free space by weight: the middle item gets twice as much.

1align-self
flex-end
3
align-self

Overrides the container's align-items for one item.

LogoHomeLogin
margin-left: auto

Absorbs the extra space and pushes items to the far side.

Recipes you can write in the exam
Centre
justify-content:center; align-items:center;

Perfect centring, both directions.

LogoHomeAboutContact
justify-content:space-between; align-items:center;

Navbar: logo on the left, links on the right.

Container properties

  • flex-direction
  • justify-content — horizontal (main axis)
  • align-items — vertical (cross axis)
  • align-content — for flex lines
  • flex-wrap

Item properties

  • order — order inside the container
  • margin: auto — perfect centring
  • align-self — overrides align-items for one item
  • flex — weight of the item's length

6.11Transforms, transitions, animations, filters

2D transforms

translate(x,y) rotate(deg) scale(x,y) skew(x,y) matrix(). Properties: transform, transform-origin.

3D transforms

translate3d scale3d rotate3d rotateX/Y/Z perspective. Properties: transform-style, perspective-origin, backface-visibility.

Transitions

Change values smoothly over a duration. Specify the property and the duration. Timing: ease (default), linear, ease-in, ease-out, ease-in-out, cubic-bezier(n,n,n,n).

Filters

Visual effects (often on images): blur(px), brightness(%), contrast(%), drop-shadow, grayscale(%), hue-rotate(deg), invert(%), opacity(%), saturate(%), sepia(%). Separate many with a space.

Animation propertyMeaning
@keyframes nameDefines the animation steps (from/to or %)
animation-name / -duration / -delayWhich keyframes, how long, wait before start
animation-iteration-countNumber or infinite
animation-directionnormal, reverse, alternate…
animation-timing-functionease, linear, ease-in, ease-out, ease-in-out
animation shorthandname duration timing-function delay iteration-count direction
Transition vs animation: a transition needs a trigger (like :hover) and goes from A to B. An animation uses @keyframes, can have many steps and can run on its own and repeat.

6.12Responsive Web Design (RWD)

RWD uses only HTML and CSS to resize, hide, shrink, enlarge or move content so the page looks good on any screen.

Viewport rules

  • Viewport = user's visible area of a page; varies by device
  • Do NOT use large fixed-width elements
  • Do NOT rely on one viewport width
  • Use media queries for small vs large screens

Grid view

Page divided into columns, usually 12 columns with total width 100%, shrinking and growing with the window. .col-1 {width: 8.33%} … .col-12 {width: 100%}. Use * {box-sizing: border-box}.

Media types & features

Types: all, print, screen, speech. Features: width/height of viewport or device, orientation (landscape/portrait), resolution.

Mobile first

Design for mobile before desktop, so the page displays faster on smaller devices.

Responsive images

width: 100% scales up and down. max-width: 100% scales down but never larger than original. background-size: contain / 100% 100% / cover.

<picture> element

Defines more than one image; the first <source> that fits is used. Frameworks: Bootstrap, Foundation, Skeleton, w3.css.

6.13CSS functions and units

attr()

Returns the value of an attribute: a:after { content: " (" attr(href) ")"; }

calc()

Performs a calculation: width: calc(100% - 100px);

Relative unitRelative to
emfont-size of the element
remfont-size of the root element
exx-height of current font
vw / vh1% of viewport width / height
vmin / vmax1% of the smaller / larger dimension
%parent element
chwidth of “0”
Absolute unitSize
cm / mmcentimetres / millimetres
in1in = 96px = 2.54cm
px1px = 1/96 of 1in
pt1pt = 1/72 of 1in
pc1pc = 12pt

?Likely exam questions

Explain the CSS box model with a diagram.

Draw four nested boxes: Margin (outside) → Border → Padding → Content (inside). Content: where text/images appear. Padding: clear area around content, inside the border. Border: around padding and content. Margin: clear area outside the border. width/height apply to content.

Difference between margin and padding?

Margin is space outside the border (between elements). Padding is space inside the border (between border and content). Both are transparent.

Explain the four position values.

static (default, normal flow), relative (moved from its normal position, leaves a gap), fixed (relative to viewport, stays when scrolling), absolute (relative to nearest positioned ancestor, removed from flow).

Difference between display:none and visibility:hidden?

display:none removes the element; the page shows as if it isn't there. visibility:hidden hides it but it still takes up its space and affects the layout.

What is a media query? Write one.

A CSS3 technique using the @media rule to apply CSS only if a condition is true. @media only screen and (max-width: 500px) { body { background-color: lightblue; } }

Pseudo-class vs pseudo-element?

Pseudo-class (:hover) styles a special state. Pseudo-element (::first-letter) styles a specific part of an element. Pseudo-class uses one colon, pseudo-element uses two.

What is responsive web design and the viewport meta tag?

RWD makes pages look good on all devices using HTML and CSS only. The viewport meta tag <meta name="viewport" content="width=device-width, initial-scale=1.0"> sets the page width to the device width.

Lecture 7 · Bootstrap 5

Bootstrap 5

The most popular front-end CSS framework for building responsive, mobile-first websites using HTML, CSS and JavaScript. You add ready-made classes instead of writing CSS.

7.1Why Bootstrap, and what's new in version 5

Why use Bootstrap?

  • Increases development speed
  • Assures responsiveness
  • Prevents repetition between projects
  • Adds consistency
  • Cross-browser compatibility
  • Large community, customizable

Bootstrap 5 vs 4

  • jQuery not required anymore
  • Dropped Internet Explorer support
  • RTL (right-to-left) text support
  • Less JS, more CSS custom properties
  • Options available as data-attributes
  • Enhanced grid; new offcanvas; Popper.js v2
  • Jumbotron removed
  • SVG icon library; lighter → better SEO
Testing the setup: if the blue alert alert-primary box appears, Bootstrap is connected.

7.2The grid system (drag the screen width)

Container → row → columns. Up to 12 columns per row; group them to make wider columns. The layout can change with screen size (e.g. sidebar beside content on desktop, stacked on mobile).

123456789101112 col-8col-4 col-4col-4col-4 col-6col-6
<div class="col-12 col-md-6 col-lg-4"> ×3 + <div class="col-md-8 col-12">Main</div><div class="col-md-4 col-12">Side Bar</div>
Breakpoint ruler width of each band is to scale (0 – 1600px)
xs0–575pxphones
sm≥576large phones
md≥768tablets
lg≥992laptops
xl≥1200desktops
xxl≥1400big screens
Screen widthClass infixBreakpoint
0 – 576pxnone (col-)X-Small
≥ 576pxsmSmall
≥ 768pxmdMedium
≥ 992pxlgLarge
≥ 1200pxxlExtra Large
≥ 1400pxxxlExtra Extra Large
Memory trick: “Some Men Like Xtra XL” → sm 576 · md 768 · lg 992 · xl 1200 · xxl 1400. A class like col-md-6 means “half width from medium screens and up”.

.container

Responsive fixed width container (has max-width per breakpoint).

.container-fluid

Full width container spanning the whole viewport.

7.3Buttons

btn-primarybtn-secondarybtn-successbtn-dangerbtn-warningbtn-infobtn-lightbtn-darkbtn-link
btn-outline-primarybtn-outline-successbtn-outline-dangerbtn-outline-warning
btn-lgnormalbtn-sm
Pattern: always btn + a colour (btn-primary) and optionally a size (btn-lg/btn-sm). Outline style: btn-outline-*.

7.4Cards

card-header
card-img-top
card-titlecard-text inside card-bodySee Profile
card-footer

Card classes

  • card — the box
  • card-body — main content
  • card-title, card-text
  • card-header, card-footer
  • card-img-top / card-img-bottom
  • Colours: bg-primary text-white; borders: border-primary
  • card-group — cards joined side by side
  • shadow (shadow-sm / shadow-lg)
  • Size by style (width:18rem) or by grid (col-sm-6)

7.5Typography and utilities

ClassWhat it does
h1…h6 (as class)Make any element look like a heading: <p class="h1">
display-1…display-6Extra large, eye-catching headings
text-start / text-center / text-endText alignment
list-unstyledRemoves bullets
list-inline + list-inline-itemList items in one line
blockquote, blockquote-footerQuotes with source
text-primary, text-danger, text-muted…Text colour
bg-primary, bg-warning, bg-gradient…Background colour / gradient
my-4, mb-3, p-3m = margin, p = padding, y = top+bottom, x = left+right, t/b = top/bottom
Spacing decoder: my-4 = margin on y-axis (top & bottom) size 4. px-2 = padding left & right size 2.
bg-primary bg-secondary bg-success bg-danger bg-warning bg-info bg-light bg-dark

7.6Forms in Bootstrap

Main classes to remember

  • form-control — text, email, password inputs
  • form-label — labels
  • form-select — drop-down
  • form-check, form-check-input, form-check-label — checkbox / radio
  • form-check-inline, form-switch
  • input-group, input-group-text — add-ons like “@”

7.7Carousel and other components

A carousel is a slideshow. Structure: carousel slide → carousel-inner → several carousel-item (one has active), plus carousel-control-prev/next buttons and optional carousel-indicators and carousel-caption. It starts with data-bs-ride="carousel".

Commonly used components & helpers

Spinners · List group · Alerts · Toasts · Modal · Badges · Tooltips · Navbars · Breadcrumbs · Clearfix · Panels · Buttons · Icons · Pagination · Cards · Tables · Popovers · Carousel · Progress bars · Collapse · Gutters · Scrollspy · Dropdowns

?Likely exam questions

What is Bootstrap? Why use it?

The most popular front-end CSS framework for responsive, mobile-first websites (HTML/CSS/JS). It increases development speed, assures responsiveness, prevents repetition, adds consistency, ensures cross-browser compatibility, has a large community and is customizable.

Write any five differences between Bootstrap 4 and Bootstrap 5.

BS5: no jQuery needed; dropped IE support; RTL support; JS minimized in favour of CSS custom properties; options as data-attributes; enhanced grid; new offcanvas component; Popper.js v2; Jumbotron removed; SVG icon library; lighter weight (good for SEO).

Explain the Bootstrap grid system and its breakpoints.

Container → row → columns, max 12 columns per row. Breakpoints: xs <576px (no infix), sm ≥576, md ≥768, lg ≥992, xl ≥1200, xxl ≥1400. col-md-4 = 4 of 12 columns from medium screens up.

Difference between .container and .container-fluid?

.container is a responsive fixed-width container. .container-fluid is full width, spanning the entire viewport.

Write code for a row with a 2/3 main area and a 1/3 sidebar that stack on mobile.

<div class="container"><div class="row"><div class="col-md-8 col-12">Main</div><div class="col-md-4 col-12">Sidebar</div></div></div>

Revision · all lectures

“Differentiate between…” cheat sheet

Difference questions are the easiest marks in a web-tech paper. Learn these in pairs.

PairFirstSecond
<ul> vs <ol>Bullets, order doesn't matterNumbers/letters, order matters
Relative vs absolute URLPath from current file (../a.html)Entire URL (http://…)
<th> vs <td>Header cell, bold & centeredNormal data cell
rowspan vs colspanMerge cells downward across rowsMerge cells sideways across columns
GET vs POSTData in URL, visible, ~2048 chars, bookmarkableData in body, hidden, no limit, for passwords
Checkbox vs radioSelect manySelect only one (same name)
<object> vs <embed>Embedded object, all browsers, plug-insExternal app, usually audio/video
Inline vs internal vs external CSSstyle attribute: one element<style>: one page · .css file: whole site
ID vs class#id, unique, one element.class, reusable, many elements
Margin vs paddingOutside the borderInside the border
Border vs outlinePart of the box sizeOutside border, takes no space, may be non-rectangular
Block vs inlineNew line, full width (div, p, h1)Same line, needed width (span, a, img)
display:none vs visibility:hiddenRemoved, no spaceInvisible, keeps its space
relative vs absolute positionFrom its normal spot, leaves gapFrom nearest positioned ancestor, removed from flow
fixed vs absoluteRelative to viewport, doesn't scrollRelative to positioned ancestor, scrolls with page
Pseudo-class vs pseudo-element:hover — a state::first-line — a part
Transition vs animationA → B on a trigger@keyframes, many steps, can repeat on its own
em vs remElement's font sizeRoot element's font size
width:100% vs max-width:100% (img)Scales up and downScales down, never above original size
content-box vs border-boxWidth = content only (default)Width includes padding + border
.container vs .container-fluidFixed width per breakpointFull viewport width
Bootstrap 4 vs 5Needs jQuery, supports IE, has JumbotronNo jQuery, no IE, RTL, offcanvas, xxl breakpoint
Self-test

Exam practice quiz

Tap an answer to check it. Wrong answers show the explanation. Filter by lecture to focus on your weak spots.

0 / 0 answered correctly