π CS50x: Introduction to Computer Science Β· subject
CS50x: Introduction to Computer Science Web Programming Syllabus
The Web Programming syllabus for CS50x: Introduction to Computer Science in full: 6 chapters and 19 topics, every one listed below, plus 51 Web Programming flashcards with answers.
Web Programming syllabus: all 6 chapters
Expand any chapter to see its topics and sub-topics.
-
The Internet
2 topics- Routers, TCP/IP, and DNS
- HTTP
-
HTML
3 topics- Tags and Attributes
- Semantic Markup
- Forms
-
CSS
3 topics- Properties and Styling
- Selectors
- Bootstrap
-
JavaScript
3 topics- Variables, Conditionals, and Loops
- Event Handling and Listeners
- The DOM
-
Flask
5 topics- Routes and Decorators
- Requests and Responses
- Templates with Jinja
- Sessions and Cookies
- AJAX
-
Final Project
3 topics- Project Design and Scope
- Implementation
- Documentation and Presentation
CS50x: Introduction to Computer Science Web Programming flashcards β 51 questions with answers
What is a router, and what role does it play on the Internet?
A router is a device that receives packets of data and forwards them toward their destination. Each router examines a packet's destination IP address and passes it along to a neighboring router closer to that destination, so data hops router-to-router across networks until it arrives.
What are TCP/IP, and what does each protocol in the pair do?
TCP/IP is the pair of protocols that governs Internet communication. IP (Internet Protocol) handles addressing and routing: every machine gets an IP address so packets can be delivered. TCP (Transmission Control Protocol) provides reliable delivery: it numbers packets so they can be reassembled in order, requests retransmission of lost packets, and uses port numbers to identify which service the data is for.
What is the format of an IPv4 address, and roughly how many unique addresses does IPv4 support?
An IPv4 address has the form #.#.#.# β four numbers separated by dots, each in the range $0$ to $255$ (8 bits each, 32 bits total). That allows $2^{32} \approx 4.3 \times 10^{9}$ (about 4 billion) unique addresses, which is why the larger 128-bit IPv6 ($2^{128}$ addresses) was introduced.
What is DNS and what problem does it solve?
DNS (Domain Name System) is a distributed, hierarchical system of servers that translates human-friendly domain names (e.g., example.com) into numeric IP addresses. It lets users type memorable names instead of memorizing IP addresses; the browser queries DNS first, then connects to the returned IP.
In TCP, what is a port number, and which port numbers are conventionally used for HTTP and HTTPS?
A port number is a numeric identifier (16 bits, so $0$ to $65535$, i.e., $2^{16}$ values) that specifies which service or program on a machine the traffic is intended for. By convention, HTTP uses port 80 and HTTPS uses port 443.
What is HTTP?
HTTP (HyperText Transfer Protocol) is the application-layer protocol that governs how web browsers (clients) request web pages and how web servers respond. It is a requestβresponse protocol: the client sends a request message (e.g., GET / HTTP/1.1) and the server replies with a status line, headers, and usually content.
Compare the HTTP methods GET and POST.
GET requests data from a server and passes any parameters in the URL's query string (visible, bookmarkable, cached, limited length) β appropriate for retrieving data. POST sends parameters in the body of the request (not shown in the URL), so it is used for submitting data that changes server state or is sensitive, such as passwords or form submissions.
What do the HTTP status codes 200, 301, 403, 404, and 500 mean?
200 OK β request succeeded. 301 Moved Permanently β resource has a new URL; browser redirects (Location header). 403 Forbidden β client lacks permission. 404 Not Found β the requested resource does not exist on the server. 500 Internal Server Error β the server's own code crashed or failed (e.g., a bug in the web application).
Identify the components of the URL https://www.example.com/path?q=cats
https:// β the protocol (HTTP secured with encryption). www β the hostname/subdomain of a server. example.com β the domain name (example) plus top-level domain (.com). /path β the path to a resource on the server. ?q=cats β the query string: HTTP parameters as key=value pairs after ?, with multiple pairs separated by &.
What is the difference between HTTP and HTTPS?
HTTPS is HTTP with encryption (TLS/SSL). All requests and responses are encrypted in transit, so intermediaries (routers, eavesdroppers) cannot read parameters, cookies, or content. HTTPS conventionally uses port 443 instead of HTTP's port 80.
In HTML, what is the difference between a tag and an attribute?
A tag marks the start (and usually end) of an element and defines its type, e.g., <p> ... </p> for a paragraph. An attribute is a key=value modifier placed inside the opening tag that configures the element's behavior or metadata, e.g., <a href="page.html"> β href is an attribute of the anchor tag.
What does the HTML element <a href="https://example.com">Click here</a> do, and what is the role of href?
The <a> (anchor) tag creates a hyperlink. The href attribute specifies the destination URL the browser navigates to when the link's content ("Click here") is clicked. Note the displayed text can differ from the actual destination β a technique exploited by phishing.
Which two attributes should an <img> tag include, and what does each do?
src β the path or URL of the image file to display; alt β alternative text describing the image, shown if the image fails to load and read aloud by screen readers for accessibility. <img> is a void (self-closing) element with no closing tag.
What is semantic markup in HTML?
Semantic markup means using tags that describe the meaning/role of content rather than its appearance β e.g., <header>, <nav>, <main>, <section>, <article>, <footer> instead of generic <div> containers. The tag name itself conveys what the content is.
Give two practical benefits of using semantic HTML elements instead of generic <div> and <span>.
1) Accessibility: screen readers and assistive technologies can identify page regions (navigation, main content) and let users jump between them. 2) Machine readability/SEO: search engines and other software better understand page structure. It also makes code more readable and maintainable for developers.
What is the semantic difference between <strong>/<em> and <b>/<i>?
<strong> and <em> are semantic: they convey that text has strong importance or emphasis (meaning), which screen readers can vocalize. <b> (bold) and <i> (italic) are purely presentational, describing only how text should look. Visually they often render the same, but <strong>/<em> carry meaning.
In an HTML <form>, what do the action and method attributes specify?
action specifies the URL (route) to which the form data is submitted, e.g., action="/register". method specifies the HTTP method used to submit β get puts fields in the URL's query string, while post sends them in the request body (used for sensitive or state-changing data).
Name common values of the type attribute on an HTML <input> element and what they provide.
type="text" (plain text box), "password" (masked input), "email" and "number" (browser-side format validation), "checkbox", "radio" (choose one of a group), "submit" (button that submits the form). Related attributes: placeholder (hint text), required (must be filled), autocomplete, autofocus.
Why must a form input have a name attribute, and how does it appear in a GET submission?
The name attribute becomes the key under which the input's value is sent to the server; inputs without name are not submitted. With method="get", each pair appears in the query string, e.g., /search?q=cats β here q is the input's name and cats is the user's value. Server code reads the value by that key.
What is the general syntax of a CSS rule, and what are properties and declarations?
A CSS rule is: selector { property: value; property: value; }. Each property: value; pair is a declaration β the property names what to style (e.g., color, font-size, text-align, background-color) and the value sets it (e.g., color: blue; font-size: 16px;). Multiple declarations are separated by semicolons inside the braces.
Show the other 31 Web Programming flashcards
What are the three ways to apply CSS to an HTML page, and which is generally preferred?
1) Inline: a style attribute directly on an element (<p style="color:red">). 2) Internal: rules inside a <style> element, typically in <head>. 3) External: a separate .css file linked with <link rel="stylesheet" href="styles.css">. External stylesheets are preferred β they separate content from presentation and can be reused across many pages.
When multiple CSS rules conflict, what is the order of specificity that decides which style wins?
From most to least specific: inline styles (style attribute), then id selectors (#id), then class selectors (.class), then type/element selectors (e.g., p, h1). The more specific selector's declarations override less specific ones; among equal specificity, the later rule wins.
In CSS, how do you select elements by type, by class, and by id? Give the syntax.
Type selector: the bare tag name β h1 { ... } styles all <h1> elements. Class selector: a dot before the class name β .highlight { ... } styles all elements with class="highlight" (a class can be shared by many elements). Id selector: a hash β #banner { ... } styles the single element with id="banner" (an id should be unique per page).
What is the difference between the CSS descendant combinator (div p) and the child combinator (div > p)?
div p (space) selects every <p> that is anywhere inside a <div> β children, grandchildren, and deeper descendants. div > p selects only <p> elements that are immediate (direct) children of a <div>, not ones nested deeper.
What are CSS pseudo-classes and attribute selectors? Give an example of each.
A pseudo-class selects an element in a particular state, written with a colon: button:hover { ... } applies only while the mouse is over the button. An attribute selector matches elements by an attribute value, written in brackets: input[type="submit"] { ... } styles only inputs whose type is submit.
What is Bootstrap and how do you add it to a web page?
Bootstrap is a popular free CSS (and JavaScript) framework providing pre-written styles and components β nicely styled buttons, tables, forms, navbars, alerts. You include it by adding its CDN <link> for CSS in <head> (and optionally its <script> before </body>), then apply its classes, e.g., <button class="btn btn-primary">.
How does Bootstrap's grid layout system work?
Bootstrap divides horizontal space into 12 equal columns. Inside a container you create a row (class="row") and give children column classes such as col-4 (spanning $\frac{4}{12} = \frac{1}{3}$ of the width). Breakpoint-infixed classes like col-md-6 make layouts responsive, so columns stack or resize at different screen widths.
In modern JavaScript, how do let and const differ when declaring variables?
let declares a block-scoped variable whose value can be reassigned. const declares a block-scoped variable that cannot be reassigned after initialization. Both are preferred over the older var, which is function-scoped and prone to bugs. Example: let counter = 0; const MAX = 10;
In JavaScript, what is the difference between the == and === comparison operators?
== is loose equality: it converts operands to a common type before comparing, so '5' == 5 is true. === is strict equality: it compares both value and type with no coercion, so '5' === 5 is false. Best practice is to use === (and !==) to avoid unintended type-coercion bugs.
Write the structure of a JavaScript for loop and an if / else if / else conditional.
Loop: for (let i = 0; i < n; i++) { ... } β initialization; condition checked before each iteration; update after each iteration. (JavaScript also has while and do...while loops.) Conditional: if (x > 0) { ... } else if (x < 0) { ... } else { ... } β branches chosen by the first true condition.
What is the syntax of addEventListener in JavaScript, and what does it do?
element.addEventListener('event', function) β e.g., button.addEventListener('click', function() { alert('Clicked!'); }); It registers a callback (event handler/listener) that the browser invokes whenever the named event (like 'click') occurs on that element. This attaches behavior in JS instead of inline onclick attributes.
Why do developers wrap DOM-manipulating JavaScript inside a listener for the DOMContentLoaded event?
Because a <script> in <head> runs before the page's HTML below it has been parsed, so querySelector would return null for elements that don't exist yet. document.addEventListener('DOMContentLoaded', function() { ... }) delays the code until the entire HTML document has been parsed and the DOM is built, guaranteeing elements are available.
Name five common browser events you can listen for and when each fires.
click β user clicks an element; submit β a form is submitted; change β a form control's value changes (e.g., a <select> choice); keyup / keydown β a keyboard key is released / pressed (used for as-you-type features); mouseover β the cursor moves onto an element. Others include load, blur, focus, and scroll.
What is the DOM?
The DOM (Document Object Model) is the browser's in-memory, tree-structured representation of a web page: the document is the root, and every element, attribute, and piece of text is a node in a hierarchy mirroring the HTML nesting. JavaScript can read and modify this tree via the global document object, changing the page dynamically without reloading.
What do document.querySelector and document.querySelectorAll do?
document.querySelector(selector) returns the first element in the DOM matching a CSS selector β e.g., querySelector('#greeting'), querySelector('.item'), querySelector('h1'). document.querySelectorAll(selector) returns all matching elements as a NodeList you can iterate over. They are the standard way to grab elements before reading or modifying them in JavaScript.
After selecting a DOM element in JavaScript, how can you change its content, style, and attributes?
Content: element.innerHTML = '<b>Hi</b>'; or element.textContent / element.innerText for plain text. Style: element.style.property, e.g., element.style.color = 'red';. Attributes: element.setAttribute('href', url) or direct properties like element.value for inputs. You can also toggle classes with element.classList.add/remove/toggle.
In Flask, how do you associate a URL with a Python function? Give the syntax.
With the @app.route decorator applied to a view function: @app.route("/") def index(): return render_template("index.html") When a request arrives for that path, Flask calls the decorated function and sends back whatever it returns as the HTTP response.
What is a decorator in Python, as used by Flask's @app.route?
A decorator is a function that takes another function and extends or modifies its behavior, applied with the @ syntax above a function definition. @app.route("/path") registers the decorated function in Flask's URL map, so Flask knows to invoke it whenever an HTTP request matches that path.
By default, which HTTP method does a Flask route accept, and how do you allow POST as well?
By default a route accepts only GET. To accept others, pass the methods argument: @app.route("/login", methods=["GET", "POST"]). Inside the function you branch on request.method β commonly rendering a form on GET and processing the submission on POST.
In Flask, what is the difference between request.args and request.form?
request.args holds parameters from the URL's query string, i.e., data sent via GET (e.g., request.args.get("q")). request.form holds parameters sent in the body of a POST request, such as submitted form fields (e.g., request.form.get("username")). Using .get(key) returns None instead of erroring when the key is missing.
What happens when a Flask view function returns render_template("page.html", name=value)?
Flask loads page.html from the templates/ folder, has Jinja substitute the passed keyword variables into the template's placeholders, and returns the resulting HTML as the body of an HTTP response (status 200 by default) that is sent back to the client's browser.
In Flask, what do redirect() and url_for() do, and how are they used together?
redirect(location) returns an HTTP redirect response telling the browser to request a different URL. url_for("function_name") generates the URL registered for a given view function. Combined β return redirect(url_for("index")) β they send the user to another page after an action, e.g., after a successful POST (the post/redirect/get pattern).
In Jinja templates, what is the difference between {{ ... }} and {% ... %}?
{{ expression }} is an output placeholder: the expression's value (a variable passed from Flask, e.g., {{ name }}) is substituted into the rendered HTML. {% statement %} performs template logic without direct output: conditionals ({% if x %}...{% endif %}), loops ({% for item in items %}...{% endfor %}), and inheritance tags like {% extends %} and {% block %}.
How does Jinja template inheritance eliminate duplicated HTML across pages?
A base template (layout.html) contains the shared boilerplate and declares insertion points: {% block body %}{% endblock %}. Each child template starts with {% extends "layout.html" %} and supplies only its unique content inside {% block body %} ... {% endblock %}. Rendering the child merges its blocks into the layout, so headers/footers live in one file.
What is an HTTP cookie and how does the server set one?
A cookie is a small piece of key=value data that a server asks the browser to store, via the Set-Cookie: key=value response header. On every subsequent request to that server, the browser automatically sends it back in a Cookie header. Cookies commonly carry a session identifier so the server can recognize a returning user (which also enables tracking).
What is a session in web programming, and how do cookies make sessions possible?
A session is per-user state kept on the server (e.g., who is logged in, a shopping cart) across multiple requests β necessary because HTTP itself is stateless. The server stores the data under a unique session ID and sends only that ID to the browser as a cookie; each later request carries the cookie, letting the server look up that user's data.
In Flask, how do you use sessions to remember a logged-in user?
Configure Flask-Session (or Flask's signed cookie sessions), then treat session as a dictionary: on login, session["name"] = request.form.get("name"); to read, session.get("name"); to log out, session.clear(). Flask handles the underlying cookie automatically, so each visitor sees only their own session data.
What is AJAX, and why is it useful?
AJAX (Asynchronous JavaScript and XML) is the technique of having JavaScript make HTTP requests in the background, after the page loads, and update parts of the page with the response β without a full page reload. It enables dynamic features like live search suggestions, infinite scroll, and chat, and today typically exchanges JSON rather than XML.
How do you make an AJAX request with the JavaScript fetch API and use the JSON response?
fetch(url) returns a Promise for the response; chain conversions and handlers: fetch('/search?q=' + query) .then(response => response.json()) .then(data => { /* update the DOM with data */ }); Or with async/await: const response = await fetch(url); const data = await response.json(); β then modify the page using the parsed data.
When designing a web project, what is scope, and what is the recommended way to define it (as in CS50's final project advice)?
Scope is the boundary of what the project will actually do. Best practice: define a good outcome (the MVP β minimum viable product you're confident you can finish), a better outcome (what you expect to achieve), and a best outcome (stretch goals). Start deliberately small and add features incrementally, rather than over-promising and failing to finish.
During implementation of a web project, what development practices help you make steady, verifiable progress?
Build iteratively: implement and fully test one small feature at a time rather than everything at once. Keep concerns separated (HTML structure, CSS styling, JS behavior, server logic in distinct files/layers). Use version control (git) to save working checkpoints, test in the browser frequently, and only move on when the current piece works β making bugs easy to localize.
CS50x: Introduction to Computer Science Web Programming FAQ
What is in the CS50x: Introduction to Computer Science Web Programming syllabus?
CS50x: Introduction to Computer Science Web Programming is split into 6 chapters: The Internet, HTML, CSS, JavaScript, Flask and Final Project. Together they contain 19 topics.
How many chapters are in CS50x: Introduction to Computer Science Web Programming?
6 chapters, containing 19 topics. The largest chapter is Flask, with 5 topics.
Are there flashcards for CS50x: Introduction to Computer Science Web Programming?
Yes β a 51-card Web Programming deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.