Beginner’s Guide to Pair Programming: Building and Publishing a Simple Web Page on GitHub Pages with HTML and CSS
Welcome to your journey into web development! This guide is designed for complete beginners and utilises a self-directed peer-led learning approach. By partnering with a peer, you’ll collaborate to build and publish a simple web page using HTML and CSS, then host it on GitHub Pages. Let’s get started!
(In truth, you don't need to pair on this. You can work solo. But if you are at the meetup, we do recommend working with somebody else on it.)
- Introduction to Pair Programming
- Creating a GitHub Repository
- Setting Up Your Development Environment
- Cloning the Repository Using Command Line
- Understanding HTML Basics
- Understanding CSS Basics
- Committing HTML and CSS to GitHub
- Publishing Your Web Page with GitHub Pages
- Conclusion and Self-Test Questions
Pair Programming is a collaborative practice where two programmers work together at one workstation. One person, the Driver, writes the code, while the other, the Navigator, reviews each line of code as it’s written. Roles can switch frequently to enhance learning and catch errors early.
- Enhanced Learning: Both participants learn from each other’s strengths.
- Improved Code Quality: Continuous code review reduces bugs.
- Problem Solving: Two minds can solve problems faster and more effectively.
Peer-Led Learning: In this approach, peers guide each other without a formal instructor, fostering a supportive learning environment.
A repository (repo) is a storage space for your project on GitHub. It tracks all changes to your code and allows collaboration with others.
-
Log In to GitHub:
-
Create a New Repository:
- Go to this organisation, and click the green "New" button to create a new repo.
-
Configure Repository Settings:
- Repository Name: Enter a name (e.g.,
my-first-webpage). - Description: (Optional) Briefly describe your project.
- Public/Private: Choose "Public" so others can see your project.
- Initialize Repository: Check "Add a README file."
- Click "Create repository."
- Repository Name: Enter a name (e.g.,
- Repository: A project folder in GitHub to store code.
- README: A markdown file that describes your project.
Before you start coding, ensure you have the necessary tools installed.
If you are using Windows then you won't have a Linux-like terminal by default so you will need to install one. Please follow the installation instructions found here to get a Linux distribution running on your Windows machine and to get it hooked up with VS Code on Windows.
Here are a couple of older but still helpful guides that have some more information about setting up and using WSL as part of your development environment:
Set up a WSL development environment
Get started using Visual Studio Code with Windows Subsystem for Linux
- Code Editor: Software to write your code. Visual Studio Code (VS Code) is highly recommended for beginners.
- Git: Version control system to track changes. Download Git.
- Command Line Interface (CLI):
- Windows: Use Command Prompt or Git Bash.
- macOS/Linux: Use Terminal.
-
Install VS Code:
- Visit the VS Code website and download the installer for your operating system.
- Follow the installation prompts.
-
Install Git:
- Go to the Git download page.
- Download and install Git for your OS.
- During installation, select the option to add Git to your system PATH.
-
Configure Git (First-Time Setup):
-
Open your CLI.
-
Set your username:
git config --global user.name "Your Name" -
Set your email:
git config --global user.email "your-email@example.com"
-
- Code Editor: Tool for writing and editing code.
- Git: Version control system to manage code changes.
- System PATH: Environment variable that tells the OS where to find executables.
- Command Line Interface (CLI): Interact with your computer like it's 1970.
Cloning a repository means creating a local copy of the repository on your computer. This allows you to work on your project locally.
-
Copy Repository URL:
- On your repository page on GitHub, click the green "Code" button.
- Copy the HTTPS URL provided (e.g.,
https://github.com/this-org-name/my-first-webpage.git).
-
Open Command Line Interface (CLI)
-
Navigate to Desired Directory:
cd path/to/your/directoryReplace
path/to/your/directorywith the path where you want to store your project. -
Run the Clone Command:
git clone https://github.com/your-username/my-first-webpage.git
Replace
your-usernamewith your GitHub username. -
Navigate to the Cloned Repository:
cd my-first-webpage
- Changing directory: Using the
cdcommand, one of many useful UNIX commands you will learn over time. - Cloning: Creating a local copy of a remote repository.
HTML (HyperText Markup Language) is the standard language for creating web pages. It structures the content on the web.
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text.</p>
</body>
</html><!DOCTYPE html>: Declares the document type and version of HTML.<html>: Root element that wraps the entire content.<head>: Contains meta-information about the document, like the title.<title>: Sets the title of the web page shown in the browser tab.<body>: Contains the visible content of the web page.<h1>: Heading level 1, used for main titles.<p>: Paragraph tag for blocks of text.
- Tags: Enclosed in angle brackets (
< >), define elements. - Elements: Building blocks of HTML, consisting of tags and content.
- Attributes: Provide additional information about elements (not covered yet but important for future learning).
CSS (Cascading Style Sheets) is used to style and layout web pages—for example, to change colors, fonts, and spacing.
You can add CSS directly within your HTML using the <style> tag.
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
<style>
body {
background-color: #f0f0f0;
}
h1 {
color: blue;
text-align: center;
}
p {
font-family: Arial, sans-serif;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text.</p>
</body>
</html><style>: Tag used to embed CSS in the HTML document.- Selectors: Specify which HTML elements to style (
body,h1,p). - Properties: Define what aspect to style (e.g.,
background-color,color,font-family). - Values: Set the property’s value (e.g.,
#f0f0f0,blue,Arial, sans-serif).
- CSS Syntax:
selector { property: value; } - Selectors: Target HTML elements for styling.
- Properties and Values: Define specific styles.
After creating your web page files, you need to commit them to your local repository and push the changes to GitHub.
-
Open VS Code:
- Open the cloned repository folder (
my-first-webpage) in VS Code.
- Open the cloned repository folder (
-
Create an
index.htmlFile:- In VS Code, create a new file named
index.html. - Paste the basic HTML structure from Section 5.
- In VS Code, create a new file named
-
Add CSS Styling:
- Within the
<head>tag ofindex.html, add the<style>section from Section 6.
- Within the
-
Save Your Changes:
- Press
Ctrl + S(Windows) orCmd + S(macOS) to save the file.
- Press
-
Open Terminal in VS Code:
- Go to
View>Terminalor pressCtrl + `.
- Go to
-
Check Repository Status:
git status
This shows the current status of your repository and any changes.
-
Add Changes to Staging Area:
git add index.html
This stages your changes for committing.
-
Commit Your Changes:
git commit -m "Add initial index.html with HTML and CSS"The
-mflag allows you to add a commit message describing the changes. -
Push Changes to GitHub:
git push origin main
This uploads your committed changes to the
mainbranch on GitHub.
- Cloning: Copies the repository from GitHub to your local machine.
- Creating Files: Adding
index.htmlwhich is the default page for web browsers. - Committing: Saves your changes with a descriptive message.
- Pushing: Uploads your local commits to GitHub.
- Staging Area: Where changes are prepared before committing.
- Commit Message: Describes the changes made in a commit.
- Branch: A separate line of development;
mainis the default branch.
GitHub Pages allows you to host your web page directly from your repository, making it accessible on the web.
-
Go to Your Repository on GitHub:
- Navigate to
https://github.com/your-username/my-first-webpage.
- Navigate to
-
Access Settings:
- Click on the "Settings" tab located on the repository page.
-
Navigate to GitHub Pages Section:
- In the sidebar, click on "Pages" (previously found under "Settings" > "Pages").
-
Configure GitHub Pages:
- Source: Select the branch to publish from (usually
main). - Folder: Choose
/rootif yourindex.htmlis in the root directory. - Click "Save."
- Source: Select the branch to publish from (usually
-
Access Your Published Web Page:
- After a few minutes, GitHub will provide a URL (e.g.,
https://your-username.github.io/my-first-webpage/) where your web page is live.
- After a few minutes, GitHub will provide a URL (e.g.,
- GitHub Pages: A service to host static websites directly from a GitHub repository.
- Branch: A separate version of your repository;
mainis the default branch. - Static Website: A website with fixed content, as opposed to dynamic websites that can change based on user interaction.
Congratulations! You’ve successfully built and published your first web page using HTML, CSS, and GitHub Pages through pair programming. To reinforce your learning, test your understanding with the following questions.
-
Pair Programming
- What are the two roles in pair programming?
- Name one benefit of pair programming.
-
GitHub Repository
- What is a repository on GitHub?
- What is the purpose of a README file?
-
Cloning the Repository
- What does the
git clonecommand do? - Why is cloning a repository useful?
- What does the
-
Development Environment
- What is the purpose of a code editor like VS Code?
- Why is Git important in web development?
-
HTML Basics
- What does the
<title>tag define? - How do you create a paragraph in HTML?
- What does the
-
CSS Basics
- What is the syntax for a CSS rule?
- Name two CSS properties used to style text.
-
Committing Changes
- What command stages your changes for committing?
- What is the purpose of a commit message?
-
Pushing to GitHub
- What does the
git pushcommand do? - Why is pushing changes to GitHub important?
- What does the
-
GitHub Pages
- What is GitHub Pages used for?
- After setting up GitHub Pages, where can you view your published web page?
-
General Concepts
* What is the root element in an HTML document?
* How do you add CSS directly within an HTML file?
* What does `<!DOCTYPE html>` declare?
* What is a static website?
* What is the default branch name in a new GitHub repository?
* How do you navigate to a directory in the command line?
* What does the `<h1>` tag represent in HTML?
* What is the function of the `<style>` tag in HTML?
Answers:
-
Pair Programming
- Roles: Driver and Navigator.
- Benefit: Enhanced learning or improved code quality.
-
GitHub Repository
- Repository: A storage space for your project on GitHub.
- README File: Describes your project.
-
Cloning the Repository
git clone: Creates a local copy of a remote repository.- Usefulness: Allows you to work on the project locally.
-
Development Environment
- Code Editor Purpose: Used to write and edit code.
- Git Importance: Manages and tracks changes in the codebase.
-
HTML Basics
<title>Tag: Defines the title of the web page shown in the browser tab.- Paragraph Creation:
<p>Your text here.</p>
-
CSS Basics
- CSS Rule Syntax:
selector { property: value; } - Text Styling Properties:
color,font-size.
- CSS Rule Syntax:
-
Committing Changes
- Staging Command:
git add index.html - Commit Message Purpose: Describes the changes made in a commit.
- Staging Command:
-
Pushing to GitHub
git push: Uploads local commits to GitHub.- Importance: Shares your changes with others and updates the remote repository.
-
GitHub Pages
- Purpose: To host and publish static websites from a GitHub repository.
- View Published Page: At the provided GitHub Pages URL (e.g.,
https://your-username.github.io/my-first-webpage/).
-
General Concepts
* **Root Element:** `<html>`
* **Adding CSS:** Using the `<style>` tag within the `<head>` section.
* **`<!DOCTYPE html>`:** Declares the document type and version of HTML.
* **Static Website:** A website with fixed content.
* **Default Branch Name:** `main`
* **Navigate Directory:** `cd path/to/directory`
* **`<h1>` Tag:** Represents a top-level heading.
* **`<style>` Tag Function:** Embeds CSS styles within an HTML document.
Keep practicing and exploring more about HTML, CSS, and GitHub to enhance your web development skills. Happy coding!