Exercises — Stage 2: Add Styling
Exercise 1: Change the background color
Goal: See a visible change, feel the Git workflow for a one-file edit.
Steps:
- Change
background-color: #f4f4f4;tobackground-color: #ffe4b5;(light peach). - Save and reload the page.
- Run
git status. Noticestyle.cssis now modified. - Change it back to
#f4f4f4and save. - Run
git statusagain — clean.
What happened: Git compares file contents, not just file names. Editing and un-editing leaves you back where you started, so Git reports the working tree as clean.
Exercise 2: Commit only one file
Goal: Understand that git add file.css is more precise than git add ..
Steps:
- Edit
style.css(change the button color to#ff5722). - Edit
index.html(change the paragraph text to "Ready to run?"). - Run
git status— both are modified. - Run
git add style.css. Rungit status— onlystyle.cssis staged. - Run
git restore --staged style.cssand revert both files to get back to clean.
What happened: git add accepts a file, a folder, or . for "everything." You can stage exactly the files you want to put in the next commit, which matters when you have changes you are not ready to save.
Exercise 3: Break the link
Goal: Prove that the <link> tag is what connects HTML to CSS.
Steps:
- In
index.html, changehref="style.css"tohref="style.cssx"(a bad path). - Save and reload the page.
- See the page revert to the unstyled Stage 0 look.
- Fix the path and reload.
What happened: The browser tried to load style.cssx, could not find it, and silently rendered the page with only default styles. The HTML is still correct — the connection to CSS was what broke.
Exercise 4: Look at the diff before committing
Goal: Learn git diff, which shows exactly what changed.
Steps:
- Edit
style.css: change the h1 color to#0000ff. - Before running
git add, rungit diff. - Observe the red line (old) and green line (new) for the change.
- Revert the change and save.
What happened: git diff shows unstaged changes as a line-by-line comparison. It is the easiest way to review your work before committing. Use it often.