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.
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:
.htmlor.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.
1.2Basic page structure
<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 type | Where is the file? | href value |
|---|---|---|
| Relative | Same folder | href="file2.htm" |
| In a child folder (subfolder) | href="foldername/file2.htm" | |
| In the parent folder (up one level) | href="../file2.htm" | |
| Absolute | Anywhere: include the entire URL | href="http://condor.depaul.edu/~gandrus/index.html" |
../ = “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 this | Browser shows | Why you need it |
|---|---|---|
< | < | A plain < would start a tag |
> | > | Greater-than sign |
& | & | Ampersand |
" | " | Double quote |
| (space) | Non-breaking space; browsers collapse normal extra spaces |
© | © | Copyright sign |
® | ® | 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 |
<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.
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.
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
| Attribute | What it does |
|---|---|
autofocus | Cursor goes into this field automatically when the page loads. |
required | Form will not submit while the field is empty. No JavaScript needed for this client-side validation. |
placeholder | Grey hint text inside <input> / <textarea> showing what to type. |
2.4New HTML5 elements
list attribute must equal the datalist's id.| Element | Meaning |
|---|---|
<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.
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.
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.
<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>.
rowspan="2", the next row has one fewer <td>, because the merged cell already fills that spot.3.3caption, thead, tbody, tfoot
<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.
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
| Attribute | Meaning |
|---|---|
action | The back-end script that will process the data. |
method | How data is sent: GET or POST. |
target | Where to show the result: _blank, _self, _parent, … |
enctype | How 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
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
4.3All form controls
Most controls use <input> with a different type. Only two have their own tags: <textarea> and <select>.
| Control | Code | Use it when… |
|---|---|---|
| Single-line text | type="text" | One line of input: name, search box |
| Password | type="password" | Same as text but characters are masked |
| Multi-line text | <textarea rows cols> | Longer details than one sentence |
| Checkbox | type="checkbox" | More than one option can be selected |
| Radio button | type="radio" | Only one option out of many (same name) |
| Select box | <select><option> | Drop-down list of options |
| File upload | type="file" | User uploads a file (attribute accept) |
| Hidden | type="hidden" | Data hidden in the page, sent to server, not visible |
| Buttons | submit / reset / button / image | Submit form / reset to initial values / run a script / image as button |
4.4Attributes per control
Text input
type— textname— sent to the server to identify the valuevalue— initial valuesize— width in charactersmaxlength— max characters allowed
textarea
namerows— number of rowscols— number of columns
Checkbox & radio
type,namevalue— sent if selectedchecked— selected by default
select / option
- select:
name,size(scrolling list),multiple(pick many) - option:
value,selected(default),label
File upload
nameaccept— file types:.jpg,.png,image/*,audio/*,video/*
Button types
submit— submits the formreset— clears to initial valuesbutton— runs client-side scriptimage— image as the button
?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>
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
<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
| Type | Where it goes | Use it when… | Example |
|---|---|---|---|
| Inline | style attribute in the tag | Formatting 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> |
| External | Separate .css file, linked with <link> | Styling an entire website | <link rel="stylesheet" href="mystyle.css"> |
5.3Anatomy of a CSS rule
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
?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.
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
| Property | What it does | Example |
|---|---|---|
border-radius | Rounded corners (CSS2 needed images for each corner) | border-radius: 25px; |
box-shadow | Shadow behind a box: h-offset v-offset blur color | 10px 10px 5px #888 |
border-image | Use an image as a border (sliced into 9 sections) | border-image: url(b.png) 30 round; |
background-size | Size of the background image (before CSS3 it was the image's real size) | background-size: 80px 60px; |
text-shadow | Shadow on text | 5px 5px 5px #FF0000 |
word-wrap | Lets long words break onto the next line | word-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.
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.
?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.
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-colorbackground-imagebackground-repeat: repeat-x, repeat-y, no-repeatbackground-position: right topbackground-attachment: fixed (does not scroll)background: shorthand for all
Border
border-style: dotted, dashed, solid, double, groove, ridge, inset, outset, none, hiddenborder-width: thin, medium, thick, pxborder-color- Shorthand:
border: 2px solid red;(style is required)
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.
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
colortext-align: left, right, center, justifytext-decoration: overline, line-through, underline, none (remove link underline)text-transform: uppercase, lowercase, capitalizetext-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 defaultfont-style: normal, italic, obliquefont-weight: normal, boldfont-variant: normal, small-capsfont: all in one
:link, :visited, :hover, :active.6.4Lists and tables in CSS
List properties
list-style-type: circle, square, upper-roman, lower-alphalist-style-image: url("the_url")list-style-position: inside, outsidelist-style: shorthand
Table properties
border,border-collapse: collapse(single border)text-align,vertical-aligntr:hover— hoverable tabletr:nth-child(even)— zebra stripes- Responsive: wrap in
<div style="overflow-x:auto">
6.5Display: block, inline, none
| Block element | Inline element | |
|---|---|---|
| New line? | Always starts on a new line | Does not start on a new line |
| Width | Full width available | Only as much as necessary |
| Examples | div h1–h6 p form header footer section | span a img |
display: none | visibility: hidden | |
|---|---|---|
| Hidden? | Yes | Yes |
| Space | Page shows as if the element is not there | Still takes up the same space |
| Layout | Does not affect layout | Still affects the layout |
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)
| Value | Positioned relative to | Leaves a gap? | Key fact |
|---|---|---|---|
static | Normal page flow | — | Default. Ignores top/left/right/bottom |
relative | Its own normal position | Yes | Other content does not fill its gap |
fixed | The viewport | No | Stays in place even when page scrolls |
absolute | Nearest positioned ancestor | No | If none, uses the body and moves with scrolling |
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
| Combinator | Symbol | Example | Selects |
|---|---|---|---|
| Descendant | space | div p | All <p> inside a <div> (any depth) |
| Child | > | div > p | <p> whose parent is <div> (immediate children) |
| Adjacent sibling | + | div + p | The <p> immediately after a <div> |
| General sibling | ~ | p ~ ul | All <ul> after a <p> (same parent) |
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 selector | Matches 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 x | a[href^="https"] |
[attr$="x"] | ends with x | a[href$=".pdf"] |
[attr*="x"] | contains x anywhere | a[href*="uu"] |
^ = 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.
row justify is horizontal; in a column the two swap, so justify becomes vertical.flex-startPacked at the start. This is the default.
flex-endPacked at the end.
centerPacked in the middle.
space-betweenFirst and last touch the edges; equal gaps between items.
space-aroundEqual space around each item, so the edges get half a gap.
space-evenlyEvery gap, edges included, is exactly equal.
stretchItems stretch to fill the height. This is the default.
flex-startLined up at the top.
flex-endLined up at the bottom.
centerCentred vertically.
baselineThe bottoms of the text line up, whatever the font size.
rowLeft to right. Default.
row-reverseRight to left: order flips and items start from the right.
columnTop to bottom, like normal block elements.
column-reverseBottom to top.
nowrapDefault. Everything is forced onto one line; items shrink.
wrapItems that don't fit move to a new line below.
wrap-reverseWraps, but new lines go above.
flex-startLines packed at the top.
centerLines packed in the middle.
space-betweenFirst line at top, last at bottom.
stretchLines stretch to fill the space. Default.
order:2B
order:3C
order:1
orderWritten A, B, C in HTML but shown C, A, B. Lower order comes first (default 0).
flexShares the free space by weight: the middle item gets twice as much.
flex-end3
align-selfOverrides the container's align-items for one item.
margin-left: autoAbsorbs the extra space and pushes items to the far side.
justify-content:center; align-items:center;Perfect centring, both directions.
justify-content:space-between; align-items:center;Navbar: logo on the left, links on the right.
Container properties
flex-directionjustify-content— horizontal (main axis)align-items— vertical (cross axis)align-content— for flex linesflex-wrap
Item properties
order— order inside the containermargin: auto— perfect centringalign-self— overrides align-items for one itemflex— 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 property | Meaning |
|---|---|
@keyframes name | Defines the animation steps (from/to or %) |
animation-name / -duration / -delay | Which keyframes, how long, wait before start |
animation-iteration-count | Number or infinite |
animation-direction | normal, reverse, alternate… |
animation-timing-function | ease, linear, ease-in, ease-out, ease-in-out |
animation shorthand | name duration timing-function delay iteration-count direction |
: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 unit | Relative to |
|---|---|
em | font-size of the element |
rem | font-size of the root element |
ex | x-height of current font |
vw / vh | 1% of viewport width / height |
vmin / vmax | 1% of the smaller / larger dimension |
% | parent element |
ch | width of “0” |
| Absolute unit | Size |
|---|---|
cm / mm | centimetres / millimetres |
in | 1in = 96px = 2.54cm |
px | 1px = 1/96 of 1in |
pt | 1pt = 1/72 of 1in |
pc | 1pc = 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.
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
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).
| Screen width | Class infix | Breakpoint |
|---|---|---|
| 0 – 576px | none (col-) | X-Small |
| ≥ 576px | sm | Small |
| ≥ 768px | md | Medium |
| ≥ 992px | lg | Large |
| ≥ 1200px | xl | Extra Large |
| ≥ 1400px | xxl | Extra Extra Large |
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 + a colour (btn-primary) and optionally a size (btn-lg/btn-sm). Outline style: btn-outline-*.7.4Cards
Card classes
card— the boxcard-body— main contentcard-title,card-textcard-header,card-footercard-img-top/card-img-bottom- Colours:
bg-primary text-white; borders:border-primary card-group— cards joined side by sideshadow(shadow-sm / shadow-lg)- Size by style (
width:18rem) or by grid (col-sm-6)
7.5Typography and utilities
| Class | What it does |
|---|---|
h1…h6 (as class) | Make any element look like a heading: <p class="h1"> |
display-1…display-6 | Extra large, eye-catching headings |
text-start / text-center / text-end | Text alignment |
list-unstyled | Removes bullets |
list-inline + list-inline-item | List items in one line |
blockquote, blockquote-footer | Quotes with source |
text-primary, text-danger, text-muted… | Text colour |
bg-primary, bg-warning, bg-gradient… | Background colour / gradient |
my-4, mb-3, p-3 | m = margin, p = padding, y = top+bottom, x = left+right, t/b = top/bottom |
my-4 = margin on y-axis (top & bottom) size 4. px-2 = padding left & right size 2.7.6Forms in Bootstrap
Main classes to remember
form-control— text, email, password inputsform-label— labelsform-select— drop-downform-check,form-check-input,form-check-label— checkbox / radioform-check-inline,form-switchinput-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>
“Differentiate between…” cheat sheet
Difference questions are the easiest marks in a web-tech paper. Learn these in pairs.
| Pair | First | Second |
|---|---|---|
| <ul> vs <ol> | Bullets, order doesn't matter | Numbers/letters, order matters |
| Relative vs absolute URL | Path from current file (../a.html) | Entire URL (http://…) |
| <th> vs <td> | Header cell, bold & centered | Normal data cell |
| rowspan vs colspan | Merge cells downward across rows | Merge cells sideways across columns |
| GET vs POST | Data in URL, visible, ~2048 chars, bookmarkable | Data in body, hidden, no limit, for passwords |
| Checkbox vs radio | Select many | Select only one (same name) |
| <object> vs <embed> | Embedded object, all browsers, plug-ins | External app, usually audio/video |
| Inline vs internal vs external CSS | style attribute: one element | <style>: one page · .css file: whole site |
| ID vs class | #id, unique, one element | .class, reusable, many elements |
| Margin vs padding | Outside the border | Inside the border |
| Border vs outline | Part of the box size | Outside border, takes no space, may be non-rectangular |
| Block vs inline | New line, full width (div, p, h1) | Same line, needed width (span, a, img) |
| display:none vs visibility:hidden | Removed, no space | Invisible, keeps its space |
| relative vs absolute position | From its normal spot, leaves gap | From nearest positioned ancestor, removed from flow |
| fixed vs absolute | Relative to viewport, doesn't scroll | Relative to positioned ancestor, scrolls with page |
| Pseudo-class vs pseudo-element | :hover — a state | ::first-line — a part |
| Transition vs animation | A → B on a trigger | @keyframes, many steps, can repeat on its own |
| em vs rem | Element's font size | Root element's font size |
| width:100% vs max-width:100% (img) | Scales up and down | Scales down, never above original size |
| content-box vs border-box | Width = content only (default) | Width includes padding + border |
| .container vs .container-fluid | Fixed width per breakpoint | Full viewport width |
| Bootstrap 4 vs 5 | Needs jQuery, supports IE, has Jumbotron | No jQuery, no IE, RTL, offcanvas, xxl breakpoint |
Exam practice quiz
Tap an answer to check it. Wrong answers show the explanation. Filter by lecture to focus on your weak spots.